openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Enumerate duplicate model names

Open tjb346 opened this issue 10 months ago • 3 comments

This addresses: https://github.com/openapi-generators/openapi-python-client/issues/652

Even with use_path_prefixes_for_title_model_names set to true, duplicate model class names can occur. By default, when duplicates are encountered they will be skipped. This can cause error when they are referenced later.

This PR enables setting enumerate_duplicate_model_names to true (false by default) in the config file which will result in a number being added to duplicate names starting with 1. For instance, if there are multiple occurrences in the schema of MyModelName, the initial occurrence will remain MyModelName and subsequent occurrences will be named MyModelName1, MyModelName2 and so on.

The existing test_model_name_conflict test is updated to account for this new config option.

tjb346 avatar Mar 04 '25 15:03 tjb346

This looks amazing

peter-gerlagh-kyos avatar Jul 12 '25 10:07 peter-gerlagh-kyos

Thanks for authoring this. Confirming that we built this from source and used it to successfully generate a client from our fastapi service which due this recent feature (https://fastapi.tiangolo.com/how-to/separate-openapi-schemas/) really struggles without this deduplication.

jboreiko avatar Jul 15 '25 16:07 jboreiko

Thank you. This also fixes generating code for the HAProxy Dataplane API spec (after converting it with swagger2openapi).

phihos avatar Aug 25 '25 10:08 phihos