openapi-generator
openapi-generator copied to clipboard
[BUG] Validation error: "There are duplicate parameter values"
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] What's the version of OpenAPI Generator used?
- [x] Have you search for related issues/PRs?
- [x] What's the actual output vs expected output?
Validating spec (bundle.oas3.yaml)
Errors:
-attribute paths.'/anPath'(get).parameters.There are duplicate parameter values
[error] Spec has 1 errors.
Description
A wrong validation error when using external $ref
openapi-generator version
4.0.0-SNAPSHOT
OpenAPI declaration file content or url
Steps to reproduce
openapi-generator-cli validate -i bundle.oas3.yaml
Related issues/PRs
https://github.com/swagger-api/swagger-parser/issues/1063
Suggest a fix
https://github.com/swagger-api/swagger-parser/pull/1065
I almost have sure that this issue is related to one that I've found in the swagger-parser. As this team already is bundling an own parser jar then you could also try and apply the fix proposed.
unfortunately the PR at swagger-api/swagger-parser#1065 is not working when the parameters are in an external file. :(
We are facing the same issue.
@Emdee89 , it was fixed by swagger-parser team today. Now we need to wait for the fix to be merged in the branch used by openapi-generator.
@cvgaviao Thanks for letting me know. Any rough pointer by when this will be released in a new version of the openapi-generator?
@Emdee89, well, only the openapi-generator team can answer that :D I've tested my generation with swagger-parser master branch, but they are using a version from their own branch.
@jmini , may I ask you to take a look on the recent swagger-parser PR that fixes this ?
I have prepared PR https://github.com/OpenAPITools/openapi-generator/pull/2775 to update Swagger-Parser
I have updated Swagger-Parser.
Can you check the latest 4.0.0-SNAPSHOT
version of OpenAPI Generator?
I've confirmed that the validate
function is no longer returning erroneous There are duplicate parameter values
messages after https://github.com/OpenAPITools/openapi-generator/pull/2775. So https://github.com/swagger-api/swagger-parser/issues/1063 has now been fixed in openapi-generator. 🎉 I think this issue can be closed. Thanks for your help @jmini!
I'm still seeing this issue.
I have the following snippet which is generated as a bundle:
parameters:
- schema:
type: string
in: query
name: portfolioId
description: Unique identifier of the portfolio to filter by.
- schema:
type: string
in: query
name: reference
description: Reference to filter by.
- schema:
type: string
format: date
in: query
name: startDate
description: Filter for deposits created on or after this date.
- schema:
type: string
format: date
in: query
name: endDate
description: Filter for deposits created on or before this date.
- schema:
type: string
in: query
name: status
description: Deposit status to filter by.
- $ref: '#/paths/~1models/get/parameters/2'
- $ref: '#/paths/~1models/get/parameters/3'
Results in...
-attribute paths.'/deposits'(get).parameters.There are duplicate parameter values
This is using the latest stable (5.1.0)
This is still present in 5.2.1
, too. I have just upgraded our internal generator. We are using swagger-cli:4.0.4
to both bundle
and validate
:
> swagger-cli bundle -t yaml api.yml > hub.yml && swagger-cli validate hub.yml
hub.yml is valid
I haven't tried updating the swagger-parser
version, but it seems that it is still an open issue in that project.
Note that swagger-cli
uses @apidevtools/swagger-parser
, a JS parser completely different from the one used by openapi-generator
- hence the valid
report in my output above.
Edit: For anyone using or willing to use swagger-cli
in their build chain, this can be worked around via: npx swagger-cli bundle -r -t yaml api.yml > inflated.yml
. The -r
flag resolves ALL references, creating an API definition with no pesky $ref
tags.
Edit 2: my workaround doesn't really work, come to find out. Using the fully-dereferenced API definition as an input to the code generator changes all my model names (because they are now inlined), so you get junk like InlineResponse200
instead of the actual model (which was a $ref
to #/components/schemas/Foo
). Back to the drawing board here.
Edit 3: I have worked around this using yq
to replace the $ref
s that are causing openapi-generator
grief. This is a nasty hack, to be sure. Duct tape secures the world... 🦆
@sarumont Any chance you can share specifically what you did with yq to replace the references? This is still an issue and I think I am going to be writing a script to replace the references that are causing the problems as well.
@philip-ellis-sp Here's my workaround job to substitute:
Basically, I'm replacing $refs
that cannot be deciphered (in /resources
) with ones that are local to the file in question (in /nodes
).
Hope this helps.
I have the same problem. I have a pretty simple schema example. The openapi-generator fails with duplicate param error but swagger-cli validations passes test.json
{
"openapi": "3.0.2",
"info": {
"version": "99.99.99",
"title": "API"
},
"servers": [
{
"url": "/v1"
}
],
"paths": {
"/a/b/c": {
"parameters": [
{
"$ref": "#/x-defs/parameter-shared-omit"
},
{
"$ref": "#/x-defs/parameter-shared-include"
}
]
}
},
"x-defs": {
"parameter-shared-omit": {
"name": "omit",
"in": "query",
"description": "Drop any JSON properties matched by an omit pattern from the response.\n",
"schema": {
"type": "integer",
"format": "int64"
}
},
"parameter-shared-include": {
"name": "include",
"in": "query",
"description": "Only include JSON properties matched by an include pattern in the response.\n",
"schema": {
"type": "string"
}
}
}
}
➜ example$ openapi-generator validate -i test.json Validating spec (test.json) Errors: - paths.'/a/b/c'. There are duplicate parameter values
[error] Spec has 1 errors.
➜ example$ swagger-cli validate test.json
test.json is valid
But when I resolve my $refs using "swagger-cli bundle --dereference test.json" then feed that to the openapi-generator, I see no issues. test_dref.json
{
"openapi": "3.0.2",
"info": {
"version": "99.99.99",
"title": "API"
},
"servers": [
{
"url": "/v1"
}
],
"paths": {
"/a/b/c": {
"parameters": [
{
"name": "omit",
"in": "query",
"description": "Drop any JSON properties matched by an omit pattern from the response.\n",
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"name": "include",
"in": "query",
"description": "Only include JSON properties matched by an include pattern in the response.\n",
"schema": {
"type": "string"
}
}
]
}
}
}
➜ example$ openapi-generator validate -i test_dref.json
Validating spec (test_dref.json)
No validation issues detected.
I have a fairly large spec and dereferencing everything puts a lot of objects inline which is not desirable.