From a60df64cfb9aeed3783392c374ec7f6068a7fdec Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Sat, 16 Apr 2022 10:41:13 +0200 Subject: [PATCH] [dart] Support/Fix sourceFolder parameter and docs (#12113) * [dart] Support/Fix sourceFolder parameter and docs * allow passing the sourceFolder to generators * not sure how this translates to the dart2 generator due to the `part` files * fix doc generation not showing default value of CLI options * [dart] Delete old generator doc files --- docs/generators/dart-dio-next.md | 18 +- docs/generators/dart-dio.md | 244 ------------------ docs/generators/dart-jaguar.md | 244 ------------------ docs/generators/dart.md | 18 +- .../languages/AbstractDartCodegen.java | 48 ++-- .../codegen/languages/DartClientCodegen.java | 15 +- .../languages/DartDioNextClientCodegen.java | 16 +- .../dart/libraries/dio/api_client.mustache | 12 +- .../libraries/dio/auth/api_key_auth.mustache | 2 +- .../libraries/dio/auth/basic_auth.mustache | 2 +- .../libraries/dio/auth/bearer_auth.mustache | 2 +- .../dart/libraries/dio/auth/oauth.mustache | 2 +- .../resources/dart/libraries/dio/lib.mustache | 16 +- .../built_value/date_serializer.mustache | 2 +- .../built_value/serializers.mustache | 8 +- 15 files changed, 83 insertions(+), 566 deletions(-) delete mode 100644 docs/generators/dart-dio.md delete mode 100644 docs/generators/dart-jaguar.md diff --git a/docs/generators/dart-dio-next.md b/docs/generators/dart-dio-next.md index d247192fd97..5603f5da3ab 100644 --- a/docs/generators/dart-dio-next.md +++ b/docs/generators/dart-dio-next.md @@ -25,18 +25,18 @@ These options may be applied as additional-properties (cli) or configOptions (pl |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| |prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| -|pubAuthor|Author name in generated pubspec| |null| -|pubAuthorEmail|Email address of the author in generated pubspec| |null| -|pubDescription|Description in generated pubspec| |null| -|pubHomepage|Homepage in generated pubspec| |null| -|pubLibrary|Library name in generated code| |null| -|pubName|Name in generated pubspec| |null| -|pubVersion|Version in generated pubspec| |null| +|pubAuthor|Author name in generated pubspec| |Author| +|pubAuthorEmail|Email address of the author in generated pubspec| |author@homepage| +|pubDescription|Description in generated pubspec| |OpenAPI API client| +|pubHomepage|Homepage in generated pubspec| |homepage| +|pubLibrary|Library name in generated code| |openapi.api| +|pubName|Name in generated pubspec| |openapi| +|pubVersion|Version in generated pubspec| |1.0.0| |serializationLibrary|Specify serialization library|
**built_value**
[DEFAULT] built_value
|built_value| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| -|sourceFolder|Source folder for generated code| |null| -|useEnumExtension|Allow the 'x-enum-values' extension for enums| |null| +|sourceFolder|source folder for generated code| |src| +|useEnumExtension|Allow the 'x-enum-values' extension for enums| |false| ## IMPORT MAPPING diff --git a/docs/generators/dart-dio.md b/docs/generators/dart-dio.md deleted file mode 100644 index b94bed6bcc7..00000000000 --- a/docs/generators/dart-dio.md +++ /dev/null @@ -1,244 +0,0 @@ ---- -title: Documentation for the dart-dio Generator ---- - -## METADATA - -| Property | Value | Notes | -| -------- | ----- | ----- | -| generator name | dart-dio | pass this to the generate command after -g | -| generator stability | STABLE | | -| generator type | CLIENT | | -| generator language | Dart | | -| generator default templating engine | mustache | | -| helpTxt | Generates a Dart Dio client library. | | - -## CONFIG OPTIONS -These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details. - -| Option | Description | Values | Default | -| ------ | ----------- | ------ | ------- | -|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| -|dateLibrary|Option. Date library to use|
**core**
Dart core library (DateTime)
**timemachine**
Time Machine is date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.
|core| -|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| -|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| -|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| -|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| -|nullableFields|Make all fields nullable in the JSON payload| |null| -|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| -|pubAuthor|Author name in generated pubspec| |null| -|pubAuthorEmail|Email address of the author in generated pubspec| |null| -|pubDescription|Description in generated pubspec| |null| -|pubHomepage|Homepage in generated pubspec| |null| -|pubLibrary|Library name in generated code| |null| -|pubName|Name in generated pubspec| |null| -|pubVersion|Version in generated pubspec| |null| -|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| -|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| -|sourceFolder|Source folder for generated code| |null| -|useEnumExtension|Allow the 'x-enum-values' extension for enums| |null| - -## IMPORT MAPPING - -| Type/Alias | Imports | -| ---------- | ------- | - - -## INSTANTIATION TYPES - -| Type/Alias | Instantiated By | -| ---------- | --------------- | - - -## LANGUAGE PRIMITIVES - - - -## RESERVED WORDS - - - -## FEATURE SET - - -### Client Modification Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|BasePath|✓|ToolingExtension -|Authorizations|✓|ToolingExtension -|UserAgent|✓|ToolingExtension -|MockServer|✗|ToolingExtension - -### Data Type Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Custom|✗|OAS2,OAS3 -|Int32|✓|OAS2,OAS3 -|Int64|✓|OAS2,OAS3 -|Float|✓|OAS2,OAS3 -|Double|✓|OAS2,OAS3 -|Decimal|✓|ToolingExtension -|String|✓|OAS2,OAS3 -|Byte|✓|OAS2,OAS3 -|Binary|✓|OAS2,OAS3 -|Boolean|✓|OAS2,OAS3 -|Date|✓|OAS2,OAS3 -|DateTime|✓|OAS2,OAS3 -|Password|✓|OAS2,OAS3 -|File|✓|OAS2 -|Array|✓|OAS2,OAS3 -|Maps|✓|ToolingExtension -|CollectionFormat|✓|OAS2 -|CollectionFormatMulti|✓|OAS2 -|Enum|✓|OAS2,OAS3 -|ArrayOfEnum|✓|ToolingExtension -|ArrayOfModel|✓|ToolingExtension -|ArrayOfCollectionOfPrimitives|✓|ToolingExtension -|ArrayOfCollectionOfModel|✓|ToolingExtension -|ArrayOfCollectionOfEnum|✓|ToolingExtension -|MapOfEnum|✓|ToolingExtension -|MapOfModel|✓|ToolingExtension -|MapOfCollectionOfPrimitives|✓|ToolingExtension -|MapOfCollectionOfModel|✓|ToolingExtension -|MapOfCollectionOfEnum|✓|ToolingExtension - -### Documentation Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Readme|✓|ToolingExtension -|Model|✓|ToolingExtension -|Api|✓|ToolingExtension - -### Global Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Host|✓|OAS2,OAS3 -|BasePath|✓|OAS2,OAS3 -|Info|✓|OAS2,OAS3 -|Schemes|✗|OAS2,OAS3 -|PartialSchemes|✓|OAS2,OAS3 -|Consumes|✓|OAS2 -|Produces|✓|OAS2 -|ExternalDocumentation|✓|OAS2,OAS3 -|Examples|✓|OAS2,OAS3 -|XMLStructureDefinitions|✗|OAS2,OAS3 -|MultiServer|✗|OAS3 -|ParameterizedServer|✗|OAS3 -|ParameterStyling|✗|OAS3 -|Callbacks|✗|OAS3 -|LinkObjects|✗|OAS3 - -### Parameter Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Path|✓|OAS2,OAS3 -|Query|✓|OAS2,OAS3 -|Header|✓|OAS2,OAS3 -|Body|✓|OAS2 -|FormUnencoded|✓|OAS2 -|FormMultipart|✓|OAS2 -|Cookie|✓|OAS3 - -### Schema Support Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Simple|✓|OAS2,OAS3 -|Composite|✗|OAS2,OAS3 -|Polymorphism|✗|OAS2,OAS3 -|Union|✗|OAS3 - -### Security Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|BasicAuth|✓|OAS2,OAS3 -|ApiKey|✓|OAS2,OAS3 -|OpenIDConnect|✗|OAS3 -|BearerToken|✓|OAS3 -|OAuth2_Implicit|✓|OAS2,OAS3 -|OAuth2_Password|✗|OAS2,OAS3 -|OAuth2_ClientCredentials|✗|OAS2,OAS3 -|OAuth2_AuthorizationCode|✗|OAS2,OAS3 - -### Wire Format Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|JSON|✓|OAS2,OAS3 -|XML|✗|OAS2,OAS3 -|PROTOBUF|✗|ToolingExtension -|Custom|✗|OAS2,OAS3 diff --git a/docs/generators/dart-jaguar.md b/docs/generators/dart-jaguar.md deleted file mode 100644 index 0f6aed48cbe..00000000000 --- a/docs/generators/dart-jaguar.md +++ /dev/null @@ -1,244 +0,0 @@ ---- -title: Documentation for the dart-jaguar Generator ---- - -## METADATA - -| Property | Value | Notes | -| -------- | ----- | ----- | -| generator name | dart-jaguar | pass this to the generate command after -g | -| generator stability | DEPRECATED | | -| generator type | CLIENT | | -| generator language | Dart | | -| generator default templating engine | mustache | | -| helpTxt | Generates a Dart Jaguar client library. | | - -## CONFIG OPTIONS -These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details. - -| Option | Description | Values | Default | -| ------ | ----------- | ------ | ------- | -|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| -|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| -|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| -|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| -|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| -|nullableFields|Is the null fields should be in the JSON payload| |null| -|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| -|pubAuthor|Author name in generated pubspec| |null| -|pubAuthorEmail|Email address of the author in generated pubspec| |null| -|pubDescription|Description in generated pubspec| |null| -|pubHomepage|Homepage in generated pubspec| |null| -|pubLibrary|Library name in generated code| |null| -|pubName|Name in generated pubspec| |null| -|pubVersion|Version in generated pubspec| |null| -|serialization|Choose serialization format JSON or PROTO is supported| |null| -|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| -|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| -|sourceFolder|Source folder for generated code| |null| -|useEnumExtension|Allow the 'x-enum-values' extension for enums| |null| - -## IMPORT MAPPING - -| Type/Alias | Imports | -| ---------- | ------- | - - -## INSTANTIATION TYPES - -| Type/Alias | Instantiated By | -| ---------- | --------------- | - - -## LANGUAGE PRIMITIVES - - - -## RESERVED WORDS - - - -## FEATURE SET - - -### Client Modification Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|BasePath|✓|ToolingExtension -|Authorizations|✗|ToolingExtension -|UserAgent|✗|ToolingExtension -|MockServer|✗|ToolingExtension - -### Data Type Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Custom|✗|OAS2,OAS3 -|Int32|✓|OAS2,OAS3 -|Int64|✓|OAS2,OAS3 -|Float|✓|OAS2,OAS3 -|Double|✓|OAS2,OAS3 -|Decimal|✓|ToolingExtension -|String|✓|OAS2,OAS3 -|Byte|✓|OAS2,OAS3 -|Binary|✓|OAS2,OAS3 -|Boolean|✓|OAS2,OAS3 -|Date|✓|OAS2,OAS3 -|DateTime|✓|OAS2,OAS3 -|Password|✓|OAS2,OAS3 -|File|✓|OAS2 -|Array|✓|OAS2,OAS3 -|Maps|✓|ToolingExtension -|CollectionFormat|✓|OAS2 -|CollectionFormatMulti|✓|OAS2 -|Enum|✓|OAS2,OAS3 -|ArrayOfEnum|✓|ToolingExtension -|ArrayOfModel|✓|ToolingExtension -|ArrayOfCollectionOfPrimitives|✓|ToolingExtension -|ArrayOfCollectionOfModel|✓|ToolingExtension -|ArrayOfCollectionOfEnum|✓|ToolingExtension -|MapOfEnum|✓|ToolingExtension -|MapOfModel|✓|ToolingExtension -|MapOfCollectionOfPrimitives|✓|ToolingExtension -|MapOfCollectionOfModel|✓|ToolingExtension -|MapOfCollectionOfEnum|✓|ToolingExtension - -### Documentation Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Readme|✓|ToolingExtension -|Model|✓|ToolingExtension -|Api|✓|ToolingExtension - -### Global Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Host|✓|OAS2,OAS3 -|BasePath|✓|OAS2,OAS3 -|Info|✓|OAS2,OAS3 -|Schemes|✗|OAS2,OAS3 -|PartialSchemes|✓|OAS2,OAS3 -|Consumes|✓|OAS2 -|Produces|✓|OAS2 -|ExternalDocumentation|✓|OAS2,OAS3 -|Examples|✓|OAS2,OAS3 -|XMLStructureDefinitions|✗|OAS2,OAS3 -|MultiServer|✗|OAS3 -|ParameterizedServer|✗|OAS3 -|ParameterStyling|✗|OAS3 -|Callbacks|✗|OAS3 -|LinkObjects|✗|OAS3 - -### Parameter Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Path|✓|OAS2,OAS3 -|Query|✓|OAS2,OAS3 -|Header|✓|OAS2,OAS3 -|Body|✓|OAS2 -|FormUnencoded|✓|OAS2 -|FormMultipart|✓|OAS2 -|Cookie|✓|OAS3 - -### Schema Support Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|Simple|✓|OAS2,OAS3 -|Composite|✗|OAS2,OAS3 -|Polymorphism|✗|OAS2,OAS3 -|Union|✗|OAS3 - -### Security Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|BasicAuth|✓|OAS2,OAS3 -|ApiKey|✓|OAS2,OAS3 -|OpenIDConnect|✗|OAS3 -|BearerToken|✗|OAS3 -|OAuth2_Implicit|✓|OAS2,OAS3 -|OAuth2_Password|✗|OAS2,OAS3 -|OAuth2_ClientCredentials|✗|OAS2,OAS3 -|OAuth2_AuthorizationCode|✗|OAS2,OAS3 - -### Wire Format Feature -| Name | Supported | Defined By | -| ---- | --------- | ---------- | -|JSON|✓|OAS2,OAS3 -|XML|✗|OAS2,OAS3 -|PROTOBUF|✓|ToolingExtension -|Custom|✗|OAS2,OAS3 diff --git a/docs/generators/dart.md b/docs/generators/dart.md index 5c8c4ffac8b..f570ec18708 100644 --- a/docs/generators/dart.md +++ b/docs/generators/dart.md @@ -24,18 +24,18 @@ These options may be applied as additional-properties (cli) or configOptions (pl |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| |prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| -|pubAuthor|Author name in generated pubspec| |null| -|pubAuthorEmail|Email address of the author in generated pubspec| |null| -|pubDescription|Description in generated pubspec| |null| -|pubHomepage|Homepage in generated pubspec| |null| -|pubLibrary|Library name in generated code| |null| -|pubName|Name in generated pubspec| |null| -|pubVersion|Version in generated pubspec| |null| +|pubAuthor|Author name in generated pubspec| |Author| +|pubAuthorEmail|Email address of the author in generated pubspec| |author@homepage| +|pubDescription|Description in generated pubspec| |OpenAPI API client| +|pubHomepage|Homepage in generated pubspec| |homepage| +|pubLibrary|Library name in generated code| |openapi.api| +|pubName|Name in generated pubspec| |openapi| +|pubVersion|Version in generated pubspec| |1.0.0| |serializationLibrary|Specify serialization library|
**native_serialization**
Use native serializer, backwards compatible
|native_serialization| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| -|sourceFolder|Source folder for generated code| |null| -|useEnumExtension|Allow the 'x-enum-values' extension for enums| |null| +|sourceFolder|source folder for generated code| |src| +|useEnumExtension|Allow the 'x-enum-values' extension for enums| |false| ## IMPORT MAPPING diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java index 8d121c79c73..2efb3790d76 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java @@ -54,7 +54,8 @@ public abstract class AbstractDartCodegen extends DefaultCodegen { protected String pubAuthorEmail = "author@homepage"; protected String pubHomepage = "homepage"; protected boolean useEnumExtension = false; - protected String sourceFolder = ""; + protected String sourceFolder = "src"; + protected String libPath = "lib" + File.separator; protected String apiDocPath = "doc" + File.separator; protected String modelDocPath = "doc" + File.separator; protected String apiTestPath = "test" + File.separator; @@ -99,8 +100,8 @@ public abstract class AbstractDartCodegen extends DefaultCodegen { modelTemplateFiles.put("model.mustache", ".dart"); apiTemplateFiles.put("api.mustache", ".dart"); embeddedTemplateDir = templateDir = "dart2"; - apiPackage = "lib.api"; - modelPackage = "lib.model"; + apiPackage = "api"; + modelPackage = "model"; modelDocTemplateFiles.put("object_doc.mustache", ".md"); apiDocTemplateFiles.put("api_doc.mustache", ".md"); @@ -182,15 +183,15 @@ public abstract class AbstractDartCodegen extends DefaultCodegen { imports.put("Object", "dart:core"); imports.put("MultipartFile", "package:http/http.dart"); - cliOptions.add(new CliOption(PUB_LIBRARY, "Library name in generated code")); - 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")); + addOption(PUB_LIBRARY, "Library name in generated code", pubLibrary); + addOption(PUB_NAME, "Name in generated pubspec", pubName); + addOption(PUB_VERSION, "Version in generated pubspec", pubVersion); + addOption(PUB_DESCRIPTION, "Description in generated pubspec", pubDescription); + addOption(PUB_AUTHOR, "Author name in generated pubspec", pubAuthor); + addOption(PUB_AUTHOR_EMAIL, "Email address of the author in generated pubspec", pubAuthorEmail); + addOption(PUB_HOMEPAGE, "Homepage in generated pubspec", pubHomepage); + addOption(USE_ENUM_EXTENSION, "Allow the 'x-enum-values' extension for enums", String.valueOf(useEnumExtension)); + addOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC, sourceFolder); } @Override @@ -212,6 +213,13 @@ public abstract class AbstractDartCodegen extends DefaultCodegen { public void processOpts() { super.processOpts(); + // Fix a couple Java notation properties + modelPackage = modelPackage.replace('.', '/'); + apiPackage = apiPackage.replace('.', '/'); + // And overwrite them in the additional properties + additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage); + additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage); + 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)"); LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI)."); @@ -274,8 +282,10 @@ public abstract class AbstractDartCodegen extends DefaultCodegen { } if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) { - this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER)); + String srcFolder = (String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER); + this.setSourceFolder(srcFolder.replace('/', File.separatorChar)); } + additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder); // make api and model doc path available in mustache template additionalProperties.put("apiDocPath", apiDocPath); @@ -307,32 +317,32 @@ public abstract class AbstractDartCodegen extends DefaultCodegen { @Override public String apiFileFolder() { - return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar); + return (outputFolder + File.separator + libPath + sourceFolder + File.separator + apiPackage()).replace('/', File.separatorChar); } @Override public String modelFileFolder() { - return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar); + return (outputFolder + File.separator + libPath + sourceFolder + File.separator + modelPackage()).replace('/', File.separatorChar); } @Override public String apiTestFileFolder() { - return outputFolder + File.separator + apiTestPath.replace('/', File.separatorChar); + return outputFolder + File.separator + apiTestPath; } @Override public String modelTestFileFolder() { - return outputFolder + File.separator + modelTestPath.replace('/', File.separatorChar); + return outputFolder + File.separator + modelTestPath; } @Override public String apiDocFileFolder() { - return outputFolder + File.separator + apiDocPath.replace('/', File.separatorChar); + return outputFolder + File.separator + apiDocPath; } @Override public String modelDocFileFolder() { - return outputFolder + File.separator + modelDocPath.replace('/', File.separatorChar); + return outputFolder + File.separator + modelDocPath; } @Override 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 5693d19265c..40edd69ed37 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 @@ -17,14 +17,12 @@ package org.openapitools.codegen.languages; -import com.google.common.collect.Sets; import org.openapitools.codegen.CliOption; import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.SupportingFile; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.util.HashMap; import java.util.Map; @@ -45,6 +43,8 @@ public class DartClientCodegen extends AbstractDartCodegen { serializationOptions.put(SERIALIZATION_LIBRARY_NATIVE, "Use native serializer, backwards compatible"); serializationLibrary.setEnum(serializationOptions); cliOptions.add(serializationLibrary); + + sourceFolder = ""; } @Override @@ -61,15 +61,14 @@ public class DartClientCodegen extends AbstractDartCodegen { this.setSerializationLibrary(); - final String libFolder = sourceFolder + File.separator + "lib"; supportingFiles.add(new SupportingFile("pubspec.mustache", "", "pubspec.yaml")); supportingFiles.add(new SupportingFile("analysis_options.mustache", "", "analysis_options.yaml")); - supportingFiles.add(new SupportingFile("api_client.mustache", libFolder, "api_client.dart")); - supportingFiles.add(new SupportingFile("api_exception.mustache", libFolder, "api_exception.dart")); - supportingFiles.add(new SupportingFile("api_helper.mustache", libFolder, "api_helper.dart")); - supportingFiles.add(new SupportingFile("apilib.mustache", libFolder, "api.dart")); + supportingFiles.add(new SupportingFile("api_client.mustache", libPath, "api_client.dart")); + supportingFiles.add(new SupportingFile("api_exception.mustache", libPath, "api_exception.dart")); + supportingFiles.add(new SupportingFile("api_helper.mustache", libPath, "api_helper.dart")); + supportingFiles.add(new SupportingFile("apilib.mustache", libPath, "api.dart")); - final String authFolder = sourceFolder + File.separator + "lib" + File.separator + "auth"; + final String authFolder = libPath + "auth"; supportingFiles.add(new SupportingFile("auth/authentication.mustache", authFolder, "authentication.dart")); supportingFiles.add(new SupportingFile("auth/http_basic_auth.mustache", authFolder, "http_basic_auth.dart")); supportingFiles.add(new SupportingFile("auth/http_bearer_auth.mustache", authFolder, "http_bearer_auth.dart")); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioNextClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioNextClientCodegen.java index bafbfb21188..b6eea21d1a8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioNextClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioNextClientCodegen.java @@ -84,9 +84,6 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen { embeddedTemplateDir = "dart/libraries/dio"; this.setTemplateDir(embeddedTemplateDir); - apiPackage = "lib.src.api"; - modelPackage = "lib.src.model"; - supportedLibraries.put(SERIALIZATION_LIBRARY_BUILT_VALUE, "[DEFAULT] built_value"); final CliOption serializationLibrary = CliOption.newString(CodegenConstants.SERIALIZATION_LIBRARY, "Specify serialization library"); serializationLibrary.setEnum(supportedLibraries); @@ -162,10 +159,9 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen { supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - final String libFolder = sourceFolder + File.separator + "lib"; - supportingFiles.add(new SupportingFile("lib.mustache", libFolder, pubName + ".dart")); + supportingFiles.add(new SupportingFile("lib.mustache", libPath, pubName + ".dart")); - final String srcFolder = libFolder + File.separator + "src"; + final String srcFolder = libPath + sourceFolder; supportingFiles.add(new SupportingFile("api_client.mustache", srcFolder, "api.dart")); final String authFolder = srcFolder + File.separator + "auth"; @@ -253,8 +249,8 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen { if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) { typeMapping.put("date", "Date"); typeMapping.put("Date", "Date"); - importMapping.put("Date", "package:" + pubName + "/src/model/date.dart"); - supportingFiles.add(new SupportingFile("serialization/built_value/date.mustache", srcFolder + File.separator + "model", "date.dart")); + importMapping.put("Date", "package:" + pubName + "/" + sourceFolder + "/" + modelPackage() + "/date.dart"); + supportingFiles.add(new SupportingFile("serialization/built_value/date.mustache", srcFolder + File.separator + modelPackage(), "date.dart")); supportingFiles.add(new SupportingFile("serialization/built_value/date_serializer.mustache", srcFolder, "date_serializer.dart")); } break; @@ -382,7 +378,7 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen { resultImports.addAll(rewriteImports(op.imports, false)); if (op.getHasFormParams() || op.getHasQueryParams()) { - resultImports.add("package:" + pubName + "/src/api_util.dart"); + resultImports.add("package:" + pubName + "/" + sourceFolder + "/api_util.dart"); } // Generate serializer factories for response types. @@ -437,7 +433,7 @@ public class DartDioNextClientCodegen extends AbstractDartCodegen { } else if (importMapping().containsKey(modelImport)) { resultImports.add(importMapping().get(modelImport)); } else { - resultImports.add("package:" + pubName + "/src/model/" + underscore(modelImport) + ".dart"); + resultImports.add("package:" + pubName + "/" + sourceFolder + "/" + modelPackage() + "/" + underscore(modelImport) + ".dart"); } } return resultImports; diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/api_client.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/api_client.mustache index 35fabd973d1..0903a48759e 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/api_client.mustache @@ -1,12 +1,12 @@ {{>header}} import 'package:dio/dio.dart';{{#useBuiltValue}} import 'package:built_value/serializer.dart'; -import 'package:{{pubName}}/src/serializers.dart';{{/useBuiltValue}} -import 'package:{{pubName}}/src/auth/api_key_auth.dart'; -import 'package:{{pubName}}/src/auth/basic_auth.dart'; -import 'package:{{pubName}}/src/auth/bearer_auth.dart'; -import 'package:{{pubName}}/src/auth/oauth.dart'; -{{#apiInfo}}{{#apis}}import 'package:{{pubName}}/src/api/{{classFilename}}.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/serializers.dart';{{/useBuiltValue}} +import 'package:{{pubName}}/{{sourceFolder}}/auth/api_key_auth.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/auth/basic_auth.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/auth/bearer_auth.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/auth/oauth.dart'; +{{#apiInfo}}{{#apis}}import 'package:{{pubName}}/{{sourceFolder}}/{{apiPackage}}/{{classFilename}}.dart'; {{/apis}}{{/apiInfo}} class {{clientName}} { static const String basePath = r'{{{basePath}}}'; diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/api_key_auth.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/api_key_auth.mustache index 2174d159630..5d9da99bd5d 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/api_key_auth.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/api_key_auth.mustache @@ -1,7 +1,7 @@ {{>header}} import 'package:dio/dio.dart'; -import 'package:{{pubName}}/src/auth/auth.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/auth/auth.dart'; class ApiKeyAuthInterceptor extends AuthInterceptor { final Map apiKeys = {}; diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/basic_auth.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/basic_auth.mustache index c286274c3a2..c2a4426937d 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/basic_auth.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/basic_auth.mustache @@ -2,7 +2,7 @@ import 'dart:convert'; import 'package:dio/dio.dart'; -import 'package:{{pubName}}/src/auth/auth.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/auth/auth.dart'; class BasicAuthInfo { final String username; diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/bearer_auth.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/bearer_auth.mustache index 626c7d238d0..b4bce45ca61 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/bearer_auth.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/bearer_auth.mustache @@ -1,6 +1,6 @@ {{>header}} import 'package:dio/dio.dart'; -import 'package:{{pubName}}/src/auth/auth.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/auth/auth.dart'; class BearerAuthInterceptor extends AuthInterceptor { final Map tokens = {}; diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/oauth.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/oauth.mustache index 4f7b79655af..e5af801f39b 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/oauth.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/auth/oauth.mustache @@ -1,6 +1,6 @@ {{>header}} import 'package:dio/dio.dart'; -import 'package:{{pubName}}/src/auth/auth.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/auth/auth.dart'; class OAuthInterceptor extends AuthInterceptor { final Map tokens = {}; diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/lib.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/lib.mustache index 32f6a54b1a6..1ac71181061 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/lib.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/lib.mustache @@ -1,12 +1,12 @@ {{>header}} -export 'package:{{pubName}}/src/api.dart'; -export 'package:{{pubName}}/src/auth/api_key_auth.dart'; -export 'package:{{pubName}}/src/auth/basic_auth.dart'; -export 'package:{{pubName}}/src/auth/oauth.dart'; -{{#useBuiltValue}}export 'package:{{pubName}}/src/serializers.dart'; -{{#useDateLibCore}}export 'package:{{pubName}}/src/model/date.dart';{{/useDateLibCore}}{{/useBuiltValue}} +export 'package:{{pubName}}/{{sourceFolder}}/api.dart'; +export 'package:{{pubName}}/{{sourceFolder}}/auth/api_key_auth.dart'; +export 'package:{{pubName}}/{{sourceFolder}}/auth/basic_auth.dart'; +export 'package:{{pubName}}/{{sourceFolder}}/auth/oauth.dart'; +{{#useBuiltValue}}export 'package:{{pubName}}/{{sourceFolder}}/serializers.dart'; +{{#useDateLibCore}}export 'package:{{pubName}}/{{sourceFolder}}/{{modelPackage}}/date.dart';{{/useDateLibCore}}{{/useBuiltValue}} -{{#apiInfo}}{{#apis}}export 'package:{{pubName}}/src/api/{{classFilename}}.dart'; +{{#apiInfo}}{{#apis}}export 'package:{{pubName}}/{{sourceFolder}}/{{apiPackage}}/{{classFilename}}.dart'; {{/apis}}{{/apiInfo}} -{{#models}}{{#model}}export 'package:{{pubName}}/src/model/{{classFilename}}.dart'; +{{#models}}{{#model}}export 'package:{{pubName}}/{{sourceFolder}}/{{modelPackage}}/{{classFilename}}.dart'; {{/model}}{{/models}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/date_serializer.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/date_serializer.mustache index b5f0ed32c22..dc16805ce62 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/date_serializer.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/date_serializer.mustache @@ -1,7 +1,7 @@ {{>header}} import 'package:built_collection/built_collection.dart'; import 'package:built_value/serializer.dart'; -import 'package:{{pubName}}/src/model/date.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/{{modelPackage}}/date.dart'; class DateSerializer implements PrimitiveSerializer { diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache index c558f153c89..7ef191808eb 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache @@ -6,11 +6,11 @@ import 'package:built_value/json_object.dart'; import 'package:built_value/serializer.dart'; import 'package:built_value/standard_json_plugin.dart'; {{#useDateLibCore}}import 'package:built_value/iso_8601_date_time_serializer.dart'; -import 'package:{{pubName}}/src/date_serializer.dart'; -import 'package:{{pubName}}/src/model/date.dart';{{/useDateLibCore}} +import 'package:{{pubName}}/{{sourceFolder}}/date_serializer.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/{{modelPackage}}/date.dart';{{/useDateLibCore}} {{#useDateLibTimeMachine}}import 'package:time_machine/time_machine.dart'; -import 'package:{{pubName}}/src/offset_date_serializer.dart';{{/useDateLibTimeMachine}} -{{#models}}{{#model}}import 'package:{{pubName}}/src/model/{{classFilename}}.dart'; +import 'package:{{pubName}}/{{sourceFolder}}/offset_date_serializer.dart';{{/useDateLibTimeMachine}} +{{#models}}{{#model}}import 'package:{{pubName}}/{{sourceFolder}}/{{modelPackage}}/{{classFilename}}.dart'; {{/model}}{{/models}}{{#builtValueSerializerImports}}import '{{{.}}}'; {{/builtValueSerializerImports}}