openapi-generator: [BUG] $ref to common parameter not being resolved

Description

Validation is failing to resolve a $ref in the parameter list to a common parameter defined outside the operation. Neither refs local to the same file nor refs to external files work. Both should. I’ve tried it with both Swagger 2.0 and OAS 3.0 specs, both fail the same way.

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.'/employees/{id}'. Declared path parameter id needs to be defined as a path parameter in path or operation level

	at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:569)
	at org.openapitools.codegen.cmd.Generate.run(Generate.java:346)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:62)
openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test
  description: Test YAML
  version: '1.0'
servers:
  - url: http://localhost
paths:
  /employees/{id}:
    get:
      operationId: getEmployeeById
      parameters:
        - $ref: '#/components/parameters/id'
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/employee'
components:
  schemas:
    employee:
      type: object
      properties:
        name:
          type: string
      required:
        - name
  parameters:
    id:
      name: id
      in: path
      required: true
      schema:
        type: string
Command line used for generation

java -jar openapi-generator-cli-4.0.0-20181217.102953-101.jar generate -g html -i test.yaml

Related issues/PRs

#455 seems to be related. But that one was resolved. So that makes this a regression.

Suggest a fix

This could be another issue with the swagger-parser like in #455.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 34 (7 by maintainers)

Commits related to this issue

Most upvoted comments

For those following this issue or https://github.com/OpenAPITools/openapi-generator/issues/2631, swagger-parser was updated: https://github.com/OpenAPITools/openapi-generator/pull/2775 and I’ve confirmed that the validate function is no longer returning erroneous There are duplicate parameter values messages. So https://github.com/swagger-api/swagger-parser/issues/1063 has now been fixed in openapi-generator. 🎉

It works fine with 3.3.4.

I believe the new issue is now fixed upstream in https://github.com/swagger-api/swagger-parser/issues/1063

It looks like they cut release 2.0.12 of swagger-parser 18 hours ago with these fixes, so hopefully this can get bumped here soon.

Please try the latest master with the upgrade parser to see if it’s still an issue.

Sorry I should be more clear @advance512:

Using parameters which involves refs was previously broken by swagger-api/swagger-parser#911 which was fixed by pulling in the upstream change in swagger-parser.

Using parameters which involves refs is now broken because of another issue in swagger-parser - swagger-api/swagger-parser#1063 which is not yet fixed upstream, so if you’re using refs under path parameters, you still have to disable verification on master (and V4 betas) of openapi-generator.

I assume this happens in all client generators - maybe we can remove the client:HTML tag?

As requested by @wing328 I tested with --skip-validate-spec and got the same results as @ericraymond. It lists the error but completes the work.

Obviously that’s not a valid long term solution for something that worked in the previous release.

@john3300 can you try with --skip-validate-spec? I tried to repeat the issue with the spec you provided but couldn’t after using the --skip-validate-spec option.

I can’t see how to add a label to this issue, but I think it should also have Issue: Regression