Skip to content

Include common lambdas in generators#3368

Merged
jmini merged 4 commits intoOpenAPITools:masterfrom
MichalFoksa:feature/include-common-lambdas-in-generators
Jul 18, 2019
Merged

Include common lambdas in generators#3368
jmini merged 4 commits intoOpenAPITools:masterfrom
MichalFoksa:feature/include-common-lambdas-in-generators

Conversation

@MichalFoksa
Copy link
Contributor

@MichalFoksa MichalFoksa commented Jul 15, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Various generator used same Mustache lambdas over and over. In this PR, DefaultCodegen registers set of following Mustache lambdas:

    .put("lowercase", new LowercaseLambda().generator(this))
    .put("uppercase", new UppercaseLambda())
    .put("titlecase", new TitlecaseLambda())
    .put("camelcase", new CamelCaseLambda().generator(this))
    .put("indented", new IndentedLambda())
    .put("indented_8", new IndentedLambda(8, " "))
    .put("indented_12", new IndentedLambda(12, " "))
    .put("indented_16", new IndentedLambda(16, " "));

Extension is done in such a way that each generator can:

  • extend the list with additional lambdas
    @Override
    protected Builder<String, Lambda> addMustacheLambdas() {
        return super.addMustacheLambdas()
                .put("multiline_comment_4", new IndentedLambda(4, " ", "///"));
    }
  • suppress all common lambdas by returning empty builder from addMustacheLambdas()
    @Override
    protected Builder<String, Lambda> addMustacheLambdas() {
        return new ImmutableMap.Builder<String, Mustache.Lambda>();
    }

NOTE: @jmini : I was not sure where to put new methods in DefaultCodegen. PLS give me an advised or feel free to update it directly.

Reviewers

@MichalFoksa MichalFoksa marked this pull request as ready for review July 15, 2019 16:38
Copy link
Member

@jmini jmini left a comment

Choose a reason for hiding this comment

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

LGTM

@jmini jmini merged commit a85bd0f into OpenAPITools:master Jul 18, 2019
@MichalFoksa MichalFoksa deleted the feature/include-common-lambdas-in-generators branch July 29, 2019 16:24
@wing328 wing328 added this to the 4.1.0 milestone Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments