How to define a reusable body parameter that is a primitive data type in OpenAPI 3.0?

放肆的年华 提交于 2019-12-11 13:34:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!