Search code examples
jsonswaggerswagger-uiswagger-2.0swagger-editor

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


Solution

  • 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