django-ninja-extra icon indicating copy to clipboard operation
django-ninja-extra copied to clipboard

ModelController generated method names mangle OpenApiClient generation

Open peteratdemtec opened this issue 2 years ago • 1 comments

Without django-ninja-extra, using just django-ninja, OpenApiClient generation yields a client with methods such as

api_instance.my_api_create_project

After introducing django-ninja-extra and using it to create a new set of API endpoints via

@api_controller("/projects")
class ProjectController(ModelControllerBase):
    model_config = ModelConfig(
        model=Project,
        schema_config=ModelSchemaConfig(),
        allowed_routes=['create', 'find_one', 'update', 'delete', 'list'],
        create_schema=ProjectIn,
        retrieve_schema=ProjectOut,
        update_schema=ProjectUpdateIn,
    )

OpenApiClient generation warns with

[main] WARN  o.o.c.l.AbstractPythonCodegen - 3ad0a930ControllerCreateItem5ad349 (starting with a number) cannot be used as method name. Renamed to call_3ad0a930_controller_create_item5ad349

and the generated method becomes

api_instance.call_3ad0a930_controller_create_item5ad349

Schemas shown on the OpenApi autogenerated documentation also include strangely named schemas, which may be related:

Screen Shot 2024-02-27 at 9 50 36 PM

Is there something else I should be doing to allow django-ninja-extra to generate better method names?

peteratdemtec avatar Feb 28 '24 02:02 peteratdemtec

@peteratdemtec The method names are generated with uuid to avoid been overridden by extra endpoints that might be defined in the ModelController. Can you please provide more context to the warning you are having so I can know how best to fix it?

eadwinCode avatar Feb 29 '24 19:02 eadwinCode

I believe this resolved with the recent update

eadwinCode avatar Aug 21 '24 14:08 eadwinCode