question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allOf merges $ref schemas outside of allOf

See original GitHub issue

When using allOf combining $ref and inline schemas, all times the $ref is used are also updated to the inline-schema.

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3.0.0
Which Swagger-UI version? Swaggerhub SmartBear
How did you install Swagger-UI? swaggerhub.com
Which browser & version? Chrome Latest
Which operating system? MacOS

Demonstration API definition

components:
  schemas:
    Error:
      type: object
      properties:
        code:
          type: integer
          format: int32
          minimum: 100
          maximum: 600
        message:
          type: string
    UnauthorizedError:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          properties:
            code:
              example: 401
            message:
              example: "Unauthorized"
    NotFoundError:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          properties:
            code:
              example: 404
            message:
              example: "Resource Not Found"

Expected Behavior

The example 404 should only appear for the NotFoundError $ref.

components:
  responses:
    NotFound:
      description: The specified resource was not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NotFoundError'

Current Behavior

The example 404 also appears for the UnauthorizedError $ref.

components:
  responses:
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UnauthorizedError'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shockeycommented, May 4, 2018

Yep, this is a bug!

I was just working in this area of Swagger-Client for https://github.com/swagger-api/swagger-js/pull/1275, so I went ahead and patched this while my memory was fresh.

0reactions
lock[bot]commented, Jul 2, 2019

Locking due to inactivity.

This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.

If you think you’re experiencing something similar to what you’ve found here: please open a new issue, follow the template, and reference this issue in your report.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding JSON Schema 2020-12 documentation
JSON Schema includes a few keywords for combining schemas together. Note that this doesn't necessarily mean combining schemas from multiple files or JSON ......
Read more >
JSON schema : "allof" with "additionalProperties"
This problem is why I have made these two proposals for draft v5: strictProperties ,; merge . Your schema for shipping_address would then...
Read more >
Combining schemas - Ajv JSON schema validator
Combining schemas. Combining schemas with $ref; Extending recursive schemas; $data reference; $merge and $patch keywords ...
Read more >
Other Internals - react-jsonschema-form documentation
The allOf keyword is supported; it uses json-schema-merge-allof to merge subschemas to render the final combined schema in the form. When these subschemas...
Read more >
oneOf, anyOf, allOf, not - Swagger
oneOf – validates the value against exactly one of the subschemas; allOf – validates ... application/json: schema: oneOf: - $ref: '#/components/schemas/Cat' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found