Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
868 views
in Technique[技术] by (71.8m points)

swagger - How do I wrap JSON objects?

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...