问题
I'm creating an OpenAPI 3.0 specification/description of an API in which many of the request bodies include some of the same parameters, and those parameters are primitive data types like strings or integers. For example:
imei:
type: integer
format: int64
description: 4G hardware device identifier
I'd like to define those parameters just once in the "components" object and then use $ref to include them where needed instead of having the same parameter defined in a dozen different request bodies. I haven't been able to find a way to do that.
- Parameters defined in the "parameters" object cannot be used in request bodies. Bummer. I think this was allowed in 2.0.
- I can define these parameters in the "schemas" object, but Swagger Editor then displays them under "Models." It's a bit of a stretch to call a parameter that is a primitive data type a model. These are parameters that are used in models, not models themselves.
I've searched SO and the web extensively and haven't found this particular question addressed. Maybe the answer is "it can't be done," but that would seem like quite an oversight by the OpenAPI technical committee.
来源:https://stackoverflow.com/questions/53218457/how-to-define-a-reusable-body-parameter-that-is-a-primitive-data-type-in-openapi