cancel
Showing results for 
Search instead for 
Did you mean: 

Way to Model Response An Array of Different Objects With Identical Properties

SOLVED
Contributor

Re: Way to Model Response An Array of Different Objects With Identical Properties

Can you use enum with example? I have tried without success.

Moderator

Re: Way to Model Response An Array of Different Objects With Identical Properties

Should work with no issues. Can you share what you tried so I have a starting point?
Contributor

Re: Way to Model Response An Array of Different Objects With Identical Properties

Here is the code:

 

      "inline_response_DELETE_Project_200": {
        "type": "object",
        "properties": {
          "changes_made": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "rows_deleted": {
                  "type": "integer",
                  "description": "The number of rows deleted when the project was deleted.",
                  "example": 0
                  },
                "table_name": {
                  "type": "string", 
                  "description": "The name of the table where the row was deleted.",
                  "example": ,
                    "enum": [
                      "user_project",
                      "test_job",
                      "project_info",
                      ],
                    }
                  }
            }
          }
        }
      },
Moderator

Re: Way to Model Response An Array of Different Objects With Identical Properties

Okay, that will not produce what you want. Please read https://swagger.io/docs/specification/adding-examples/ for a deeper explanation on how to add examples to responses. It should give you enough information on the right steps. If you run into any issues, please share the definitiion you got to and we'll take it from there.

 

As a side note - the Editor is intended to be used with YAML and not JSON. By using JSON, you will not get some of the benefits of the editor. Converting to YAML would be as simple as copying the JSON and pasting it again into the Editor. It will automatically detect it and ask if you want to convert it to YAML.

Contributor

Re: Way to Model Response An Array of Different Objects With Identical Properties

By reading the pages that you cited and by using YAML, I was able to document the response that consisted of a multi-item example.  Thanks for your help!

Moderator

Re: Way to Model Response An Array of Different Objects With Identical Properties

Awesome! Happy to hear.

Occasional Contributor

Re: Way to Model Response An Array of Different Objects With Identical Properties

@BostonKevin could you share a code snippet?

I'm struggling with the same issue.

Highlighted
Contributor

Re: Way to Model Response An Array of Different Objects With Identical Properties

I cannot give you the exact details, but a successful response iwith a multi-item response in YAML could be defined as:

 

    inline_response_DELETE_200:
      type: object
      properties:
        changes_made:
          type: array
          items:
            type: object
            properties:
              rows_deleted:
                type: integer
                description: The number of rows deleted.
              table_name:
                type: string
                description: The table where a row was deleted.
          example:
            - rows_deleted: 1
              table_name: user_project
            - rows_deleted: 0
              table_name: test_job
            - rows_deleted: 1
              table_name: project_info

The above schema could be invoked in the description of the DELETE resource, as follows:

 

      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/inline_response_DELETE_200'

Hope this helps!

New Here?
Join us and watch the welcome video:
Join our online event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win