swagger-api / swagger-api/swagger-parser
Internal parameter references in callbacks fail to parse properly
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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