Skip to content
TORNLIFE More

Hashed operationIds in OpenAPI

Started by AdmiralSnackbar [2112923] on in Bugs & Issues.

5 replies · 88 views · thread synced · 4 days ago · View on torn.com
About this thread

Posts archived: 6 / 6 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
6
Discussion span
→
People posting
4
Likes on archived posts
5
Posts by staff, officers and moderators
3
Authority score
57 / 100
Historical score
36 / 100
Story score
41 / 100
Engagement score
53 / 100

Most-liked replies

AdmiralSnackbar [2112923]

So yeah… tried generating a TypeScript SDK from your openapi.json (https://www.torn.com/swagger/openapi.json) and it’s… insane. All the function names are hashes. I mean literally:

 

```typescript

import { createClient } from "../generated/torn/client/index.js";
import { c82d282102d0d4f54768a6a465639673, 94dfc0c0663c9dc53241abbc59e39597 } from "../generated/torn/sdk.gen.js";

const client = createClient({ auth: process.env.TORN_API_KEY });

const myFaction = await c82d282102d0d4f54768a6a465639673({ client });
const otherFaction = await 94dfc0c0663c9dc53241abbc59e39597({ client, query: { id: 12345 } });

```

I can’t remember these names. I can’t explain them to anyone. They work… technically… but this is unusable in any real code.

If the operationIds were descriptive, like:


```typescript
import { getMyFaction, getUserFaction } from "../generated/torn/sdk.gen.js";

const myFaction = await getMyFaction({ client });
const otherFaction = await getUserFaction({ client, query: { id: 12345 } });

```


…then it would be readable, obvious, and maintainable.

 

Steps to reproduce:

- Use https://www.torn.com/swagger/openapi.json.

- Generate a TypeScript SDK with @hey-api/openapi-ts and operations.strategy = "flat".

- Notice all function names are long hashes.

- Switching to byTags or single doesn’t really help.

Suggested fix:

- Replace hashed operationIds with descriptive ones:


```json
"/user/faction": { "get": { "operationId": "getMyFaction", ... } },
"/user/{id}/faction": { "get": { "operationId": "getUserFaction", ... } }

```

That’s it. No hacks, no wrappers needed, just readable function names.

splent [2088243] Admin Staff

After some additional research, I found out I missed adding unique identifiers to Swagger when I switched the Swagger from 3.0.x to 3.1.x. 

 

It seems if you don't add/specify identifiers, Swagger will generate its own hashed identifiers.
But apparently there should be no need for workarounds such as the one provided by Tiksan, so I apologise to everyone who had to do that due to my ignorance. 


I'll be able to add these tomorrow. 


Thanks!

splent [2088243] Admin Staff

Hey, 


The identifiers are now added and Swagger was updated to the version 5.2.3. You might need to hard-refresh the openapi.json file if you're not seeing these changes in Swagger.

 

Thanks!