javanile / yamlinc

Compose multiple YAML files into one with $include tag. Split Swagger/OpenAPI into multiple YAML files.
MIT License
114 stars 22 forks source link

Sanitize each element of an array #5

Closed stefancarlton closed 6 years ago

stefancarlton commented 6 years ago

I spotted a flaw when working with Swagger and using this tool - including within an array context (e.g. Swagger's parameter list) it returns an object rather than an array as it does for objects

base.yml

object:
  bob:
    type: "string"
    enum:
      $include: "items.yml"
fred:
  - type: "string"
    enum:
      $include: "items.yml"

items.yml

- "item1"
- "item2"
- "item3"

Output

## --------------------
## DON'T EDIT THIS FILE
## --------------------
## Engine: yamlinc@0.0.64
## Source: base.yml

object:
  bob:
    type: string
    enum:
      - item1
      - item2
      - item3
fred:
  - type: string
    enum:
      '0': item1
      '1': item2
      '2': item3

With this fix in place:

object:
  bob:
    type: string
    enum:
      - item1
      - item2
      - item3
fred:
  - type: string
    enum:
      - item1
      - item2
      - item3

My JS foo is a work in progress so there might be a better solution?

francescobianco commented 6 years ago

@stefancarlton Thanks for your support!!!! :smiley: