From 24155b31e985f43e6946c7e9ea7915af60b376e1 Mon Sep 17 00:00:00 2001 From: benjaminSchilling33 Date: Fri, 27 Dec 2019 09:45:07 +0100 Subject: [PATCH] Added Dart config parameters to fulfill pubspec requirements for publishing to pub (#3911) * Added three configuration values for Dart 2 to be able to publish the generated code to pub without changes: pubAuthor - contains the name of the author pubAuthorEmail - contains the email address of the author pubHomepage - contain the homepage of the project Changed the name of the output directory from docs to doc as this is the path required by pub * Added three configuration values for Dart 2 to be able to publish the generated code to pub without changes: pubAuthor - contains the name of the author pubAuthorEmail - contains the email address of the author pubHomepage - contain the homepage of the project Changed the name of the output directory from docs to doc as this is the path required by pub --- .../codegen/languages/DartClientCodegen.java | 46 ++++++++++++++++++- .../src/main/resources/dart2/pubspec.mustache | 3 ++ .../codegen/dart/DartClientOptionsTest.java | 6 +++ .../options/DartClientOptionsProvider.java | 6 +++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java index 8930d2d6b53..34d906a9212 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java @@ -74,16 +74,22 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { public static final String PUB_NAME = "pubName"; public static final String PUB_VERSION = "pubVersion"; public static final String PUB_DESCRIPTION = "pubDescription"; + public static final String PUB_AUTHOR = "pubAuthor"; + public static final String PUB_AUTHOR_EMAIL = "pubAuthorEmail"; + public static final String PUB_HOMEPAGE = "pubHomepage"; public static final String USE_ENUM_EXTENSION = "useEnumExtension"; public static final String SUPPORT_DART2 = "supportDart2"; protected boolean browserClient = true; protected String pubName = "openapi"; protected String pubVersion = "1.0.0"; protected String pubDescription = "OpenAPI API client"; + protected String pubAuthor = "Author"; + protected String pubAuthorEmail = "author@homepage"; + protected String pubHomepage = "homepage"; protected boolean useEnumExtension = false; protected String sourceFolder = ""; - protected String apiDocPath = "docs" + File.separator; - protected String modelDocPath = "docs" + File.separator; + protected String apiDocPath = "doc" + File.separator; + protected String modelDocPath = "doc" + File.separator; protected String apiTestPath = "test" + File.separator; protected String modelTestPath = "test" + File.separator; @@ -153,6 +159,9 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { cliOptions.add(new CliOption(PUB_NAME, "Name in generated pubspec")); cliOptions.add(new CliOption(PUB_VERSION, "Version in generated pubspec")); cliOptions.add(new CliOption(PUB_DESCRIPTION, "Description in generated pubspec")); + cliOptions.add(new CliOption(PUB_AUTHOR, "Author name in generated pubspec")); + cliOptions.add(new CliOption(PUB_AUTHOR_EMAIL, "Email address of the author in generated pubspec")); + cliOptions.add(new CliOption(PUB_HOMEPAGE, "Homepage in generated pubspec")); cliOptions.add(new CliOption(USE_ENUM_EXTENSION, "Allow the 'x-enum-values' extension for enums")); cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, "Source folder for generated code")); cliOptions.add(CliOption.newBoolean(SUPPORT_DART2, "Support Dart 2.x (Dart 1.x support has been deprecated)").defaultValue(Boolean.TRUE.toString())); @@ -214,6 +223,27 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { additionalProperties.put(PUB_DESCRIPTION, pubDescription); } + if (additionalProperties.containsKey(PUB_AUTHOR)) { + this.setPubAuthor((String) additionalProperties.get(PUB_AUTHOR)); + } else { + //not set, use to be passed to template + additionalProperties.put(PUB_AUTHOR, pubAuthor); + } + + if (additionalProperties.containsKey(PUB_AUTHOR_EMAIL)) { + this.setPubAuthorEmail((String) additionalProperties.get(PUB_AUTHOR_EMAIL)); + } else { + //not set, use to be passed to template + additionalProperties.put(PUB_AUTHOR_EMAIL, pubAuthorEmail); + } + + if (additionalProperties.containsKey(PUB_HOMEPAGE)) { + this.setPubHomepage((String) additionalProperties.get(PUB_HOMEPAGE)); + } else { + //not set, use to be passed to template + additionalProperties.put(PUB_HOMEPAGE, pubHomepage); + } + if (additionalProperties.containsKey(USE_ENUM_EXTENSION)) { this.setUseEnumExtension(convertPropertyToBooleanAndWriteBack(USE_ENUM_EXTENSION)); } else { @@ -551,6 +581,18 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { this.pubDescription = pubDescription; } + public void setPubAuthor(String pubAuthor) { + this.pubAuthor = pubAuthor; + } + + public void setPubAuthorEmail(String pubAuthorEmail) { + this.pubAuthorEmail = pubAuthorEmail; + } + + public void setPubHomepage(String pubHomepage) { + this.pubHomepage = pubHomepage; + } + public void setUseEnumExtension(boolean useEnumExtension) { this.useEnumExtension = useEnumExtension; } diff --git a/modules/openapi-generator/src/main/resources/dart2/pubspec.mustache b/modules/openapi-generator/src/main/resources/dart2/pubspec.mustache index 59801210034..6f1bd2bb4a0 100644 --- a/modules/openapi-generator/src/main/resources/dart2/pubspec.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/pubspec.mustache @@ -1,6 +1,9 @@ name: {{pubName}} version: {{pubVersion}} description: {{pubDescription}} +authors: + - {{pubAuthor}} <{{pubAuthorEmail}}> +homepage: {{pubHomepage}} environment: sdk: '>=2.0.0 <3.0.0' dependencies: diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientOptionsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientOptionsTest.java index e9e32475553..902a0ebad30 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientOptionsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientOptionsTest.java @@ -52,6 +52,12 @@ public class DartClientOptionsTest extends AbstractOptionsTest { times = 1; clientCodegen.setPubDescription(DartClientOptionsProvider.PUB_DESCRIPTION_VALUE); times = 1; + clientCodegen.setPubAuthor(DartClientOptionsProvider.PUB_AUTHOR_VALUE); + times = 1; + clientCodegen.setPubAuthorEmail(DartClientOptionsProvider.PUB_AUTHOR_EMAIL_VALUE); + times = 1; + clientCodegen.setPubHomepage(DartClientOptionsProvider.PUB_HOMEPAGE_VALUE); + times = 1; clientCodegen.setSourceFolder(DartClientOptionsProvider.SOURCE_FOLDER_VALUE); times = 1; clientCodegen.setUseEnumExtension(Boolean.valueOf(DartClientOptionsProvider.USE_ENUM_EXTENSION)); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartClientOptionsProvider.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartClientOptionsProvider.java index 0ed8360cd61..c79592d1d7f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartClientOptionsProvider.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartClientOptionsProvider.java @@ -31,6 +31,9 @@ public class DartClientOptionsProvider implements OptionsProvider { public static final String PUB_NAME_VALUE = "swagger"; public static final String PUB_VERSION_VALUE = "1.0.0-SNAPSHOT"; public static final String PUB_DESCRIPTION_VALUE = "Swagger API client dart"; + public static final String PUB_AUTHOR_VALUE = "Author"; + public static final String PUB_AUTHOR_EMAIL_VALUE = "author@homepage"; + public static final String PUB_HOMEPAGE_VALUE = "Homepage"; public static final String SOURCE_FOLDER_VALUE = "src"; public static final String USE_ENUM_EXTENSION = "true"; public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false"; @@ -51,6 +54,9 @@ public class DartClientOptionsProvider implements OptionsProvider { .put(DartClientCodegen.PUB_NAME, PUB_NAME_VALUE) .put(DartClientCodegen.PUB_VERSION, PUB_VERSION_VALUE) .put(DartClientCodegen.PUB_DESCRIPTION, PUB_DESCRIPTION_VALUE) + .put(DartClientCodegen.PUB_AUTHOR, PUB_AUTHOR_VALUE) + .put(DartClientCodegen.PUB_AUTHOR_EMAIL, PUB_AUTHOR_EMAIL_VALUE) + .put(DartClientCodegen.PUB_HOMEPAGE, PUB_HOMEPAGE_VALUE) .put(CodegenConstants.SOURCE_FOLDER, SOURCE_FOLDER_VALUE) .put(DartClientCodegen.USE_ENUM_EXTENSION, USE_ENUM_EXTENSION) .put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)