[BUG][validate] Component with a property pointing to a missing $ref incorrectly passes validation
Created by: ml10
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.yaml
passes 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.yml
to confirm - edit
$PWD/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml
with 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.yaml
still 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.yml
again 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.