Skip to content

Instantly share code, notes, and snippets.

@shockey
Forked from JamesMessinger/NewsArticle.yaml
Last active November 3, 2017 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shockey/63f4415ff08672f3e8039c3d7a4fcd7f to your computer and use it in GitHub Desktop.
Save shockey/63f4415ff08672f3e8039c3d7a4fcd7f to your computer and use it in GitHub Desktop.
Example of using `allOf`, `anyOf`, `oneOf`, and `not` to describe a schema in an OpenAPI spec. Also includes a nullable schema.
# Invalid! Used for testing 3.0 version-guarding in the UI rendering.
swagger: "2.0"
servers: []
info:
version: 1.0.0
title: minimal
description: News Articles ftw
paths:
/users:
get:
responses:
'200':
description: hello world
definitions:
NewsArticle:
title: NewsArticle
type: object
nullable: true
properties:
id:
type: integer
format: int32
x-mysql-type: int(11)
allOfNewsArticle:
title: allOfNewsArticle
type: object
allOf:
- $ref: '#/definitions/NewsArticle'
- properties:
articleBody:
type: string
anyOfNewsArticle:
title: anyOfNewsArticle
type: object
anyOf:
- $ref: '#/definitions/NewsArticle'
- properties:
articleBody:
type: string
oneOfNewsArticle:
title: oneOfNewsArticle
type: object
oneOf:
- $ref: '#/definitions/NewsArticle'
- properties:
articleBody:
type: string
notNewsArticle:
title: notNewsArticle
type: object
allOf:
- $ref: '#/definitions/NewsArticle'
- not:
articleBody:
type: string
responses: {}
parameters: {}
examples: {}
requestBodies: {}
securitySchemes: {}
headers: {}
openapi: 3.0.0-RC1
servers: []
info:
version: 1.0.0
title: minimal
description: News Articles ftw
paths:
/users:
get:
responses:
'200':
description: hello world
components:
schemas:
NewsArticle:
title: NewsArticle
type: object
nullable: true
properties:
id:
type: integer
format: int32
x-mysql-type: int(11)
allOfNewsArticle:
title: allOfNewsArticle
type: object
allOf:
- $ref: '#/components/schemas/NewsArticle'
- properties:
articleBody:
type: string
anyOfNewsArticle:
title: anyOfNewsArticle
type: object
anyOf:
- $ref: '#/components/schemas/NewsArticle'
- properties:
articleBody:
type: string
oneOfNewsArticle:
title: oneOfNewsArticle
type: object
oneOf:
- $ref: '#/components/schemas/NewsArticle'
- properties:
articleBody:
type: string
notNewsArticle:
title: notNewsArticle
type: object
allOf:
- $ref: '#/components/schemas/NewsArticle'
- not:
articleBody:
type: string
responses: {}
parameters: {}
examples: {}
requestBodies: {}
securitySchemes: {}
headers: {}
@hkosova
Copy link

hkosova commented Aug 2, 2017

The value of not should be a schema, so it should be

        - not:
            properties:
              articleBody:
                type: string

or

        - not:
            type: string

etc.

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