Skip to content

Instantly share code, notes, and snippets.

@JamesMessinger
Last active July 31, 2018 09:13
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JamesMessinger/09dd37c80d3324908ff0 to your computer and use it in GitHub Desktop.
Save JamesMessinger/09dd37c80d3324908ff0 to your computer and use it in GitHub Desktop.
Example of using `allOf` to extend an object in a Swagger API
swagger: "2.0"
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
properties:
id:
type: integer
format: int32
x-mysql-type: int(11)
NewsArticleExt: # tmp
title: NewsArticleExt
type: object
allOf:
- $ref: "#/definitions/NewsArticle"
- properties:
test:
type: string
@Zhuinden
Copy link

  Pet:
    allOf:
      - $ref: '#/definitions/NewPet'
    required:
      - id
    properties:
      id:
        type: integer
        format: int64

  NewPet:
    required:
      - name  
    properties:
      name:
        type: string
      tag:
        type: string

@teliov
Copy link

teliov commented Dec 2, 2016

Actually this should be something like this

swagger: "2.0"
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
      properties:
          id:
              type: integer
              format: int32
              x-mysql-type: int(11)
  NewsArticleExt: # tmp
      title: NewsArticleExt
      type: object
      allOf:
          - $ref: "#/definitions/NewsArticle"
          - type: object
            properties:
              test:
                  type: string

@erm3nda
Copy link

erm3nda commented Aug 26, 2017

Lol, in your examples the /users path items has no schema defined, so are not calling any of the definitions...

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