Redocly / Redocly/redocly-cli

Decorator can't act on Tags that are not at root.

Open
#1,028 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3 Type: Enhancement
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

Describe the bug
Our swagger spec has tags as part of the operation, I am trying to write a custom decorator to reformat these, however my code will not trigger on the TagList item if the tags are not at the root level.

To Reproduce
Steps to reproduce the behavior:
This is a sample of the OAS spec

{
  "openapi": "3.0.1",
  "info": {
    "title": "Test",
    "version": "1.0"
  },
  "tags": [
    "TestTag"
  ],
  "paths": {
    "/api/v1/apitokens": {
      "get": {
        "summary": "List the API Tokens used to access this API",
        "tags": [
          "ApiTokensControllerV1"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiTokenReadModelV1ListMethodResult"
                }
              },
            }
          }
        }
      }
    }
  }
}

And this is my custom plugin

module.exports = RewriteTags;

/** @type {import('@redocly/cli').OasDecorator} */
function RewriteTags({tag}) {
  return {
    TagList: {
      leave(t) {
        console.log(t)
      }
    }
  }
};

When this is run it logs out the TestTag at the root but not the ApiTokensControllerV1 tag in the get operation

Expected behavior
Should act on tags at all levels

Logs

OpenAPI definition
See above

Redocly Version(s)
1.0.0-beta.124

Node.js Version(s)
v16.13.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the OasDecorator and TagList traversal used by the custom RewriteTags plugin, then reproduce the example with both root-level and operation-level tags. Done means the decorator observes and can process TagList items at both levels, with a test covering the nested operation tag.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.