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

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^\\/']['patternProperties']['^(get|put|post|delete|options|head|patch|trace)$']['properties']['parameters']['items']: #116

Open
spaceone opened this issue Mar 2, 2021 · 2 comments

Comments

@spaceone
Copy link

spaceone commented Mar 2, 2021

I get:

{'in': 'query', 'name': 'bar', 'example': '1', 'examples': {'1': {'summary': '1', 'value': '1'}, '2': {'summary': '2', 'value': '2'}}, 'schema': {'type': 'string'}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^\\/']['patternProperties']['^(get|put|post|delete|options|head|patch|trace)$']['properties']['parameters']['items']:
    {'oneOf': [{'$ref': '#/definitions/Parameter'},
               {'$ref': '#/definitions/Reference'}]}

On instance['paths']['/']['get']['parameters'][0]:
    {'$ref': '#/components/parameters/foo',
     'x-scope': ['file:///usr/share/ucs-test/73_udm-rest/openapi2.json']}

for

{
    "components": {
        "parameters": {
            "foo": {
                "in": "query",
                "name": "bar",
                "example": "1",
                "examples": {
                    "1": {
                        "summary": "1",
                        "value": "1"
                    },
                    "2": {
                        "summary": "2",
                        "value": "2"
                    }
                },
                "schema": {
                    "type": "string"
                }
            }
        }
    },
    "info": {
        "description": "",
        "title": "",
        "version": "1.0.0"
    },
    "openapi": "3.0.0",
    "paths": {
       "/": {
            "get": {
                "parameters": [
                    {
                        "$ref": "#/components/parameters/foo"
                    }
                ],
                "responses": { "200": {"description": "", "content": {"text/plain": {"schema": {"type": "string"}}}} }
            }
        }
    }
}

since openapi-spec-validator==0.3.0. It succeeded to validate with openapi-spec-validator==0.2.10.
If I remove one of example or examples from #/components/parameters/foo the validation succeeds.

Does openapi define them as mutually exclusive?
https://swagger.io/docs/specification/adding-examples/ doesn't seem to contain a mix. The swagger UI just sucks in displaying examples.

@p1c2u
Copy link
Collaborator

p1c2u commented Mar 28, 2021

Hi @spaceone

yes you're right, example and examples are mutually exclusive

Example of the parameter’s potential value. The example SHOULD match the specified schema and encoding properties if present. The example field is mutually exclusive of the examples field. Furthermore, if referencing a schema that contains an example, the example value SHALL override the example provided by the schema. To represent examples of media types that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary.

See https://spec.openapis.org/oas/v3.0.3#fixed-fields-9

@Altreus
Copy link

Altreus commented May 19, 2021

Also see #126 - the error is in components/schemas/foo but the problem is not being reported there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants