Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !13668

Fix issue9444

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/ahsanfz/fix_issue9444 into master Oct 11, 2022
  • Overview 0
  • Commits 6
  • Pipelines 1
  • Changes 1

Created by: ahsanfz

This is for issue #9444

@bbdouglas, @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10)

Need feedback

So I analyzed the problem as following:

org.openapitools.codegen.utils.StringUtils.camelize(final String inputWord, boolean lowercaseFirstLetter)

removes all underscores characters using this matcher:

m = camelizeUnderscorePattern.matcher(word);

If we let camelize do what it does and say that even removing the first underscore is part of its job, then one can do a more local fix in class "AbstractJavaCodegen" just for the java generators.

So toVarName() and getterAndSetterCapitalize() could be changed with something as simple as the line below at start of methods:
boolean beginsWithUnderScore = name.startsWith("_");

And when the methods are ready to return, re-add back the underscore at the beginning. For example the toVarName could change as follows towards the end.

And getterAndSetterCapitalize is just a little bit complicated, but doable as follows:

    public String getterAndSetterCapitalize(String name) {
        boolean lowercaseFirstLetter = false;
        if (name == null || name.length() == 0) {
            return name;
        }
        boolean prependUnderscore = name.length()!=1 && name.startsWith("_");
        name = toVarName(name);
        //
        // Let the property name capitalized
        // except when the first letter of the property name is lowercase and the second letter is uppercase
        // Refer to section 8.8: Capitalization of inferred names of the JavaBeans API specification
        // http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf)
        //
        if (name.length() > 1 && Character.isLowerCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) {
            lowercaseFirstLetter = true;
        }
        name = camelize(name, lowercaseFirstLetter);
        // Note capitalizing "P" initial letter since camelize capitalizes it
        if ( prependUnderscore && !name.equals("PropertyClass")) {
            name = "_" + name;
        }
        return name;
    }

Can some one see a problem for these changes. Any other suggestions ?

We could make this a configurable option as well.

Open Part still

Also the last open part is the moustache templates.

For this schema with props type, _type and subtype:

components:
  schemas:
    Message:
      required:
      - _type
      - text
      type: object
      properties:
        type:
          type: string
          description: Type of this message.
          enum:
          - STATUS
          - TEXT
          - ERROR
          - PROGRESS
        subType:
          type: string
          description: Sub-type of this message.
          enum:
          - STATUS
          - LOCK
          - UNKNOWN
        _type:
          type: string
      discriminator:
        propertyName: _type

I should get this generated in the annotations

@JsonPropertyOrder({
  Message.JSON_PROPERTY_TYPE,
  Message.JSON_PROPERTY_SUB_TYPE,
  Message.JSON_PROPERTY__TYPE
})

but the double "__" in third property above is not generated:

I looked at the moustache templates. No expert here, but maybe the "nameInSnakeCase" is the culprit in pojo.moustasche. I just searched the string "JSON_PROPERTY_" and the following lines poped up:

{{classname}}.JSON_PROPERTY_{{nameInSnakeCase}}{{^-last}},{{/-last}}

Must be other places also as variable is wrong at a couple of places.

Any suggestions

Regards,

PR TEMPLATE Leave alone for now.

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 (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/ahsanfz/fix_issue9444