Mermade / openapi-filter

Filter internal paths, operations, parameters, schemas etc from OpenAPI/Swagger/AsyncAPI definitions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

With `--inverse`, The openapi `tags` array is converted to an object if first element doesn't contain the tag(s) being filtered on

localstatic opened this issue · comments

When using --inverse in combination with an tags array at the top level of the spec, the structure of the resulting tags property's value gets converted incorrectly to an object instead of an array if the first element in the input array does not have the property being filtered on ("x-public" in the following examples).

Minimal repro spec:

{
  "tags": [
    {
      "name": "Tag 1"
    },
    {
      "x-public": true,
      "name": "Tag 2"
    }
  ]
}

Running openapi-filter --inverse --tags "x-public" -- repro.json on this results in:

{
  "tags": {
    "1": {
      "x-public": true,
      "name": "Tag 2"
    }
  }
}

If the "x-public" property is moved to the first item in the tags array, the resulting output is correct, though:

Input spec:

{
  "tags": [
    {
      "x-public": true,
      "name": "Tag 1"
    },
    {
      "name": "Tag 2"
    }
  ]
}

Command: openapi-filter --inverse --tags "x-public" -- repro.json
Output:

{
  "tags": [
    {
      "x-public": true,
      "name": "Tag 1"
    }
  ]
}

This issue initially had the wrong output for the last example (bad copy/paste). It has since been updated.

Thanks for flagging this up! Should be fixed in openapi-filter@1.5.2