Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Closed
damonhook opened this issue Apr 21, 2023 · 1 comment · Fixed by #210
Closed

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

damonhook opened this issue Apr 21, 2023 · 1 comment · Fixed by #210

Comments

@damonhook
Copy link

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

@damonhook
Copy link
Author

damonhook commented Apr 21, 2023

Possible Remediation

It looks like changing #/$defs/path-item to #/$defs/path-item-or-reference in [$defs][paths] seems to work as expected

"paths": {
"type": "object",
"patternProperties": {
"^/": {
"$ref": "#/$defs/path-item"
}
},
"$ref": "#/$defs/specification-extensions",
"unevaluatedProperties": false
},

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.

1 participant