swagger-api / swagger-api/swagger-parser

Internal parameter references in callbacks fail to parse properly

Open
#2,099 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

Hi, using io.swagger.parser.v3:swagger-parser🫙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 :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with OpenAPIV3Parser.readWithInfo and OpenAPIDeserializer.getParameterDefinition, using the callback-param-api.yaml example from the issue to reproduce the warning. Trace callback parameter reference resolution through components, then run the supplied loadMinimalExample test. Done means both callback parameter references parse without the duplicate-parameter warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.