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

Support anyOf, oneOf, and not in ExampleBuilder in 3.0 #215

Closed
gracekarina opened this issue Nov 1, 2017 · 5 comments
Closed

Support anyOf, oneOf, and not in ExampleBuilder in 3.0 #215

gracekarina opened this issue Nov 1, 2017 · 5 comments
Assignees
Labels

Comments

@gracekarina
Copy link
Contributor

Support anyOf, oneOf, and not in ExampleBuilder in 3.0

Right now inflector only supports allOf.

@gracekarina gracekarina self-assigned this Nov 1, 2017
@hkosova
Copy link

hkosova commented Nov 2, 2017

Assuming ExampleBuilder is supposed to return the first subschema from anyOf and oneOf,

given this spec

openapi: 3.0.0
info:
  version: 0.0.0
  title: test

paths:
  /oneOf:
    get:
      responses:
        '200':
          description: A book or movie object
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Book'
                  - $ref: '#/components/schemas/Movie'

  /anyOf:
    get:
      responses:
        '200':
          description: A book or movie object
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/Movie'
                  - $ref: '#/components/schemas/Book'
  
  /mixed-array:
    get:
      responses:
        '200':
          description: An array containing strings and/or integers
          content:
            application/json:
              schema:
                type: array
                items:
                  oneOf:
                    - type: string
                    - type: integer

components:
  schemas:
    Book:
      type: object
      properties:
        title:
          type: string
        authors:
          type: array
          items:
            type: string
        isbn:
          type: string
      required:
        - title
      example:
        title: The Hitchhiker's Guide to the Galaxy
        authors:
          - Douglas Adams
        isbn: 0-330-25864-8
    Movie:
      type: object
      properties:
        title:
          type: string
        directors:
          type: array
          items:
            type: string
        year:
          type: integer
      required:
        - title
      example:
        title: Blade Runner
        directors:
          - Ridley Scott
        year: 1982

/oneOf should return a book:

{
  "title": "The Hitchhiker's Guide to the Galaxy",
  "authors": [
    "Douglas Adams"
  ],
  "isbn": "0-330-25864-8"
}

/anyOf should return a movie:

{
  "title": "Blade Runner",
  "directors": [
    "Ridley Scott"
  ],
  "year": 1982
}

and /mixed-array should return a string array:

[
  "string"
]

@gracekarina
Copy link
Contributor Author

@hkosova Thanks Helen, do you have a spec with not

@hkosova
Copy link

hkosova commented Nov 20, 2017

@gracekarina

openapi: 3.0.0
info:
  version: 0.0.0
  title: not models
paths:
  /NotString:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                $ref: '#/components/schemas/NotString'
  /NotStringInlineSchema:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                not:
                  type: string
  /NotNumber:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                $ref: '#/components/schemas/NotNumber'
  /NotNumberInlineSchema:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                not:
                  anyOf:
                    - type: number
                    - type: integer
  /ArrayOfNotString:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                $ref: '#/components/schemas/ArrayOfNotString'
  /ArrayOfNotStringInlineSchema:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                type: array
                items:
                  not:
                    type: string
  /NotUserObject:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                $ref: '#/components/schemas/NotUser'
  /NotUserObjectInline:
    get:
      responses:
        '200':
          description: OK
          content:
            application/yaml:
              schema:
                not:
                  $ref: '#/components/schemas/User'
components:
  schemas:
    NotString:
      not:
        type: string
    NotNumber:
      not:
        anyOf:
          - type: number
          - type: integer
    NotUser:
      not:
        $ref: '#/components/schemas/User'
    ArrayOfNotString:
      type: array
      items:
        not:
          type: string

    User:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
      required: [id, name]

@gracekarina
Copy link
Contributor Author

the inflector currently supports anyOf and OneOf, the not is not supported yet.

@gracekarina
Copy link
Contributor Author

support of not, done!

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

No branches or pull requests

2 participants