OpenAPITools / OpenAPITools/openapi-generator

[BUG][validate] Component with a property pointing to a missing $ref incorrectly passes validation

Open
#9,047 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Full file

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:

  1. Validate file with a component with a property pointing to a missing $ref
  2. File passes validation when it shouldn't.

Specifically
First ensure a valid file:

  1. 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.
  2. 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
  3. 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
  4. 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.
  5. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.