# Duplicate operationId's

**URL:** https://softwaremill.community/t/duplicate-operationids/416
**Category:** tapir
**Created:** [July 6, 2024, 10:24am UTC](https://softwaremill.community/t/duplicate-operationids/416 "2024-07-06T10:24:44Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:24am UTC](https://softwaremill.community/t/duplicate-operationids/416/1 "2024-07-06T10:24:44Z")

</div>

Currently Tapir is rendering specs with duplicate operationId’s. According the OpenAPI specification this should not be allowed, they should be unique. I think spec generation should fail, right?

Reusing endpoint definitions and patching them is not uncommon (at least how I am using them).  
I have a set of endpoints which I want to duplicate with some different paths/options. I can prefix the endpoint-paths easily by mapping a list of endpoints and call `prependIn`.  
However, the operationId I cannot patch, only override. What if endpoint names (operation-ids) can be prefixed/suffixed/tweaked? Is it currently possible? Is there any reason why this cannot be implemented?

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:27am UTC](https://softwaremill.community/t/duplicate-operationids/416/2 "2024-07-06T10:27:33Z")

</div>

Looks like I can tweak the `info` field of and Endpoint. Perhaps it can be a method on the endpoint itself to tweak it?

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:33am UTC](https://softwaremill.community/t/duplicate-operationids/416/3 "2024-07-06T10:33:40Z")

</div>

Something like:

```auto
def prefixName(n: String): ThisType[R] = withInfo(info.copy(name = Some(n + info.name.getOrElse(""))))
def suffixName(n: String): ThisType[R] = withInfo(info.copy(name = info.name.map(_ + n)))

```

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:35am UTC](https://softwaremill.community/t/duplicate-operationids/416/4 "2024-07-06T10:35:50Z")

</div>

I am also missing a way to configure my openapi generator to render all names snake, kebab, camel etc. Is it missing?

---

<div class="post-metadata">

### Author: ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)
#### Post date: [July 6, 2024, 10:36am UTC](https://softwaremill.community/t/duplicate-operationids/416/5 "2024-07-06T10:36:13Z")

</div>

There’s a deduplication step so operation ids should be unique. Can you provide a reproducing example, which demonstrates how this fails?

---

<div class="post-metadata">

### Author: ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)
#### Post date: [July 6, 2024, 10:37am UTC](https://softwaremill.community/t/duplicate-operationids/416/6 "2024-07-06T10:37:03Z")

</div>

As for the names, there’s some options which you might change, I think `schemaName` is what you are looking for: [Generating OpenAPI documentation — tapir 1.x documentation](https://tapir.softwaremill.com/en/latest/docs/openapi.html#options)

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:37am UTC](https://softwaremill.community/t/duplicate-operationids/416/7 "2024-07-06T10:37:09Z")

</div>

Is this duplicationstep explicit? I just rendered some specs where I have named all my endpoints the same.

---

<div class="post-metadata">

### Author: ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)
#### Post date: [July 6, 2024, 10:38am UTC](https://softwaremill.community/t/duplicate-operationids/416/8 "2024-07-06T10:38:07Z")

</div>

No, it’s part of the process: [tapir/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/schema/SchemasForEndpoints.scala at master · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/blob/master/docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/schema/SchemasForEndpoints.scala#L27)

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:40am UTC](https://softwaremill.community/t/duplicate-operationids/416/9 "2024-07-06T10:40:17Z")

</div>

It says SchemaKey, is that also used for operationId’s?

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:42am UTC](https://softwaremill.community/t/duplicate-operationids/416/10 "2024-07-06T10:42:49Z")

</div>

schemaName is not what I am looking for I think. That is how the schemas are named, this is purely about operationId’s. If the spec has duplicate operationId’s then e.g. my Zodios client generators fails to generator all of the endpoints, it silently drops the duplicates.

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 10:50am UTC](https://softwaremill.community/t/duplicate-operationids/416/11 "2024-07-06T10:50:23Z")

</div>

The EndpointVerifier test does also not catch duplicate operationId’s.

Is there a specific test in the repo for these operationId’s? Then I can perhaps fiddle a bit with that to see if I can demonstrate it (and fix it perhaps).

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 6, 2024, 11:02am UTC](https://softwaremill.community/t/duplicate-operationids/416/12 "2024-07-06T11:02:42Z")

</div>

Added a test to the EndpointVerifier to show it is not detecting duplicate names: [test(testing): add test to detect duplicate endpoint names by ThijsBroersen · Pull Request #3908 · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/pull/3908)

---

<div class="post-metadata">

### Author: ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)
#### Post date: [July 7, 2024, 10:25am UTC](https://softwaremill.community/t/duplicate-operationids/416/13 "2024-07-07T10:25:15Z")

</div>

Ah yes, you are right, I misunderstood the original problem.

There’s an `operationIdGenerator` that you can customise in options (see [tapir/docs/openapi-docs/src/main/scala/sttp/tapir/docs/openapi/EndpointToOpenAPIPaths.scala at e2f61dfa8f9019881502ae3a2af4c4cc3d42f9cf · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/blob/e2f61dfa8f9019881502ae3a2af4c4cc3d42f9cf/docs/openapi-docs/src/main/scala/sttp/tapir/docs/openapi/EndpointToOpenAPIPaths.scala#L31)), however if the endpoint’s `name` is explicitly set, it alway overrides the generated operation id.

So here I guess the solution would be “do not use duplicate endpoint names”, as they are then used for operation ids (and I think that’s their only usage). Unless you have a use-case for using the same name multiple times?

And you are right of course that this should be caught by the `EndpointVerifier` - thanks for the test - maybe you could contribute the implementation as well?

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 8, 2024, 5:31pm UTC](https://softwaremill.community/t/duplicate-operationids/416/14 "2024-07-08T17:31:32Z")

</div>

Yes, I can. I will take a look later this week.

---

<div class="post-metadata">

### Author: ![Thijs](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/thijs/32/248_2.png) [@Thijs](https://softwaremill.community/u/Thijs)
#### Post date: [July 18, 2024, 2:29pm UTC](https://softwaremill.community/t/duplicate-operationids/416/15 "2024-07-18T14:29:06Z")

</div>

I have pushed changes…
