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

Keyword discriminator from Open API 3 Specification #35

Closed
epoberezkin opened this issue Sep 21, 2017 · 8 comments
Closed

Keyword discriminator from Open API 3 Specification #35

epoberezkin opened this issue Sep 21, 2017 · 8 comments

Comments

@epoberezkin
Copy link
Member

No description provided.

@oeN
Copy link

oeN commented Dec 4, 2018

Is this feature still planned?

@epoberezkin
Copy link
Member Author

No. This keyword is for tools only in v3, it doesn't do any validation any more.

@oeN
Copy link

oeN commented Dec 4, 2018

Sorry to bother you again.
Is there a way to have a valid swagger schema, that can be validated with Ajv, that results with the same behavior of oneOf and the discriminator keyword?

@epoberezkin
Copy link
Member Author

I may be wrong, but I think in OpenAPI v3 you must use oneOf, discriminator is just to inform the tools what is the logic behind these oneOfs. My understanding is that removing discriminator in v3 should always result in the same validation outcome (valid/invalid), but may affect error reporting or some other behaviours. So from validation point of view it can be just ignored.

@oeN
Copy link

oeN commented Dec 4, 2018

👍 thank you! I've studied a little and in the end, I've used the if/then/else and replaced the pre-commit test from swagger-cli api:test .. to ajv compile ...

@cdimascio
Copy link

cdimascio commented Nov 3, 2019

@epoberezkin for the most part, this statement is accurate, however, i believe when defaults are involved the discriminator is necessary to clear up ambiguities. That is, its role ends up being more than just informing tools.

For example, given this openapi 3 spec where TypeOne and TypeTwo are used in a oneOf and their schema have a property, value, whose default value is different depending on the discriiminator e.g. type's value. Without taking into consideration the discriminator, the wrong default can be used.

Is there a way this can be solved?

@catadch
Copy link

catadch commented Nov 5, 2019

@cdimascio raised this issue in response to one I raised with him against the otherwise excellent express-openapi-validator I'm using in a high profile project.

The schema is enormous and was intented to include many thousands of constant values. However, as discussed for over two years now, OpenAPI 3.x does not support a constant datatype, though JSON Schema does.

Our client demands the API be specified in OpenAPI 3 so I was using the "enum with one value and default" work-around in lieu of a constant type, but this broke @cdimascio's validator, and every other one I tried, when combined with discriminators for oneOf.

I do not have the luxury of waiting for a fix, but would like to know the OpenAPI community is considering this as an enhancement to the specification so my manual, ugly hack to provide consumers with easy access to thousands of identically named but differently scoped constant values can eventually be consigned to the bin.

@epoberezkin
Copy link
Member Author

created see ajv-validator/ajv#1119 for discriminator keyword

discrimitator cannot be implemented as a separate keyword, only as an extension of oneOf functionality - from validation point of view it's no-op.

Defaults are just meta-data from JSON Schema spec point of view, the spec does notdefine how it should be processed.

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

No branches or pull requests

4 participants