-
-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Hi!
First of all: thanks for this awesome project, it's amazing and such a nice change coming from DRF with drf-spectacular. 👍
I started using django-ninja with django-ninja-extra for the first time now and am still finding my way through porting our existing api. Now I'm struggling with the following situation:
From the django rest api, I'm using OpenAPI Generator to generate a typescript-fetch client. The standard templates, which could be modified manually, make use of the apis operationId to generate the function names.
For example this api leads to this client:
@api_controller(tags=["User"], permissions=[])
class UserController(ModelControllerBase):
model_config = ModelConfig(model=User)
create_user = ModelEndpointFactory.create(schema_in=UserSchema, schema_out=UserSchema, operation_id="create_user") # operation_id will be used as-is as function name in the generated client
@route.get(response=list[UserSchema], operation_id="") # the empty operation_id leads to the auto-generated name `coreApiGetUsers` below
def get_users(self):
return User.objects.all().order_by("last_name", "username")export class UserApi extends runtime.BaseAPI {
// these two are fine
async createUser(requestParameters: UserApiCreateUserRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<UserSchema>
async coreApiGetUsers(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<UserSchema>>
// these (and others) contain the random uuid-parts
async userGetItem94779491(requestParameters: UserApiUserGetItem94779491Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<UserSchema>
async userPatchItem421d551c(requestParameters: UserApiUserPatchItem421d551cRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<UserSchema>
// ... and others
}Currently, the situation is a bit tricky due to the random-suffix in the function names userPatchItem421d551c that are generated, if the operation_id is not set explicitly.
They are generated in ModelEndpointFactory._change_name
Can you tell me how to avoid this, without having to specify each endpoint manually like this:
create_user = ModelEndpointFactory.create(schema_in=UserSchema, schema_out=UserSchema, operation_id="create_user")Or would you suggest to do it like this anyway, for example because it's more explicit? It's just very verbose, if we have many standard endpoints without business logic.
Thanks for your time and support!