Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9047
Closed
Open
Issue created Mar 22, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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

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.

Assignee
Assign to
Time tracking