Skip to content
GitLab
    • Explore Projects Groups Snippets
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
  • !4812

[bug][dart] Allow derived generators to call DefaultCodegen#processOpts

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Jim Schubert requested to merge dart-default-process-opts into master 5 years ago
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 3

DefaultCodegen#procesOpts sets up quite a bit which may be expected by users (template directory overrides, git user/repo, etc). The way the dart-dio and dart-jaguar processOpts methods were written, these things did not work. This makes it work.

cc all dart contributors for awareness:

  • Dart: @yissachar
  • Dart (refactor): @joernahrens
  • Dart 2: @swipesight
  • Dart (Jaguar): @jaumard
  • Dart (Dio): @athornz

To repro the bug, copy the dart README.mustache (for dart-dio or dart-jaguar) to some directory called template, make some changes to the README, for example add to the top:

# Testing https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}.git

Generate with:

openapi-generator generate --generator-name dart-dio -t $(pwd)/template --input-spec openapi.yaml --output client/

We'd expect this README to be generated, but as of current master it is not. This was reported as a question by a member of the community in Slack. I thought it was going to be a quick assist, but turned out to be an issue. There's no associated GitHub issue, although I'd image this might resolve other issues with dart-dio and dart-jaguar because there's an attempted workaround in the extended DartClientCodegen which leads me to believe there was a known confusion with templateDir:

        final Object isSupportDart2 = additionalProperties.get(SUPPORT_DART2);
        if (Boolean.FALSE.equals(isSupportDart2) || (isSupportDart2 instanceof String && !Boolean.parseBoolean((String) isSupportDart2))) {
            // dart 1.x
            LOGGER.info("Dart version: 1.x");
            supportingFiles.add(new SupportingFile("analysis_options.mustache", "", ".analysis_options"));
        } else {
            // dart 2.x
            LOGGER.info("Dart version: 2.x");
            // check to not overwrite a custom templateDir
            if (templateDir == null) {
                embeddedTemplateDir = templateDir = "dart2";
            }
        }

I don't follow why the if final if condition in the above snippet exists. Maybe someone familiar with these generators could add more of a comment (why are we setting dirs here when they should be handled in constructor and super.processOpts?)

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.
Compare
  • master (base)

and
  • latest version
    053a6245
    1 commit, 2 years ago

3 files
+ 9
- 71

    Preferences

    File browser
    Compare changes
modules/…/…/…/…‎/…/…/…/languages‎
DartClientC‎odegen.java‎ +5 -1
DartDioClien‎tCodegen.java‎ +3 -70
DartJaguarClie‎ntCodegen.java‎ +1 -0
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java
+ 5
- 1
  • View file @ 053a6245

  • Edit in single-file editor

  • Open in Web IDE


@@ -173,9 +173,13 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
return "Generates a Dart (1.x (deprecated) or 2.x) client library.";
}
protected void defaultProcessOpts() {
super.processOpts();
}
@Override
public void processOpts() {
super.processOpts();
defaultProcessOpts();
if (StringUtils.isEmpty(System.getenv("DART_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable DART_POST_PROCESS_FILE not defined so the Dart code may not be properly formatted. To define it, try `export DART_POST_PROCESS_FILE=\"/usr/local/bin/dartfmt -w\"` (Linux/Mac)");
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java
+ 3
- 70
  • View file @ 053a6245

  • Edit in single-file editor

  • Open in Web IDE


@@ -70,7 +70,8 @@ public class DartDioClientCodegen extends DartClientCodegen {
super();
browserClient = false;
outputFolder = "generated-code/dart-dio";
embeddedTemplateDir = templateDir = "dart-dio";
embeddedTemplateDir = "dart-dio";
this.setTemplateDir(embeddedTemplateDir);
//no tests at this time
modelTestTemplateFiles.clear();
@@ -159,75 +160,7 @@ public class DartDioClientCodegen extends DartClientCodegen {
@Override
public void processOpts() {
if (additionalProperties.containsKey(CodegenConstants.TEMPLATE_DIR)) {
this.setTemplateDir((String) additionalProperties.get(CodegenConstants.TEMPLATE_DIR));
}
if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
this.setModelPackage((String) additionalProperties.get(CodegenConstants.MODEL_PACKAGE));
}
if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
this.setApiPackage((String) additionalProperties.get(CodegenConstants.API_PACKAGE));
}
if (additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
setHideGenerationTimestamp(convertPropertyToBooleanAndWriteBack(CodegenConstants.HIDE_GENERATION_TIMESTAMP));
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, hideGenerationTimestamp);
}
if (additionalProperties.containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
.get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS)) {
this.setPrependFormOrBodyParameters(Boolean.valueOf(additionalProperties
.get(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.ENSURE_UNIQUE_PARAMS)) {
this.setEnsureUniqueParams(Boolean.valueOf(additionalProperties
.get(CodegenConstants.ENSURE_UNIQUE_PARAMS).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS)) {
this.setAllowUnicodeIdentifiers(Boolean.valueOf(additionalProperties
.get(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.API_NAME_SUFFIX)) {
this.setApiNameSuffix((String) additionalProperties.get(CodegenConstants.API_NAME_SUFFIX));
}
if (additionalProperties.containsKey(CodegenConstants.MODEL_NAME_PREFIX)) {
this.setModelNamePrefix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_PREFIX));
}
if (additionalProperties.containsKey(CodegenConstants.MODEL_NAME_SUFFIX)) {
this.setModelNameSuffix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_SUFFIX));
}
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) {
this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.DOCEXTENSION)) {
this.setDocExtension(String.valueOf(additionalProperties
.get(CodegenConstants.DOCEXTENSION).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.ENABLE_POST_PROCESS_FILE)) {
this.setEnablePostProcessFile(Boolean.valueOf(additionalProperties
.get(CodegenConstants.ENABLE_POST_PROCESS_FILE).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.GENERATE_ALIAS_AS_MODEL)) {
ModelUtils.setGenerateAliasAsModel(Boolean.valueOf(additionalProperties
.get(CodegenConstants.GENERATE_ALIAS_AS_MODEL).toString()));
}
defaultProcessOpts();
if (StringUtils.isEmpty(System.getenv("DART_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable DART_POST_PROCESS_FILE not defined so the Dart code may not be properly formatted. To define it, try `export DART_POST_PROCESS_FILE=\"/usr/local/bin/dartfmt -w\"` (Linux/Mac)");
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java
+ 1
- 0
  • View file @ 053a6245

  • Edit in single-file editor

  • Open in Web IDE


@@ -113,6 +113,7 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
@Override
public void processOpts() {
defaultProcessOpts();
if (additionalProperties.containsKey(NULLABLE_FIELDS)) {
nullableFields = convertPropertyToBooleanAndWriteBack(NULLABLE_FIELDS);
} else {
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!12573
Source branch: dart-default-process-opts

Menu

Explore Projects Groups Snippets