Additional properties not allowed: oneOf

Originally posted by superh2m on February 04, 2019

Hi everyone !

It’s been few days that I’m trying to create a “clean” configuration with swagger, but swagger-cli doesn’t validate some of it.

To explain the context, first of all I use swagger-cli with swagger-ui, and I bundle the following output used by swagger-ui with swagger-cli :

"choices": {    "type": "array",    "description": "The choices",    "items": {        "anyOf": [            { "$ref": "../../../choice/choice.boolean.output.json" },            { "$ref": "../../../choice/choice.integer.output.json" },            { "$ref": "../../../choice/choice.text.output.json" }        ]    }}

And everytime I’m trying to validate the schema with the following command :

swagger-cli validate api-description.yaml

I have the same error :

Additional properties not allowed: oneOf at #/properties/.../items/properties/choices 

I try lot of combinations with docs :

https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

https://swagger.io/docs/specification/data-models/data-types/

https://swagger.io/docs/specification/describing-responses/

And I notice something weird about that, that I’m able to bundle it with the same package swagger-cli and display part of it in the swagger-ui “Example value” section :

But in the model view I have an empty model :

Screenshot from 2019-02-04 13-34-01.png

Do you know why ?

I really need help :frowning:

Originally posted by HKosova on February 04, 2019

Is your definition

"swagger": "2.0"

or

"openapi": "3.0.0"

?

“anyOf” was introduced in OpenAPI 3.0 and is not supported in OpenAPI/Swagger 2.0.

Originally posted by superh2m on February 04, 2019

swagger: "2.0"

:confused:

It will never be supported in Swagger ?

But why in the github https://github.com/swagger-api/swagger-core it’s marked the version 2.0 it’s compatible with the version OpenAPI 3.0 ?

Originally posted by HKosova on February 04, 2019

You need Swagger Core 2.x in order to use OpenAPI 3.0 features such as oneOf.

The “swagger”: “2.0” and “openapi”: “3.0.0” identifiers in an API definition are versions of the OpenAPI Specification, which defines the syntax and keywords you can use. Swagger Core is a library that implements OpenAPI Spec. Please see What Is the Difference Between Swagger and OpenAPI?