Skip to content

References to incorrect components should be considered invalid #171

Open

Description

@charjr

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)

Activity

  1. SOHELAHMED7 commented on Dec 29, 2022

    @SOHELAHMED7
    Contributor

    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 ...) {
  2. changed the title [-]openApi->validate returns true with invalid response $ref[/-] [+]References to incorrect components should be considered invalid[/+] on Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions