swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Internal parameter references in callbacks fail to parse properly

Open fsudau opened this issue 1 year ago • 0 comments

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 :)

fsudau avatar May 10 '24 10:05 fsudau