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

additionalProperties support? #33

Closed
yohanboniface opened this issue Apr 25, 2018 · 3 comments
Closed

additionalProperties support? #33

yohanboniface opened this issue Apr 25, 2018 · 3 comments

Comments

@yohanboniface
Copy link

Hi,

Not sure if I'm doing something wrong or if additionalProperties is missing proper support.

Here is my test case:

from openapi_core import create_spec
from openapi_core.wrappers import MockRequest, MockResponse
from openapi_core.validators import ResponseValidator


schema = {
    "components": {
        "schemas": {
            "Errors": {
                "additionalProperties": {
                    "type": "string"
                },
                "type": "object"
            }
        }
    },
    "info": {
        "title": "xxx",
        "version": "1.0.0"
    },
    "openapi": "3.0.0",
    "paths": {
        "/simulate": {
            "get": {
                "responses": {
                    "422": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Errors"
                                }
                            }
                        },
                        "description": "Error in data"
                    }
                }
            }
        }
    }
}


spec = create_spec(schema)

validator = ResponseValidator(spec)
request = MockRequest('http://localhost', 'get', '/simulate')
response = MockResponse('{"error_key": "message"}', 422)
result = validator.validate(request, response)
result.raise_for_errors()

Which raises the error openapi_core.exceptions.UndefinedSchemaProperty: Undefined properties in schema: {'error_key'}.

I'm expecting instead that any key is allowed in the Error schema, given I'm using additionalProperties (see http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.6 and this discussion).

Thanks for your inputs on this! :)

@p1c2u
Copy link
Collaborator

p1c2u commented Apr 27, 2018

@yohanboniface thnks for the bug report. You're right, additionalProperties support is missing atm. I will try to add it shortly.

@yohanboniface
Copy link
Author

Thanks!

@yohanboniface
Copy link
Author

@p1c2u one subtle subcase of this: according to the documentation, additionalProperties should also accept boolean values, eg.: additionalProperties: true, which if I get it right means "additional properties with any type are accepted":

additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.

Also, it seems that additionalProperties: true should considered as the default starting from OpenAPI 3.0, at least this will be in the documentation starting at 3.0.2, see this change: https://github.com/OAI/OpenAPI-Specification/pull/1548/files. Not sure though if this should be already reflected here or not.

Thanks! :)

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

2 participants