Skip to content

Conversation

@MaggieKimani1
Copy link
Contributor

@MaggieKimani1 MaggieKimani1 commented Jan 11, 2024

  • Retains examples present in a media type object by adding serialization logic of the examples map to x-examples during down-casting from v3 to v2
  • Adds logic to cater for the round trip i.e. serializing x-examples in a v2 document to examples in the resulting v3 document during upcasting
  • Fixes Examples are missing after converting V3 swagger to V2 #1430

Snippets

openapi: 3.0.1
info:
  title: Pet Store API
  version: 1.0.0
paths:
  /pets:
    get:
      summary: Get all pets
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    name:
                      type: string
                    age:
                      type: integer
              examples:
                example1:
                  summary: Example - List of Pets
                  value:
                    - name: "Buddy"
                      age: 2
                    - name: "Whiskers"
                      age: 1
               example2:
                  summary: Example - Playful Cat
                  value:
                    name: "Whiskers"
                    age: 1

Results to:

swagger: '2.0'
info:
  title: Pet Store API
  version: 1.0.0
paths:
  /pets:
    get:
      summary: Get all pets
      produces:
        - application/json
      responses:
        '200':
          description: Successful response
          schema:
            type: array
            items:
              type: object
              properties:
                name:
                  type: string
                age:
                  type: integer
          x-examples:
            example1:
              summary: Example - List of Pets
              value:
                - name: "Buddy"
                  age: 2
                - name: "Whiskers"
                  age: 1
           example2:
              summary: Example - Playful Cat
              value:
                name: "Whiskers"
                age: 1

And the reverse is also true.

@MaggieKimani1 MaggieKimani1 marked this pull request as ready for review January 11, 2024 13:56
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes!

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants