DEV Community

Cover image for Swagger Codegen and Multiple Tags
Nathan Kallman
Nathan Kallman

Posted on • Originally published at kallmanation.com

Swagger Codegen and Multiple Tags

Today ChatGPT lied to me, so I’m setting the record straight. This is my question: “If an endpoint in an OpenAPI spec has multiple tags, what will Swagger Codegen do?”. Because Swagger Codegen organized the generated code into api/tag_name_api files. So what if there’s multiple tags? Does it take the first tag? The last tag? Or does it generate a file for each tag and give it the same behavior? ChatGPT claimed it takes only the first tag. I’ve already revealed that’s false, so I guess I don’t have any dramatic reveal, so let me just spout the details for you.

Methodology

I used Swagger Codegen V3 Online Generator: https://swagger.io/docs/open-source-tools/swagger-codegen/codegen-v3/online-generators/

I POST ‘ed to https://generator3.swagger.io/api/generate on 2/9/2026 with a payload looking like this:

  "specURL" : "my.code/openapi/v3/swagger.yaml",
  "lang" : "ruby",
  "options" : {
    "gemName": "liar-liar-pants-on-fire",
    "gemRequiredRubyVersion": ">= 3.1.4",
    "gemSummary": "Liar Liar Pants on FIRE", 
    "gemDescription": "",
    "gemAuthor": "Me"
  },
  "type" : "CLIENT",
  "codegenVersion" : "V3"
}
Enter fullscreen mode Exit fullscreen mode

The swagger had tag sections that looked like this (two endpoints, each with one differing tag and one common tag)

get:
  summary: Get thingy
  operationId: getThingy
  tags:
    - Better Grouping
    - Thingies
get:
  summary: Get whatchamacallit
  operationId: getWhatchamacallit
  tags:
    - Better Grouping
    - Whatchamacallits
Enter fullscreen mode Exit fullscreen mode

Results

The generated code had three files api/better_grouping_api.rb, api/thingies_api.rb, and api/whatchamacallits_api.rb.

And wouldn’t you know it, better_grouping_api had the code to call both endpoints and the thingies_api and whatchamacallits_api had the duplicated code for their correspondingly tagged endpoint.

So there you go, if you have OpenAPI spec with multiple tags, it looks like Swagger Codegen v3 will yield the behavior under each of the tag_api files it generates for each tag.

Top comments (0)