Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

bundling anyOf schema's #59

Open
viper90 opened this issue Mar 8, 2021 · 2 comments
Open

bundling anyOf schema's #59

viper90 opened this issue Mar 8, 2021 · 2 comments

Comments

@viper90
Copy link

viper90 commented Mar 8, 2021

When I try to bundle a set of schemas in a path using "anyOf" or "oneOf", the schemas are invalid. Tried adding a unique name for each of the schemas and adding/removing indentation, however this still didn't allow this usage to be bundled in to the flat file. Instead I have re-structured the output bundled file manually and move the schemas under components: schemas: and then manually create the $ref's for each of the schemas. I'm not sure if I added something to the schema file at the beginning, if this would then render correctly perhaps?

Current output when bundled:

paths:
  /workflow/request:
    post:
      summary: Workflow Trigger
      description: Triggers one of the many workflows.
      requestBody:
        content:
          application/json:
            schema:
              anyOf:
                - retrieve:
                    type: object
                    properties:
                      id:
                        type: string
                        description: Associated asset ID used for tracking or filenames.
                      operation:
                        type: string
                        description: Used to look up variables within the sub workflow.
                    required:
                      - id
                      - operation
                - transfer:
                    type: object
                    properties:
                      id:
                        type: string
                        description: Associated asset ID used for tracking or filenames.
                      operation:
                        type: string
                        description: Used to look up variables within the sub workflow.
                    required:
                      - id
                      - operation
                - list:
                    type: object
                    properties:
                      id:
                        type: string
                        description: Associated asset ID used for tracking or filenames.
                      operation:
                        type: string
                        description: Used to look up variables within the sub workflow.
                    required:
                      - id
                      - operation
                - find:
                    type: object
                    properties:
                      id:
                        type: string
                        description: Associated asset ID used for tracking or filenames.
                      operation:
                        type: string
                        description: Used to look up variables within the sub workflow.
                    required:
                      - id
                      - operation
                - copy:
                    type: object
                    properties:
                      id:
                        type: string
                        description: Associated asset ID used for tracking or filenames.
                      operation:
                        type: string
                        description: Used to look up variables within the sub workflow.
                    required:
                      - id
                      - operation
      responses:
        '200':
          description: OK
  

Working bundle:

/workflow/request:
    post:
      requestBody:
        content:
          application/json:
            schema:
              anyOf:
                - $ref: "#/components/schemas/retrieve"
                - $ref: "#/components/schemas/delete"
                - $ref: "#/components/schemas/create"
                - $ref: "#/components/schemas/transfer"
                - $ref: "#/components/schemas/upload"
                - $ref: "#/components/schemas/list"
                - $ref: "#/components/schemas/find"
                - $ref: "#/components/schemas/difference"
                - $ref: "#/components/schemas/copy"

components:
     schemas:
      retrieve:
        type: object
        properties:
          id:
            type: string
            description: Associated asset ID used for tracking or filenames.
          operation:
            type: string
            description: Used to look up variables within the sub workflow.
        required:
          - id
          - operation
      transfer:
        type: object
        properties:
          id:
            type: string
            description: Associated asset ID used for tracking or filenames.
          operation:
            type: string
            description: Used to look up variables within the sub workflow.
        required:
          - id
          - operation
      list:
        type: object
        properties:
          id:
            type: string
            description: Associated asset ID used for tracking or filenames.
          operation:
            type: string
            description: Used to look up variables within the sub workflow.
        required:
          - id
          - operation
      find:
        type: object
        properties:
          id:
            type: string
            description: Associated asset ID used for tracking or filenames.
          operation:
            type: string
            description: Used to look up variables within the sub workflow.
        required:
          - id
          - operation
      copy:
        type: object
        properties:
          id:
            type: string
            description: Associated asset ID used for tracking or filenames.
          operation:
            type: string
            description: Used to look up variables within the sub workflow.
        required:
          - id
          - operation
@chriskolenko
Copy link

I got the same issue with allOf too FYI.

@chriskolenko
Copy link

For people reading along I found a work around.

Structure of my project:

  • api.yaml
  • commands.yaml

Command to generate:
swagger-cli bundle api.yaml --outfile _build/api.yaml --type yaml

I was having issues because inside the commands.yaml where I had the following:

    NewObj:
      allOf:
        - $ref: '#/components/schemas/Command'
        - required:
            - description
            ....

After bundling the Command ref was expanded. Which wasn't what I wanted.

The work around:

Add the following to the api.yaml file:

components:
  schemas:
    Command:
      $ref: './commands.yaml#/components/schemas/Command'

The resulting bundled file will now contain the $ref BANG!

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

No branches or pull requests

2 participants