OpenApiInteractionValidator is resolving the wrong schema for an operation

Issue #365 new
Simon Dean created an issue

Upstream Issue

This seems to be an issue in the upstream dependency https://github.com/swagger-api/swagger-parser.  I've raised issue https://github.com/swagger-api/swagger-parser/issues/1621 for it.  I'm raising it here too for anyone else who encounters the issue swagger-request-validator.  Feel free to close this issue if that's the right approach.  

Minimal Reproduction Repo

See the following repo for a minimal reproduction of this issue: 

Here's an example OpenAPI spec that demonstrates the issue: 

https://github.com/simondean/swagger-request-validator-filename-issue/blob/main/example-openapi.yaml

openapi: 3.0.1
info:
  title: Example OpenAPI spec
  version: 0.0.1
paths:
  '/example':
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExamplePost'
      responses:
        204:
          description: No content
components:
  schemas:
    # Renaming this key from `Example` to `ExampleGet` stops the issue from occurring
    # Removing this key stops the issue from occurring
    Example:
      $ref: example.get.yaml
    ExamplePost:
      $ref: example.post.yaml

The comments in the code snippet show how the issue only happens when the unused schema is called `Example`.  Rename it to `ExampleGet` or delete it, and the issue stops.  The word `Example` is unimportant, other than it seems to need to be similar to the other schema that is used.  Both schemes could be renamed to `Anything` and `AnythingPost` and you would still get the issue

Expected Behaviour

The following assertion should pass: 

        assertEquals("POST Example", api.getPaths()
                .get("/example")
                .getPost()
                .getRequestBody()
                .getContent()
                .get("application/json")
                .getSchema()
                .getTitle());

Actual Behaviour

Swagger Parser loads the wrong request body schema for the POST operation.  It's request body description is set to `GET Example` when it should be `POST Example`:

expected: <POST Example> but was: <GET Example>

Comments (0)

  1. Log in to comment