Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

$ref in properties being treated as a JSONSchema reference #133

Closed DanStory closed 2 years ago

DanStory commented 2 years ago

We have an OpenAPI spec with definitions that describe some limited JSONSchema, as the API endpoint returns JSONSchema itself.

Updating openapi-enforcer from 1.13.0 to 1.17.0 has a bug/error when the OpenAPI spec is parsed

TypeError: value.$ref.split is not a function or its return value is not iterable
    at parse (.../node_modules/openapi-enforcer/src/ref-parser.js:291:49)

Basically the definition has a $ref under properties to describe an actual object property and seems to trip up thinking it is a JSONSchema reference when it isn't. example:

    "definitions": {
        "Schema": {
            "properties": {
                "$ref": {
                    "type": "string"
                }
            },
            "required": [
                "$ref"
            ],
            "type": "object"
        }
    }
Gi60s commented 2 years ago

Hey Dan.

Sorry for the slow response.

I think I know how to fix this. Give me a few days.

Gi60s commented 2 years ago

I've published a fix to npm as version 1.17.1. Thanks for reporting the issue. Let me know if there are any other problems.