Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

Fixes v2 examples serialization in a response object#1524

Merged
MaggieKimani1 merged 20 commits intorelease/2.0.0microsoft/OpenAPI.NET:release/2.0.0from
mk/fix-v2-examples-serializationmicrosoft/OpenAPI.NET:mk/fix-v2-examples-serializationCopy head branch name to clipboard
Jan 11, 2024
Merged

Fixes v2 examples serialization in a response object#1524
MaggieKimani1 merged 20 commits intorelease/2.0.0microsoft/OpenAPI.NET:release/2.0.0from
mk/fix-v2-examples-serializationmicrosoft/OpenAPI.NET:mk/fix-v2-examples-serializationCopy head branch name to clipboard

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
src/Microsoft.OpenApi/Models/OpenApiResponse.cs Outdated Show resolved Hide resolved
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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.