diff --git a/bin/configs/typescript-angular-with-prefixed-module-name-v8.yaml b/bin/configs/typescript-angular-with-prefixed-module-name-v8.yaml index b7cf4fd45e81..d0c0e1cd0b70 100644 --- a/bin/configs/typescript-angular-with-prefixed-module-name-v8.yaml +++ b/bin/configs/typescript-angular-with-prefixed-module-name-v8.yaml @@ -8,3 +8,4 @@ additionalProperties: npmRepository: https://skimdb.npmjs.com/registry snapshot: false apiModulePrefix: PetStore + configurationPrefix: PetStore diff --git a/docs/generators/typescript-angular.md b/docs/generators/typescript-angular.md index d859d3f759b1..55a7c1477dd6 100644 --- a/docs/generators/typescript-angular.md +++ b/docs/generators/typescript-angular.md @@ -9,6 +9,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | ------ | ----------- | ------ | ------- | |allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| |apiModulePrefix|The prefix of the generated ApiModule.| |null| +|configurationPrefix|The prefix of the generated Configuration.| |null| |disallowAdditionalPropertiesIfNotPresent|Specify the behavior when the 'additionalProperties' keyword is not present in the OAS document. If false: the 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications. If true: when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.This setting is currently ignored for OAS 2.0 documents: 1) When the 'additionalProperties' keyword is not present in a 2.0 schema, additional properties are NOT allowed. 2) Boolean values of the 'additionalProperties' keyword are ignored. It's as if additional properties are NOT allowed.Note: the root cause are issues #1369 and #1371, which must be resolved in the swagger-parser project.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is automatically set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.
|true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names.| |Enum| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java index 2ddd43eb04de..7436c8c2915a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java @@ -52,6 +52,7 @@ public static enum QUERY_PARAM_OBJECT_FORMAT_TYPE {dot, json, key}; public static final String PROVIDED_IN_ROOT = "providedInRoot"; public static final String ENFORCE_GENERIC_MODULE_WITH_PROVIDERS = "enforceGenericModuleWithProviders"; public static final String API_MODULE_PREFIX = "apiModulePrefix"; + public static final String CONFIGURATION_PREFIX = "configurationPrefix"; public static final String SERVICE_SUFFIX = "serviceSuffix"; public static final String SERVICE_FILE_SUFFIX = "serviceFileSuffix"; public static final String MODEL_SUFFIX = "modelSuffix"; @@ -107,6 +108,7 @@ public TypeScriptAngularClientCodegen() { false)); this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular. (At least 6.0.0)").defaultValue(this.ngVersion)); this.cliOptions.add(new CliOption(API_MODULE_PREFIX, "The prefix of the generated ApiModule.")); + this.cliOptions.add(new CliOption(CONFIGURATION_PREFIX, "The prefix of the generated Configuration.")); this.cliOptions.add(new CliOption(SERVICE_SUFFIX, "The suffix of the generated service.").defaultValue(this.serviceSuffix)); this.cliOptions.add(new CliOption(SERVICE_FILE_SUFFIX, "The suffix of the file of the generated service (service.ts).").defaultValue(this.serviceFileSuffix)); this.cliOptions.add(new CliOption(MODEL_SUFFIX, "The suffix of the generated model.")); @@ -210,6 +212,16 @@ public void processOpts() { } else { additionalProperties.put("apiModuleClassName", "ApiModule"); } + if (additionalProperties.containsKey(CONFIGURATION_PREFIX)) { + String configurationPrefix = additionalProperties.get(CONFIGURATION_PREFIX).toString(); + validateClassPrefixArgument("Configuration", configurationPrefix); + + additionalProperties.put("configurationClassName", configurationPrefix + "Configuration"); + additionalProperties.put("configurationParametersInterfaceName", configurationPrefix + "ConfigurationParameters"); + } else { + additionalProperties.put("configurationClassName", "Configuration"); + additionalProperties.put("configurationParametersInterfaceName", "ConfigurationParameters"); + } if (additionalProperties.containsKey(SERVICE_SUFFIX)) { serviceSuffix = additionalProperties.get(SERVICE_SUFFIX).toString(); validateClassSuffixArgument("Service", serviceSuffix); diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache index f94be6a072a8..1c4ec6efb232 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache @@ -73,13 +73,13 @@ export class AppModule {} ``` // configuring providers -import { ApiModule, Configuration, ConfigurationParameters } from '{{npmName}}'; +import { ApiModule, {{configurationClassName}}, {{configurationParametersInterfaceName}} } from '{{npmName}}'; -export function apiConfigFactory (): Configuration => { - const params: ConfigurationParameters = { +export function apiConfigFactory (): {{configurationClassName}} => { + const params: {{configurationParametersInterfaceName}} = { // set configuration parameters here. } - return new Configuration(params); + return new {{configurationClassName}}(params); } @NgModule({ @@ -93,15 +93,15 @@ export class AppModule {} ``` // configuring providers with an authentication service that manages your access tokens -import { ApiModule, Configuration } from '{{npmName}}'; +import { ApiModule, {{configurationClassName}} } from '{{npmName}}'; @NgModule({ imports: [ ApiModule ], declarations: [ AppComponent ], providers: [ { - provide: Configuration, - useFactory: (authService: AuthService) => new Configuration( + provide: {{configurationClassName}}, + useFactory: (authService: AuthService) => new {{configurationClassName}}( { basePath: environment.apiUrl, accessToken: authService.getAccessToken.bind(authService) diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/api.module.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/api.module.mustache index 74fae2fb22ed..42a995c1b54f 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/api.module.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/api.module.mustache @@ -1,5 +1,5 @@ import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core'; -import { Configuration } from './configuration'; +import { {{configurationClassName}} } from './configuration'; import { HttpClient } from '@angular/common/http'; {{#apiInfo}} @@ -17,10 +17,10 @@ import { {{classname}} } from './{{importPath}}'; {{/hasMore}}{{/apis}}{{/apiInfo}} {{/providedInRoot}}] }) export class {{apiModuleClassName}} { - public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders{{#enforceGenericModuleWithProviders}}<{{apiModuleClassName}}>{{/enforceGenericModuleWithProviders}} { + public static forRoot(configurationFactory: () => {{configurationClassName}}): ModuleWithProviders{{#enforceGenericModuleWithProviders}}<{{apiModuleClassName}}>{{/enforceGenericModuleWithProviders}} { return { ngModule: {{apiModuleClassName}}, - providers: [ { provide: Configuration, useFactory: configurationFactory } ] + providers: [ { provide: {{configurationClassName}}, useFactory: configurationFactory } ] }; } diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache index 0f90f8effa79..44194e1c73ce 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache @@ -12,7 +12,7 @@ import { {{classname}} } from '../model/models'; {{/imports}} import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; +import { {{configurationClassName}} } from '../configuration'; {{#withInterfaces}} import { {{classname}}Interface{{#useSingleRequestParameter}}{{#operations}}{{#operation}}{{#allParams.0}}, @@ -60,10 +60,10 @@ export class {{classname}} { protected basePath = '{{{basePath}}}'; public defaultHeaders = new HttpHeaders(); - public configuration = new Configuration(); + public configuration = new {{configurationClassName}}(); public encoder: HttpParameterCodec; - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: {{configurationClassName}}) { if (configuration) { this.configuration = configuration; } diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/apiInterface.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/apiInterface.mustache index d981d629a667..89fed56e2674 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/apiInterface.mustache @@ -32,7 +32,7 @@ export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterIn {{/description}} export interface {{classname}}Interface { defaultHeaders: HttpHeaders; - configuration: Configuration; + configuration: {{configurationClassName}}; {{#operation}} /** diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/configuration.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/configuration.mustache index 19b1314a9f66..e3a5e8243854 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/configuration.mustache @@ -1,6 +1,6 @@ import { HttpParameterCodec } from '@angular/common/http'; -export interface ConfigurationParameters { +export interface {{configurationParametersInterfaceName}} { /** * @deprecated Since 5.0. Use credentials instead */ @@ -22,7 +22,7 @@ export interface ConfigurationParameters { credentials?: {[ key: string ]: string | (() => string | undefined)}; } -export class Configuration { +export class {{configurationClassName}} { /** * @deprecated Since 5.0. Use credentials instead */ @@ -43,7 +43,7 @@ export class Configuration { */ credentials: {[ key: string ]: string | (() => string | undefined)}; - constructor(configurationParameters: ConfigurationParameters = {}) { + constructor(configurationParameters: {{configurationParametersInterfaceName}} = {}) { this.apiKeys = configurationParameters.apiKeys; this.username = configurationParameters.username; this.password = configurationParameters.password; @@ -96,7 +96,7 @@ export class Configuration { /** * Select the correct content-type to use for a request. - * Uses {@link Configuration#isJsonMime} to determine the correct content-type. + * Uses {@link {{configurationClassName}}#isJsonMime} to determine the correct content-type. * If no content type is found return the first found type if the contentTypes is not empty * @param contentTypes - the array of content types that are available for selection * @returns the selected content-type or undefined if no selection could be made. @@ -115,7 +115,7 @@ export class Configuration { /** * Select the correct accept content-type to use for a request. - * Uses {@link Configuration#isJsonMime} to determine the correct accept content-type. + * Uses {@link {{configurationClassName}}#isJsonMime} to determine the correct accept content-type. * If no content type is found return the first found type if the contentTypes is not empty * @param accepts - the array of content types that are available for selection. * @returns the selected content-type or undefined if no selection could be made. diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptAngularClientOptionsProvider.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptAngularClientOptionsProvider.java index ca8c7f491e97..51049743954c 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptAngularClientOptionsProvider.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptAngularClientOptionsProvider.java @@ -42,6 +42,7 @@ public class TypeScriptAngularClientOptionsProvider implements OptionsProvider { public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true"; public static final String FILE_NAMING_VALUE = "camelCase"; public static final String API_MODULE_PREFIX = ""; + public static final String CONFIGURATION_PREFIX = ""; public static final String QUERY_PARAM_OBJECT_FORMAT_VALUE = "dot"; public static String SERVICE_SUFFIX = "Service"; public static String SERVICE_FILE_SUFFIX = ".service"; @@ -75,6 +76,7 @@ public Map createOptions() { .put(TypeScriptAngularClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY) .put(TypeScriptAngularClientCodegen.NG_VERSION, NG_VERSION) .put(TypeScriptAngularClientCodegen.API_MODULE_PREFIX, API_MODULE_PREFIX) + .put(TypeScriptAngularClientCodegen.CONFIGURATION_PREFIX, CONFIGURATION_PREFIX) .put(TypeScriptAngularClientCodegen.SERVICE_SUFFIX, SERVICE_SUFFIX) .put(TypeScriptAngularClientCodegen.SERVICE_FILE_SUFFIX, SERVICE_FILE_SUFFIX) .put(TypeScriptAngularClientCodegen.MODEL_SUFFIX, MODEL_SUFFIX) diff --git a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/README.md b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/README.md index 151fb2f1a505..89dd72d00f78 100644 --- a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/README.md +++ b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/README.md @@ -73,13 +73,13 @@ export class AppModule {} ``` // configuring providers -import { ApiModule, Configuration, ConfigurationParameters } from '@openapitools/typescript-angular-petstore'; +import { ApiModule, PetStoreConfiguration, PetStoreConfigurationParameters } from '@openapitools/typescript-angular-petstore'; -export function apiConfigFactory (): Configuration => { - const params: ConfigurationParameters = { +export function apiConfigFactory (): PetStoreConfiguration => { + const params: PetStoreConfigurationParameters = { // set configuration parameters here. } - return new Configuration(params); + return new PetStoreConfiguration(params); } @NgModule({ @@ -93,15 +93,15 @@ export class AppModule {} ``` // configuring providers with an authentication service that manages your access tokens -import { ApiModule, Configuration } from '@openapitools/typescript-angular-petstore'; +import { ApiModule, PetStoreConfiguration } from '@openapitools/typescript-angular-petstore'; @NgModule({ imports: [ ApiModule ], declarations: [ AppComponent ], providers: [ { - provide: Configuration, - useFactory: (authService: AuthService) => new Configuration( + provide: PetStoreConfiguration, + useFactory: (authService: AuthService) => new PetStoreConfiguration( { basePath: environment.apiUrl, accessToken: authService.getAccessToken.bind(authService) diff --git a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api.module.ts b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api.module.ts index 61312d8cab77..3ef34151107c 100644 --- a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api.module.ts +++ b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api.module.ts @@ -1,5 +1,5 @@ import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core'; -import { Configuration } from './configuration'; +import { PetStoreConfiguration } from './configuration'; import { HttpClient } from '@angular/common/http'; import { PetService } from './api/pet.service'; @@ -13,10 +13,10 @@ import { UserService } from './api/user.service'; providers: [] }) export class PetStoreApiModule { - public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders { + public static forRoot(configurationFactory: () => PetStoreConfiguration): ModuleWithProviders { return { ngModule: PetStoreApiModule, - providers: [ { provide: Configuration, useFactory: configurationFactory } ] + providers: [ { provide: PetStoreConfiguration, useFactory: configurationFactory } ] }; } diff --git a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/pet.service.ts b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/pet.service.ts index 46fef0be89fe..0975398771b9 100644 --- a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/pet.service.ts @@ -21,7 +21,7 @@ import { ApiResponse } from '../model/models'; import { Pet } from '../model/models'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; +import { PetStoreConfiguration } from '../configuration'; @@ -32,10 +32,10 @@ export class PetService { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders = new HttpHeaders(); - public configuration = new Configuration(); + public configuration = new PetStoreConfiguration(); public encoder: HttpParameterCodec; - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: PetStoreConfiguration) { if (configuration) { this.configuration = configuration; } diff --git a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/store.service.ts b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/store.service.ts index d5d08ab3adc3..1ca9d2fc346f 100644 --- a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/store.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs'; import { Order } from '../model/models'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; +import { PetStoreConfiguration } from '../configuration'; @@ -31,10 +31,10 @@ export class StoreService { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders = new HttpHeaders(); - public configuration = new Configuration(); + public configuration = new PetStoreConfiguration(); public encoder: HttpParameterCodec; - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: PetStoreConfiguration) { if (configuration) { this.configuration = configuration; } diff --git a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/user.service.ts b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/user.service.ts index 399676219054..a79076289582 100644 --- a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/api/user.service.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs'; import { User } from '../model/models'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; +import { PetStoreConfiguration } from '../configuration'; @@ -31,10 +31,10 @@ export class UserService { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders = new HttpHeaders(); - public configuration = new Configuration(); + public configuration = new PetStoreConfiguration(); public encoder: HttpParameterCodec; - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: PetStoreConfiguration) { if (configuration) { this.configuration = configuration; } diff --git a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/configuration.ts b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/configuration.ts index 38126642420d..1bd306a523eb 100644 --- a/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/configuration.ts +++ b/samples/client/petstore/typescript-angular-v8-provided-in-root/builds/with-prefixed-module-name/configuration.ts @@ -1,6 +1,6 @@ import { HttpParameterCodec } from '@angular/common/http'; -export interface ConfigurationParameters { +export interface PetStoreConfigurationParameters { /** * @deprecated Since 5.0. Use credentials instead */ @@ -22,7 +22,7 @@ export interface ConfigurationParameters { credentials?: {[ key: string ]: string | (() => string | undefined)}; } -export class Configuration { +export class PetStoreConfiguration { /** * @deprecated Since 5.0. Use credentials instead */ @@ -43,7 +43,7 @@ export class Configuration { */ credentials: {[ key: string ]: string | (() => string | undefined)}; - constructor(configurationParameters: ConfigurationParameters = {}) { + constructor(configurationParameters: PetStoreConfigurationParameters = {}) { this.apiKeys = configurationParameters.apiKeys; this.username = configurationParameters.username; this.password = configurationParameters.password; @@ -77,7 +77,7 @@ export class Configuration { /** * Select the correct content-type to use for a request. - * Uses {@link Configuration#isJsonMime} to determine the correct content-type. + * Uses {@link PetStoreConfiguration#isJsonMime} to determine the correct content-type. * If no content type is found return the first found type if the contentTypes is not empty * @param contentTypes - the array of content types that are available for selection * @returns the selected content-type or undefined if no selection could be made. @@ -96,7 +96,7 @@ export class Configuration { /** * Select the correct accept content-type to use for a request. - * Uses {@link Configuration#isJsonMime} to determine the correct accept content-type. + * Uses {@link PetStoreConfiguration#isJsonMime} to determine the correct accept content-type. * If no content type is found return the first found type if the contentTypes is not empty * @param accepts - the array of content types that are available for selection. * @returns the selected content-type or undefined if no selection could be made.