OpenAPITools / OpenAPITools/openapi-generator
[BUG][PYTHON] Reserved word escaping breaks python naming conventions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The current method of escaping reserved words in variable names involves appending a leading underscore (_) to the variable name. Per PEP8 and community convention, variable names with a leading underscore are typically used to signify that the variable is internal and thus should not be considered part of the public interface of its containing scope. This is not only confusing due to convention, but also affects python's star (*) imports (from package import *) and commonly used tools (such as IPython) which rely on this convention to determine whether to include attributes for introspection and completion purposes.
openapi-generator version
4.0.0
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: Status Check API
paths:
/check:
get:
summary: Check Pass/Fail Status
operationId: checkStatus
responses:
default:
description: Status
content:
application/json:
schema:
$ref: "#/components/schemas/Status"
components:
schemas:
Status:
required:
- pass
properties:
pass:
type: boolean
Command line used for generation
openapi-generator generate -i openapi.yaml -g python
Steps to reproduce
Give a property a name that collides with a python reserved word, such as pass in your declaration file and then generate a python package.
Suggest a fix
PEP8 recommends instead to append a trailing underscore, such that pass would become pass_.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with PythonClientCodegen.java at the linked reserved-word escaping method and reproduce the issue using the provided OpenAPI declaration and generate command. Check the generated Python package for the pass property; done means reserved names follow the requested naming convention without breaking generated access or imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, python
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100