Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] fix api file name & api var name #11051

Merged
merged 3 commits into from
Feb 14, 2022

Conversation

JoeCqupt
Copy link
Contributor

@JoeCqupt JoeCqupt commented Dec 6, 2021

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Dec 23, 2021

org.openapitools.codegen.languages.AbstractPythonCodegen#toApiFilename

@Override
    public String toApiFilename(String name) {
        // replace - with _ e.g. created-at => created_at
        name = name.replaceAll("-", "_");

        // e.g. PhoneNumberApi.py => phone_number_api.py
        return underscore(name + "_" + apiNameSuffix);
    }

this method has some problem

  1. when apiNameSuffix is blank , api file name will end with '_'
  2. apiNamePrefix param is not effect

i want modify it to :

 @Override
    public String toApiFilename(String name) {
        // e.g. PhoneNumberApi.py => phone_number_api.py
        return underscore(toApiName(name));
    }

but it is incompatible with some situation,
eg:
old: FakeClassnameTags123Api -> fake_classname_tags_123_api.py
new: FakeClassnameTags123Api -> fake_classname_tags123_api.py

@JoeCqupt
Copy link
Contributor Author

@JoeCqupt
Copy link
Contributor Author

same to toApiFilename, toApiVarName method also need modify

@JoeCqupt JoeCqupt changed the title [Python] fix api filename [Python] fix api file name & api var name Dec 23, 2021
@@ -691,10 +688,7 @@ public String toApiName(String name) {

@Override
public String toApiVarName(String name) {
if (name.length() == 0) {
return "default_api";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when name length is 0 with your update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after update, it will call method: toApiName(name)

    public String toApiName(String name) {
        if (name.length() == 0) {
            return "DefaultApi";
        }
        return camelize(apiNamePrefix + "_" + name + "_" + apiNameSuffix);
    }

this method will get default name where name length is 0

@spacether
Copy link
Contributor

This PR changes the api file names, making it a breaking change.
Existing users of autogenerated apis will have their code break if they are referencing api files whose module names no longer exist.
As is this must wait for the 6.0.0 branch.
A solution to get this merged sooner is to add an additional property command line arg which activates this new path when it is set to true, and defaults to false, keeping the current master branch file names. That would allow you to release in a minor or patch release.
Which do you prefer to do?

@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Dec 31, 2021

This PR changes the api file names, making it a breaking change. Existing users of autogenerated apis will have their code break if they are referencing api files whose module names no longer exist. As is this must wait for the 6.0.0 branch. A solution to get this merged sooner is to add an additional property command line arg which activates this new path when it is set to true, and defaults to false, keeping the current master branch file names. That would allow you to release in a minor or patch release. Which do you prefer to do?

@spacether i can wait for 6.0.0 branch

@wing328 wing328 changed the base branch from master to 6.0.x January 13, 2022 18:07
@wing328
Copy link
Member

wing328 commented Jan 13, 2022

UPDATE: I've changed the target branch to 6.0.x

@wing328 wing328 modified the milestones: 5.4.0, 6.0.0 Jan 13, 2022
@wing328 wing328 changed the base branch from 6.0.x to master February 14, 2022 03:25
@wing328 wing328 merged commit dce8b80 into OpenAPITools:master Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants