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

OpenAPI 3.1 SpecFilter.removeBrokenReferenceDefinitions breakes WebHooks processing #4737

Closed
bnasslahsen opened this issue Sep 22, 2024 · 1 comment

Comments

@bnasslahsen
Copy link

When using io.swagger.v3.core.filter.SpecFilter.removeBrokenReferenceDefinitions on the provided OpenAPI 3.1.0 specification, the function is incorrectly removing the RequestDto schema definition from the components.schemas section. The schema is still referenced in the webhook newPet request body, but the actual schema definition is removed from the OpenAPI spec, resulting in a broken reference.

Input OpenAPI Spec:
The original OpenAPI specification includes a schema definition RequestDto under the components.schemas, which is referenced by the newPet webhook's request body schema.

openapi: 3.1.0
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: http://localhost
    description: Generated server url
paths: {}
components:
  schemas:
    RequestDto:
      properties:
        personalNumber:
          type: string
webhooks:
  newPet:
    post:
      requestBody:
        description: Information about a new pet in the system
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RequestDto'
              description: Webhook Pet
      responses:
        '200':
          description: >-
            Return a 200 status to indicate that the data was received
            successfully

Generated OpenAPI Spec:
After using the removeBrokenReferenceDefinitions method, the resulting OpenAPI spec incorrectly removes the RequestDto schema from the components.schemas section, even though it is still referenced. This causes a broken reference in the generated spec:

openapi: 3.1.0
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: http://localhost
    description: Generated server url
paths: {}
components:
  schemas: {}
webhooks:
  newPet:
    post:
      requestBody:
        description: Information about a new pet in the system
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RequestDto'
              description: Webhook Pet
      responses:
        '200':
          description: >-
            Return a 200 status to indicate that the data was received
            successfully

Expected Result
The SpecFilter.removeBrokenReferenceDefinitions method should retain schema definitions that are referenced in other parts of the OpenAPI specification (such as in webhooks, request bodies, or responses). In this case, since the RequestDto schema is being referenced in the newPet webhook, the method should not remove the RequestDto schema from the components.schemas section.

The expected behavior is as follows:

The RequestDto schema should remain in the components.schemas section, as it is actively referenced in the webhook newPet.

@micryc
Copy link
Contributor

micryc commented Oct 24, 2024

Hi @bnasslahsen thank you for reporting the issue ! It should be solved by: #4762, I am closing this ticket for now, If there will be still any questions feel free to reopen.

@micryc micryc closed this as completed Oct 24, 2024
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

No branches or pull requests

2 participants