Closed ArchiCain closed 5 years ago
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
same here with the following spec:
swagger: '2.0'
schemes:
- http
# Path API Definitions
paths:
/document/upload/{documentId}:
post:
tags:
- document
summary: 'uploads a pdf as a document'
consumes:
- multipart/form-data
parameters:
- in: formData
name: file
type: file
description: 'The file to upload.'
- $ref: '#/parameters/documentid'
- $ref: '#/parameters/language'
responses:
200:
description: 'Successful operation'
405:
description: 'Invalid input'
parameters:
documentid:
name: documentId
in: path
description: 'id of the document'
required: true
type: integer
language:
name: language
in: query
description: 'required language'
required: true
type: string
results in the following error
[ERROR]
org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
| Error count: 4, Warning count: 0
Errors:
-attribute paths.'/document/upload/{documentId}'. Declared path parameter documentId needs to be defined as a path parameter in path or operation level
this happens for any generator, e.g. spring
java -jar .\openapi-generator-cli.jar generate -g spring -i test.yml -o blub
with
swagger: '2.0'
info:
description: >-
This is the REST API
version: 1.0.0
title: test
schemes:
- http
# Path API Definitions
paths:
/document/upload/{documentId}:
post:
tags:
- document
summary: 'uploads a pdf as a document'
consumes:
- application/json
parameters:
- $ref: '#/parameters/documentid'
- $ref: '#/parameters/language'
responses:
200:
description: 'Successful operation'
405:
description: 'Invalid input'
parameters:
documentid:
name: documentId
in: path
description: 'id of the document'
required: true
type: integer
language:
name: language
in: query
description: 'required language'
required: true
type: string
results in
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
| Error count: 1, Warning count: 0
Errors:
-attribute paths.'/document/upload/{documentId}'. Declared path parameter documentId needs to be defined as a path parameter in path or operation level
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:566)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:353)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
@wing328 @jmini could you please have a look at this? this sounds like a serious issue and should definitely be resolved before the 4.0.0
release
it is all about referencing the path parameter
this works
swagger: '2.0'
info:
version: 1.0.0
title: OpenAPI Petstore
host: http://localhost
schemes:
- http
paths:
'/pet/{petId}':
get:
tags:
- pet
produces:
- application/json
parameters:
- name: petId
in: path
required: true
type: integer
responses:
'200':
description: successful operation
parameters:
petId:
name: petId
in: path
required: true
type: integer
while this doesn't:
swagger: '2.0'
info:
version: 1.0.0
title: OpenAPI Petstore
host: http://localhost
schemes:
- http
paths:
'/pet/{petId}':
get:
tags:
- pet
produces:
- application/json
parameters:
- $ref: '#/parameters/petId'
responses:
'200':
description: successful operation
parameters:
petId:
name: petId
in: path
required: true
type: integer
@GetDaStick @rolandbaettig @macjohnny have you guys tried the following suggestion?
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
The issue is due to a limitation in the swagger parser not being able to handle the parameter reference correctly.
Yes and we tried but it had no impact the error came anyway
Am 16.02.2019 um 14:03 schrieb William Cheng notifications@github.com:
@GetDaStick @rolandbaettig @macjohnny have you guys tried the following suggestion?
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
The issue is due to a limitation in the swagger parser not being able to handle the parameter reference correctly.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@rolandbaettig is it correct to say that you were able to generate the code successfully and you're looking for a way to hide/disable/fix the incorrect error message (false alarm)?
I also get this error. I would prefer to get valid spec errors, although passing the option to skip spec validation does work around this issue. Thanks!
No it is not. I couldn’t generate the code with the reference to the path parameter. I had to replace the reference with the definition of the path param.
Von: William Cheng notifications@github.com Antworten an: OpenAPITools/openapi-generator reply@reply.github.com Datum: Sonntag, 17. Februar 2019 um 02:53 An: OpenAPITools/openapi-generator openapi-generator@noreply.github.com Cc: Roland Bättig conil@bluewin.ch, Mention mention@noreply.github.com Betreff: Re: [OpenAPITools/openapi-generator] [BUG][typescript-angular] Attribute path error while using #ref for path parameters (#2150)
@rolandbaettig is it correct to say that you were able to generate the code successfully and you're looking for a way to fix the incorrect error message (false alarm)?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
We are having the same issue.
@anibalcesar have you tried --skip-validate-spec
to skip the validation?
Can someone change the title of this? This is a general issue, so [typescript-angular]
should be removed.
Disabling validation is not really an option in my team. :( But it looks like the fix to silence the false positive is in the pipe :)
I looked into swagger-parser and it looks like this false alarm is fixed in swagger-api/swagger-parser@56c9830 which is in v2.0.9. Currently, openapi-generator master is using a fork based on 2.0.8: https://github.com/OpenAPITools/openapi-generator/blob/d32564da51c2dd18c2acc61473e44589a13a89f7/pom.xml#L1365-L1366
All commits from swagger-paraser v2.0.9 are included in the OpenAPITools branch/fork: https://github.com/OpenAPITools/swagger-parser/compare/2.0-OpenAPITools...swagger-api:v2.0.9
And it looks like that will be released as 2.0.10-OpenAPITools.org-1
to be included with openapi-generator in #2262. (Thanks for the pointer about the PR to update the dep in gitter @wing328)
So, I guess it is coming soon :)
Disabling validation is not really an option in my team. :
Do you mind elaborating on this? We're thinking about showing the validation error as warnings moving forward (so --skip-validate-spec set to true be default)
When someone introduces something that breaks the spec, it should fail as loudly as possible and prevent them from continuing without fixing the spec. It's an effort to increase code quality. Though, I suppose once it hits the generator, that is probably too late in the process, and they should have those errors much sooner. Hmm. I guess turning those errors into warnings at the generator stage wouldn't be that bad.
I totally agree with detecting broken specs as part of the workflow but at the same time I think we should evaluate whether openapi-generator is the ideal candidate for validating the spec as the validation relies on swagger parser (which is a dependency we do not actively work on). Personally, I always use https://github.com/APIDevTools/swagger-cli to validate the spec (this is not to say the spec validation feature in openapi-generator is bad or unusable).
The reason why I brought this up is that the false alarm seems to be causing quite a lot of confusions, which introduces unnecessary overhead in support.
We can try the latest swagger parser to see if the false alarms go away before deciding what to do next.
Please try the latest master with the upgrade parser to see if it's still an issue.
Description
There is an attribute path error being thrown when using #ref for path parameters. All of my research says that this is a valid spec. Am I missing something obvious?
openapi-generator version
4.0.0-SNAPSHOT
OpenAPI declaration file content or url
member.yaml
shared.yaml
Command line used for generation
openapi-generator validate -i member.yaml
Steps to reproduce
Just run the command above against member.yaml. The shared.yaml file must be in the same directory as member.yaml.
Error being thrown