Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
758 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...