question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allOf not supported in multifiles spec

See original GitHub issue

I have discovered that “allOf” seems to be unsupported when using multiple files.

If I have this simplified version of petstore.yaml in a single file, everything is ok:

swagger.yaml

swagger: '2.0'
info:
  version: '1.0.0'
  title: Swagger Petstore (Simple)
  description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
  termsOfService: http://helloreverb.com/terms/
  contact:
    name: Swagger API team
    email: foo@example.com
    url: http://swagger.io
  license:
    name: MIT
    url: http://opensource.org/licenses/MIT
host: petstore.swagger.io
basePath: /api
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /pets:
    get:
      description: Returns all pets from the system that the user has access to
      operationId: findPets
      produces:
        - application/json
        - application/xml
        - text/xml
        - text/html
      parameters:
        - name: tags
          in: query
          description: tags to filter by
          required: false
          type: array
          items:
            type: string
          collectionFormat: csv
        - name: limit
          in: query
          description: maximum number of results to return
          required: false
          type: integer
          format: int32
      responses:
        '200':
          description: pet response
          schema:
            type: array
            items:
              $ref: '#/definitions/ShippingInfo'
definitions:
  PrintInfo:
    type: object
    description: "Print info of the shipping info"
    required:
      - B
    properties:
      B:
        type: boolean
  ShippingInfo:
    type: object
    description: "Information about the shipping for a device"
    allOf:
      - $ref: "#/definitions/PrintInfo"
      - type: object
        required:
          - A
        properties:
          A:
            type: integer
            format: int64

If I do the same thing, but using 2 files, PrintInfo is not in the definitions and ShippingInfo only contains the field A (should contain A and B)

swagger.yaml

swagger: '2.0'
info:
  version: '1.0.0'
  title: Swagger Petstore (Simple)
  description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
  termsOfService: http://helloreverb.com/terms/
  contact:
    name: Swagger API team
    email: foo@example.com
    url: http://swagger.io
  license:
    name: MIT
    url: http://opensource.org/licenses/MIT
host: petstore.swagger.io
basePath: /api
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /pets:
    get:
      description: Returns all pets from the system that the user has access to
      operationId: findPets
      produces:
        - application/json
        - application/xml
        - text/xml
        - text/html
      parameters:
        - name: tags
          in: query
          description: tags to filter by
          required: false
          type: array
          items:
            type: string
          collectionFormat: csv
        - name: limit
          in: query
          description: maximum number of results to return
          required: false
          type: integer
          format: int32
      responses:
        '200':
          description: pet response
          schema:
            type: array
            items:
              $ref: './definitions.yaml#/definitions/ShippingInfo'

definitions.yaml

definitions:
  PrintInfo:
    type: object
    description: "Print info of the shipping info"
    required:
      - B
    properties:
      B:
        type: boolean
  ShippingInfo:
    type: object
    description: "Information about the shipping for a device"
    allOf:
      - $ref: "#/definitions/PrintInfo"
      - type: object
        required:
          - A
        properties:
          A:
            type: integer
            format: int64

The only difference between these 2 examples is the fact that one is in one file and the other is in 2 files. @gracekarina This might interest you, it is highly related to this: https://github.com/swagger-api/swagger-parser/issues/581

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gracekarinacommented, Jan 8, 2018

Please write a new one

1reaction
JFCotecommented, Jan 8, 2018

It seems to work and already be in the v2.4 of swagger-codegen! Thanks a lot @gracekarina

Read more comments on GitHub >

github_iconTop Results From Across the Web

oneOf, anyOf, allOf, not - Swagger
oneOf – validates the value against exactly one of the subschemas; allOf ... Besides these, there is a not keyword which you can...
Read more >
Understanding JSON Schema 2020-12 documentation
allOf ; anyOf; oneOf; not; Properties of Schema Composition ... Note that this doesn't necessarily mean combining schemas from multiple files or JSON...
Read more >
How to use multiple references in OpenAPI 3 yaml file's paths ...
I tried to use allOf , but it leads to Property allOf is not allowed. error. The create.yml file is this: post: tags:...
Read more >
OpenAPI Specification
Throughout the specification description fields are noted as supporting ... allOf - Inline or referenced schema MUST be of a Schema Object and...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
Tooling which supports OAS 3.1 SHOULD be compatible with all OAS 3.1.* versions. The patch version SHOULD NOT be considered by tooling, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found