2

I'm using Swagger, one of the Open API tools to define an API.

For example, I have an object NameValue { propertyName: propertyValue}

How to let Sagger allow propertyValue could be integer, string, boolean.

NameValue:
   type: "object"
   required:
     - "propertyName"
   properties:
     propertyName:
       type: allow integer, string, boolean.

I have try

   propertyName:
    oneOf:
      - type: "integer"
      - type: "string"
      - ypte: "boolean"

But it does not work. I have searched the google, but find nothing about this.

EvanL00
  • 370
  • 3
  • 13
  • Are you using `swagger: "2.0"` or `openapi: 3.0.0`? – Helen Mar 28 '18 at 10:32
  • @Helen Swagger "2.0" – EvanL00 Mar 29 '18 at 02:29
  • Possible duplicate of [oneOf in Swagger schema does not work](https://stackoverflow.com/questions/36872277/oneof-in-swagger-schema-does-not-work) – Helen Mar 29 '18 at 10:24
  • See the linked question. `oneOf` and `anyOf` are only supported in OpenAPI 3.0 but not in OpenAPI/Swagger 2.0. – Helen Mar 29 '18 at 10:24
  • @Helen I think this is a different question. Because what I want to achieve is to specify a value to be more than one type. The link question is specify an entity to be more than one kind. – EvanL00 Apr 02 '18 at 01:10
  • It's exactly the same question. And the answer is the same - you need `oneOf` as in your 2nd example, but it's only supported in `openapi: 3.0.0` but not `swagger: '2.0'`. (Your 2nd example is a valid OpenAPI 3.0 property definition). – Helen Apr 02 '18 at 06:50

0 Answers0