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

Internal parameter references in callbacks fail to parse properly #2099

Open
fsudau opened this issue May 10, 2024 · 0 comments
Open

Internal parameter references in callbacks fail to parse properly #2099

fsudau opened this issue May 10, 2024 · 0 comments

Comments

@fsudau
Copy link

fsudau commented May 10, 2024

Hi, using io.swagger.parser.v3:swagger-parser:jar:2.1.22, this spec:

openapi: 3.0.0
info:
  version: 1.0.0
  title: reproducing API
  description: Reproduces callback-with-parameters issue

paths:
  /mypath:
    get:
      responses:
        '200':
          description: OK
      callbacks:
        myCallbackName:
          $ref: '#/components/callbacks/my-callback'

components:
  parameters:
    cb-param-one:
      in: header
      name: name-one
      required: true
      schema:
        type: string
    cb-param-two:
      in: header
      name: name-two
      required: true
      schema:
        type: string
  callbacks:
    my-callback:
      https://example.org/callback:
        post:
          parameters:
            - $ref: '#/components/parameters/cb-param-one'
            - $ref: '#/components/parameters/cb-param-two'
          responses:
            '200':
              description: OK

fails to parse properly. This code

    @Test
    public void loadMinimalExample() {
        SwaggerParseResult parseResult = new OpenAPIV3Parser().readWithInfo("callback-param-api.yaml", emptyList());
        List<String> msgs = parseResult.getMessages();
        if (!msgs.isEmpty()) {
            fail(Joiner.on("\n").join(msgs));
        }
    }

produces the warning components.callbacks(post).parameters. There are duplicate parameter values. The problem vanishes if you use only one parameter reference.

Background / Assumptions
This is closely related to the work done in #1063 #1066 #1065 #1080. From my understanding, the issue unfolds like this: OpenAPIDeserializer first deserializes components (which includes parameters and callbacks), then paths. To validate parameters, the getParameterDefinition method is used to resolve parameter references from this.components. This works fine when paths reference stuff, but when callbacks are parsed, this.coomponents does not exist yet. Since the resolving fails, the two callback parameter are then regarded to be identical. I could be completely wrong though :)

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

1 participant