Skip to content

Parser: YAML anchors & aliases depend on declaration order #609

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

Closed
rdrey opened this issue Aug 27, 2015 · 2 comments
Closed

Parser: YAML anchors & aliases depend on declaration order #609

rdrey opened this issue Aug 27, 2015 · 2 comments

Comments

@rdrey
Copy link

rdrey commented Aug 27, 2015

Hi

This following example works:

    swagger: '2.0'

    info:
      version: "0.0.1"
      title: API

    definitions:      
      OperationType:
        type: string
        enum: &OperationType
        - registration

    # Describe your paths here
    paths:
      /checker:
        get:
          parameters:
            - name: operations
              in: query
              type: array
              items:
                type: string
                enum: *OperationType
              default: [registration]
          responses:
            200:
              description: OK
              schema:
                $ref: '#/definitions/OperationType'

But if the order of paths: and definitions: is reversed, it results in the following error:

YAML Syntax Error
Unidentified alias "OperationType" at line 17, column 37: enum: *OperationType ^

This is probably an error in the YAML Parsing dependency, but I'm not sure.

Thanks!

@mohsen1
Copy link
Contributor

mohsen1 commented Aug 27, 2015

Yes, in YAML you should define an alias before using it. If you put definitions after paths the OperationType anchor is used before being defined. I recommend defining all of your anchors on top under a free-form swagger extension

swagger: '2.0'

info:
  version: "0.0.1"
  title: API

x-types:
  OperationType: &OperationType
    - registration

# Describe your paths here
paths:
  /checker:
    get:
      parameters:
        - name: operations
          in: query
          type: array
          items:
            type: string
            enum: *OperationType
          default: [registration]
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/OperationType'

definitions:      
  OperationType:
    type: string
    enum: *OperationType

@rdrey
Copy link
Author

rdrey commented Aug 27, 2015

Ah, thanks! I wasn't aware this was a YAML limitation (even though the examples I've found all declared the anchors first). Will follow your example and declare some lists up top.

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

No branches or pull requests

2 participants