OpenAPITools / OpenAPITools/openapi-generator
[BUG] Using $ref under components/schema results in spec validation failure
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
A spec like this:
openapi: 3.0.3
info:
title: api spec
version: 1.0.0
servers:
- url: /v3
components:
schemas:
$ref: './definitions/_index.yaml'
...
Results in validation error(s):
xception 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: 2, Warning count: 0
Errors:
-attribute components.schemas.$ref is not of type `object`
-attribute components.schemas.Schema name $ref doesn't adhere to regular expression ^[a-zA-Z0-9\.\-_]+$
at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:544)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:571)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:433)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
This is using docker.io/openapitools/openapi-generator-cli:latest (image id: e718a88b4de4). The spec with the schemas changed as below passes the validation:
openapi: 3.0.3
info:
title: api spec
version: 1.0.0
servers:
- url: /v3
components:
schemas:
UnauthorizedError:
$ref: "./definitions/unauthorized_error.yaml"
NotFoundError:
$ref: "./definitions/not_found_error.yaml"
...
According to 3.0 docs a $ref element should be valid immediately under schema.
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
Reproduce the validation failure with the OpenAPI 3.0.3 example, then trace the validation path from CodegenConfigurator.java through Generate.java and OpenAPIGenerator.java. Done means a components.schemas.$ref pointing to an external definitions file validates without requiring individually named schema entries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, yaml
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100