Skip to content

Using $ref for path items not working with OpenAPI 3.1 specs #207

Closed
@damonhook

Description

@damonhook

Summary

Using a $ref for path items results in a validation error even though doing so is valid as per the OpenAPI 3.1 spec (here)

Minimal Example

openapi.yaml file

openapi: 3.1.0

info:
  title: Example API
  version: 1.0.0

paths:
  /:
    $ref: "#/components/pathItems/rootPath"

components:
  pathItems:
    rootPath:
      get:
        responses:
          200:
            description: Example Response

Running

openapi-spec-validator openapi.yaml

Results in

# Validation Error

Unevaluated properties are not allowed ('$ref' was unexpected)

Failed validating 'unevaluatedProperties' in schema['properties']['paths']['patternProperties']['^/']:
    {'$ref': '#/$defs/specification-extensions',
     'patternProperties': {'^(get|put|post|delete|options|head|patch|trace)$': {'$ref': '#/$defs/operation'}},
     'properties': {'description': {'type': 'string'},
                    'parameters': {'items': {'$ref': '#/$defs/parameter-or-reference'},
                                   'type': 'array'},
                    'servers': {'items': {'$ref': '#/$defs/server'},
                                'type': 'array'},
                    'summary': {'type': 'string'}},
     'type': 'object',
     'unevaluatedProperties': False}

On instance['paths']['/']:
    {'$ref': '#/components/pathItems/rootPath'}

Note
You can paste the above openapi.yaml file onto https://editor-next.swagger.io/ to see it working as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions