{"record":{"id":"a8d3d4bc465cda48","repo":"OpenAPITools/openapi-generator","slug":"property-s-in-model-s-cannot-use-s-as-its-publi","errorCode":null,"errorMessage":"property %s in model %s cannot use %s as its public Python name","messagePattern":"property (.+?) in model (.+?) cannot use (.+?) as its public Python name","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java","lineNumber":835,"sourceCode":"                    || legacyMetadataCollision\n                    || nameMappingGeneratedMembers.contains(publicName));\n            boolean storageNameCollision = generatedMembers.contains(property.name)\n                    && (explicitPublicName\n                    || legacyMetadataCollision\n                    || nameMappingGeneratedMembers.contains(property.name));\n            if (publicNameCollision || storageNameCollision) {\n                String generatedMemberName = publicNameCollision\n                        ? publicName\n                        : property.name;\n                throw new IllegalArgumentException(String.format(Locale.ROOT,\n                        \"property %s in model %s uses generated Python member name %s\",\n                        property.baseName, model.name, generatedMemberName));\n            }\n            if (explicitPublicName\n                    && (!publicName.matches(\"[A-Za-z_][A-Za-z0-9_]*\")\n                    || PYTHON_KEYWORDS.contains(publicName)\n                    || publicName.startsWith(\"__\"))) {\n                throw new IllegalArgumentException(String.format(Locale.ROOT,\n                        \"property %s in model %s cannot use %s as its public Python name\",\n                        property.baseName, model.name, publicName));\n            }\n            if (explicitPublicName\n                    && (!property.name.matches(\"[A-Za-z][A-Za-z0-9_]*\")\n                    || PYTHON_KEYWORDS.contains(property.name)\n                    || MODEL_FIELD_NAME_COLLISIONS.contains(property.name)\n                    || MODEL_CLASS_BODY_NAMES.contains(property.name)\n                    || PYDANTIC_PRIVATE_MEMBER_NAMES.contains(property.name))) {\n                throw new IllegalArgumentException(String.format(Locale.ROOT,\n                        \"property %s in model %s has invalid generated Python field name %s\",\n                        property.baseName, model.name, property.name));\n            }\n\n            for (String inputName : List.of(property.baseName, publicName)) {\n                CodegenProperty owner = inputNameOwners.putIfAbsent(inputName, property);\n                if (owner != null\n                        && !owner.baseName.equals(property.baseName)","sourceCodeStart":817,"sourceCodeEnd":853,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java#L817-L853","documentation":"The python generator validates any explicitly mapped public name (--name-mapping) against Python identifier rules: it must match [A-Za-z_][A-Za-z0-9_]*, must not be a Python keyword, and must not start with '__' (dunder names are reserved for the generated class machinery). Violations throw this IllegalArgumentException during model post-processing.","triggerScenarios":"-g python --name-mapping foo=1st_choice (starts with digit), foo=__private (dunder prefix), foo=class / foo=return (keyword), foo=two words (space) or foo=empty-string.","commonSituations":"Mapping wire names to human-friendly labels that contain spaces, hyphens, or leading digits; teams converting camelCase APIs to Python style and picking names like 'from' or 'type' without realizing they are keywords.","solutions":["Choose a target name that starts with a letter or single underscore, contains only [A-Za-z0-9_], and is not a Python keyword","Remove the leading '__' (e.g. use _private or private_)","Rename the property in the spec instead of mapping it to an invalid identifier"],"exampleFix":"# before\nopenapi-generator-cli generate -i api.yaml -g python --name-mapping order_id=1st_order,class_type=class\n# after\nopenapi-generator-cli generate -i api.yaml -g python --name-mapping order_id=first_order,class_type=clazz","handlingStrategy":"validation","validationCode":"# Validate a mapping target as a Python public identifier (Python):\nimport keyword\nPUBLIC_RE = re.compile(r'^[A-Za-z_][A-Za-z0-9_]*$')\ndef valid_public(name: str) -> bool:\n    return bool(PUBLIC_RE.match(name)) and not keyword.iskeyword(name) and not name.startswith('__')\n\nassert all(valid_public(t) for t in mapping_targets)","typeGuard":null,"tryCatchPattern":"try {\n    new DefaultGenerator().opts(input).generate();\n} catch (IllegalArgumentException e) {\n    // message: 'property X in model Y cannot use Z as its public Python name'\n    // change the --name-mapping target to a valid identifier and rerun\n}","preventionTips":["Keep a regex+keyword check for public names in your mapping authoring workflow","Never start public names with '__'; single '_' is allowed but avoid it for public API","Automate mapping generation from a reviewed list rather than hand-editing per property"],"tags":["python","codegen","naming","identifier","openapi-generator"],"backgroundTag":"invalid-identifier-name","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}