openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
558 stars 67 forks source link

Provide an alias for operations when operationIds are unavailable #19

Open anttiviljami opened 4 years ago

anttiviljami commented 4 years ago

Sometimes operationIds aren't very helpful, or completely missing.

Let's provide useful aliases for those cases. Some examples:

GET /pets -> getPets GET /pets/{id} -> getPetsById POST /pets -> postPets DELETE /pets/{id} -> deletePetsById

MV10 commented 3 years ago

Previously I linked to this from an issue filed under your React package. Our API is .NET-based and we generate schemas using a very popular product called Swashbuckle. While researching whether Swashbuckle could automate this for us, I discovered that they mention this problem in their readme:

Auto-generating an ID that matches these requirements, while also providing a name that would be meaningful in client libraries is a non-trivial task and so, Swashbuckle omits the operationId by default. However, if neccessary, you can assign operationIds by decorating individual routes OR by providing a custom strategy.

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/README.md#assign-explicit-operationids

Because of the ongoing difficulty of generating meaningful IDs (even by hand) for a large API surface, we're backing away from the React package and returning to URI-based calls.

I thought it might be helpful to point out that even the big-name products don't feel they can automate this.

ken-playerlync commented 1 year ago

I worked around this by creating a script that will format my swagger-api.json to have operationIds... could be something you can add as a utility in your typegen tool