How do I wrap JSON objects?

霸气de小男生 提交于 2019-12-04 06:41:16

问题


I'm currently looking for a way to wrap JSON in the Swagger UI component.

In YAML my object declaration is:

  restException:
    properties:
      message:
        type: string

The output generated by Swagger UI is (whic I agree, is correct): { "message": "string" }

and what I want is:

"restException": {
  "message": "string"
}

I've just find a ugly way to do it by explicitely declaring the wrapper in the YAML file. But it's verry bad since it's also generates when I use "Swagger Codegen" to generate client or server code.

restExceptionContainer: restException: properties: message: type: string

I'm ok for adding code in the Swagger UI file if needed ! Need your help to find where :)


回答1:


You should document restException as an object (type: object).

Please refer to https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L646 as an example and look at how Pet and Category are defined.

  Pet:
    type: object
    required:
      - name
      - photoUrls
    properties:
      id:
        type: integer
        format: int64
      category:
        $ref: '#/definitions/Category'

where Category is defined as:

  Category:
    type: object
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string


来源:https://stackoverflow.com/questions/36545405/how-do-i-wrap-json-objects

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