Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References to incorrect components should be considered invalid #171

Open
charjr opened this issue Oct 21, 2022 · 1 comment · May be fixed by #197
Open

References to incorrect components should be considered invalid #171

charjr opened this issue Oct 21, 2022 · 1 comment · May be fixed by #197

Comments

@charjr
Copy link

charjr commented Oct 21, 2022

Expected

Referencing a component that does not meet the criteria an object requires should be considered invalid.

Example

A Response object referencing a component that does not contain a "description" should be considered invalid.

image

Reasoning

"description" is a REQUIRED property for a Response object.

Actual

Referencing a component that does not meet the criteria an object requires is considered valid.

Example

$api = Reader::readFromJson(<<<JSON
{
  "openapi": "3.0.0",
  "info": {
    "title": "Test API",
    "version": "1.0.0"
  },
  "paths": {
    "/path": {
      "get": {
        "responses": {
          "200": {
            "\$ref": "#/components/schemas/notAResponse"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "notAResponse": {
        "type": "integer"
      }
    }
  }
}
JSON);

var_dump($api->validate()); // bool(true)
@SOHELAHMED7
Copy link

Concrete validation of entire OpenAPI spec doc is work in progress.

In above case validate of paths of OpenAPI is considered.

However if you want to validate schema you can see solution at https://github.com/thephpleague/openapi-psr7-validator#standalone-openapi-validator

You can get all schema as:

        $spec = \cebe\openapi\Reader::readFromYaml(...yaml...);

        // var_dump($spec->components->schemas); 

        foreach ($spec->components->schemas as ...) {

@charjr charjr changed the title openApi->validate returns true with invalid response $ref References to incorrect components should be considered invalid Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants