Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zally produces other JSON pointers with swagger-parser 2.0.22+ #1255

Closed
vadeg opened this issue Jun 9, 2021 · 3 comments
Closed

Zally produces other JSON pointers with swagger-parser 2.0.22+ #1255

vadeg opened this issue Jun 9, 2021 · 3 comments

Comments

@vadeg
Copy link
Contributor

vadeg commented Jun 9, 2021

Schema

            openapi: 3.0.1
            paths:
              /pets:
                get:
                  responses:
                    200:
                      content:
                        application/json:
                          schema:
                            properties:
                              id:
                                "${'$'}ref": "#/components/schemas/CustomId"
            components:
              schemas:
                CustomId:
                  type: integer
                  format: int64

swagger-parser 2.0.21 will produce a JSON pointer to id property as /paths/~1pets/get/responses/200/content/application~1json/schema/properties/id

swagger-parser 2.0.22+ will produce a JSON pointer to id property as /components/schemas/CustomId.

The reason for this is that swagger-parser flattens schemas by replacing schema with a reference with an actual schema. This behaviour breaks the AST reference builder.

@vadeg
Copy link
Contributor Author

vadeg commented Jun 10, 2021

There was a bug in swagger-api/swagger-parser#1433 which prevent properties to be resolved if the properties have a $ref.

The reason why Zally gets the wrong JSON pointer is because swagger-parser reassigns the same schema instance to the property during the resolution. Zally uses object identities to get JSON pointers for OpenAPI object. In the example above the resolved API will look like this:

openapi: 3.0.1
paths:
  /pets:
    get:
      responses:
        200:
          content:
            application/json:
              schema:
                properties:
                  id: 
                   # This part is an identical object as "CustomId" below
                    type: integer
                    format: int64
components:
  schemas:
    CustomId:
      type: integer
      format: int64

@vadeg
Copy link
Contributor Author

vadeg commented Jul 6, 2021

The problem is related to how Swagger parser makes full schema resolution. Check the resolveFully example. In this case JSON pointers map based on identities will point wrong instances.

@vadeg
Copy link
Contributor Author

vadeg commented Jul 7, 2021

This is not a bug in Zally, but fixing a bug in the parser leads to different JSON pointers resolution in some cases. Will close this, because there is nothing to fix.

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

No branches or pull requests

1 participant