Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT][TYPESCRIPT-ANGULAR] Add configurationPrefix option #7731

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ additionalProperties:
npmRepository: https://skimdb.npmjs.com/registry
snapshot: false
apiModulePrefix: PetStore
configurationPrefix: PetStore
1 change: 1 addition & 0 deletions docs/generators/typescript-angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>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.</dd></dl>|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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<suffix>.ts).").defaultValue(this.serviceFileSuffix));
this.cliOptions.add(new CliOption(MODEL_SUFFIX, "The suffix of the generated model."));
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}
Expand All @@ -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 } ]
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterIn
{{/description}}
export interface {{classname}}Interface {
defaultHeaders: HttpHeaders;
configuration: Configuration;
configuration: {{configurationClassName}};

{{#operation}}
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpParameterCodec } from '@angular/common/http';

export interface ConfigurationParameters {
export interface {{configurationParametersInterfaceName}} {
/**
* @deprecated Since 5.0. Use credentials instead
*/
Expand All @@ -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
*/
Expand All @@ -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;
Expand Down Expand Up @@ -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 <code>undefined</code> if no selection could be made.
Expand All @@ -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 <code>undefined</code> if no selection could be made.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -75,6 +76,7 @@ public Map<String, String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 } ]
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpParameterCodec } from '@angular/common/http';

export interface ConfigurationParameters {
export interface PetStoreConfigurationParameters {
/**
* @deprecated Since 5.0. Use credentials instead
*/
Expand All @@ -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
*/
Expand All @@ -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;
Expand Down Expand Up @@ -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 <code>undefined</code> if no selection could be made.
Expand All @@ -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 <code>undefined</code> if no selection could be made.
Expand Down