Skip to content

Swagger (v2) not deserialized properly #390

Closed

Description

In the following code :

var stream = new HttpClient().GetStreamAsync("https://petstore.swagger.io/v2/swagger.json").Result;

var inputDocument = new OpenApiStreamReader().Read(stream, out var diagnostic);

Debug.Assert(diagnostic.SpecificationVersion == OpenApiSpecVersion.OpenApi2_0);

var schema = inputDocument.Paths["/pet/{petId}"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema;

schema ends up null, whereas it should contain Pet.

Activity

  1. darrelmiller commented on Mar 13, 2019

    @darrelmiller
    Member

    Hey Sebastien Bacquet (@sbacquet) Good catch.

    The problem comes because of the produces with two media types. If you run the petstore OpenAPI through the workbench tool you get the following V3 output.

            '200':
              description: successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json: { }

    The schema is preserved for the first content type but lost for the second. I suspect this is a regression related to other changes around maintaining state whilst translating V2 into V3.

    I will investigate.

  2. sbacquet commented on Mar 13, 2019

    @sbacquet
    Author

    Hello Darrel,

    Thanks a lot for investigating.
    May I suggest to add a unit test to cover this case ? ;)

    Thanks again!

  3. huaxing-yuan commented on Mar 13, 2019

    @huaxing-yuan

    Hello, i think i'm running into a similar scenario the response schema reference is empty.
    The bug is introduced in the package v1.1.2. I rolled back to v1.1.1 the schema is now read correctly.

    This is part of my swagger v2 document

    paths:
      /xxx:
        post:
          operationId: xxx
          produces:
            - application/json
          parameters:
            ***
          responses:
            '200':
              description: success
              schema:
                $ref: '#/definitions/checkOutput'
  4. darrelmiller commented on Mar 13, 2019

    @darrelmiller
    Member

    Huaxing YUAN (@huaxing-yuan) Thanks for the additional info, I suspected it was a regression. And yes Sebastien Bacquet (@sbacquet) I'll make sure that our test cases are updated to account for this.

  5. added this to the 1.1.3 milestone on Apr 10, 2019
  6. VitaliyKurokhtin commented on Apr 10, 2019

    @VitaliyKurokhtin
    Contributor

    Should be resolved by #398

  7. darrelmiller commented on Apr 27, 2019

    @darrelmiller
    Member

    This fix should be available in 1.1.3

  8. sbacquet commented on Apr 29, 2019

    @sbacquet
    Author

    I confirm it's fixed, thank you !

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

Metadata

Metadata

Labels

type:bugA broken experience

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions