'How to get pretty API names with RapidAPI from OpenAPI spec

I'm creating an API using RapidAPI and when I upload an OpenAPI spec, the web UI API names are populated using the OpenAPI spec operationId which is often camelCase. How can I get the name to appear as human friendly while preserving the standard camelCase operationId format?

Here's an example:

This is the official OpenAPI PetStore OAS3 example spec:

https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

Here's an example API:

paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets

This gets loaded as the following where the operationId value listPets appears in the HTML navigation menu as shown below:

Pet Shot

Instead of listPets, I'd like the left hand nav to be human friendly with spaces like other APIs on RapidAPI. Other OpenAPI solutions use the operation summary property which is "List all pets" in the OAI Petstore example and would be ideal, however, RapidAPI doesn't seem to support this, at least by default.

An output example is the RapidAPI Community Open Weather Map API which shows a name like "Current Weather Data".

https://rapidapi.com/community/api/open-weather-map

enter image description here

Is there a way to get a human friendly name in the web UI via OpenAPI spec without converting the operationId format to a non-standard human friendly string? For example, is there another field the RapidAPI can use as a way to tell it to use the summary property?



Solution 1:[1]

I was informed that it's not possible to separately set the API names shown in the RapidAPI UI.

As mentioned, this type of information is typically stored in the OpenAPI Specification's operation summary properties. My workaround solution was to programmatically copy the OpenAPI Spec operation's summary property to the operationId property.

My implementation of this is available as the SpecOperationIdsFromSummaries() function in my Spectrum OpenAPI Spec SDK:

https://github.com/grokify/spectrum/blob/v1.8.0/openapi3edit/operations.go#L190-L203

Solution 2:[2]

Doing this programmatically in the openapi.json may be the best option. If using the FastAPI python library, the following code added to your main.py will take your function summaries as operationIDs:

def use_summaries_as_operation_ids(app: FastAPI) -> None:
    for route in app.routes:
        if isinstance(route, APIRoute):
            route.operation_id = route.summary

use_summaries_as_operation_ids(app)

More on this here: https://fastapi.tiangolo.com/advanced/path-operation-advanced-configuration/#using-the-path-operation-function-name-as-the-operationid

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Svencken