OpenAPITools / OpenAPITools/openapi-generator
[BUG][validate] Component with a property pointing to a missing $ref incorrectly passes validation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Spec files with that have a component with a property pointing to a missing $ref are not currently flagged as an issue by the built-in validator.
openapi-generator version
The current latest docker image is digest 4e5bf573bce9.
OpenAPI declaration file content or url
I took this sample file and modified it like so:
18:18 $ git diff
diff --git i/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml w/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml
index 31100fda527..d828e997ec6 100644
--- i/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml
+++ w/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml
@@ -775,7 +775,7 @@ components:
format: int64
type: integer
category:
- $ref: '#/components/schemas/Category'
+ $ref: '#/components/schemas/DoesNotExist'
name:
example: doggie
type: string
✔ ~/code/openapi-generator/samples [master|✚ 1]
Generation Details
N/A, this only deals with validation.
Steps to reproduce
In general:
- Validate file with a component with a property pointing to a missing $ref
- File passes validation when it shouldn't.
Specifically
First ensure a valid file:
- Run
docker run --rm -v $PWD/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml:/tmp/openapi.yaml openapitools/openapi-generator-cli:latest validate -i /tmp/openapi.yamlpasses validation, as expected. - Run
docker run --rm -v $PWD/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml:/tmp/openapi.yml stoplight/spectral lint /tmp/openapi.ymlto confirm - edit
$PWD/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yamlwith above modifications, introducing a component with a property pointing to a missing $ref - Run
docker run --rm -v $PWD/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml:/tmp/openapi.yaml openapitools/openapi-generator-cli:latest validate -i /tmp/openapi.yamlstill passes validation, which is unexpected. - Run
docker run --rm -v $PWD/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml:/tmp/openapi.yml stoplight/spectral lint /tmp/openapi.ymlagain and the error is correctly reported.
These edits also fail validation against https://apidevtools.org/swagger-parser/online
Full output of these commands is in this gist.
Related issues/PRs
I queried "ref validate" and found issues close to this, but none focused just on validation.
Suggest a fix
Components with a property pointing to a missing $ref should be considered invalid.
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 the validate -i CLI command and reproduce the issue using samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml, changing the Category reference to DoesNotExist. Compare the built-in validator result with Spectral and the swagger-parser result; done means the missing component property reference is reported as invalid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- api, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100