Skip to content

Commit

Permalink
feature: add customApiConfiguration flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Koenig authored and mojoaxel committed Sep 26, 2022
1 parent 1148af3 commit e651ed3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class Globals {
modelIndexFile?: string;
serviceIndexFile?: string;
rootUrl?: string;
customApiConfiguration?: string;

constructor(options: Options) {
this.configurationClass = options.configuration || 'ApiConfiguration';
Expand All @@ -42,6 +43,10 @@ export class Globals {
if (options.modelIndex !== false && options.modelIndex !== '') {
this.modelIndexFile = options.modelIndex === true || options.modelIndex == undefined ? 'models' : options.modelIndex;
}
if (options.customApiConfiguration) {
this.customApiConfiguration = options.customApiConfiguration;
this.configurationFile = this.customApiConfiguration;
}
}

}
4 changes: 3 additions & 1 deletion lib/ng-openapi-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export class NgOpenApiGen {
};

// Generate the general files
this.write('configuration', general, this.globals.configurationFile);
if (!this.globals.customApiConfiguration) {
this.write('configuration', general, this.globals.configurationFile);
}
this.write('response', general, this.globals.responseFile);
this.write('requestBuilder', general, this.globals.requestBuilderFile);
this.write('baseService', general, this.globals.baseServiceFile);
Expand Down
3 changes: 3 additions & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@ export interface Options {

/** When specified, will create temporary files in system temporary folder instead of next to output folder. */
useTempDir?: boolean;

/** When set, the ApiConfiguration file not be generated and only a custom import will be used */
customApiConfiguration?: string;
}
5 changes: 5 additions & 0 deletions ng-openapi-gen-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
"description": "When specified, will create temporary files in system temporary folder instead of output folder",
"default": false,
"type": "boolean"
},
"customApiConfiguration": {
"description": "When set, the ApiConfiguration file not be generated and only a custom import will be used",
"default": "",
"type": "string"
}
}
}
4 changes: 4 additions & 0 deletions templates/baseService.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
/* eslint-disable */
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
{{#if customApiConfiguration}}
import { {{configurationClass}} } from '{{configurationFile}}';
{{else}}
import { {{configurationClass}} } from './{{configurationFile}}';
{{/if}}

/**
* Base class for services
Expand Down
5 changes: 5 additions & 0 deletions templates/index.handlebars
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

{{#if customApiConfiguration}}
export { {{configurationClass}} } from '{{{configurationFile}}}';
{{else}}
export { {{configurationClass}} } from './{{{configurationFile}}}';
{{/if}}
export { {{baseServiceClass}} } from './{{{baseServiceFile}}}';
export { {{requestBuilderClass}} } from './{{{requestBuilderFile}}}';
export { {{responseClass}} } from './{{{responseFile}}}';
Expand Down
4 changes: 4 additions & 0 deletions templates/module.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
/* eslint-disable */
import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { HttpClient } from '@angular/common/http';
{{#if customApiConfiguration}}
import { {{configurationClass}}, {{configurationParams}} } from '{{configurationFile}}';
{{else}}
import { {{configurationClass}}, {{configurationParams}} } from './{{configurationFile}}';
{{/if}}

{{#services}}import { {{typeName}} } from './services/{{fileName}}';
{{/services}}
Expand Down
4 changes: 4 additions & 0 deletions templates/service.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse, HttpContext } from '@angular/common/http';
import { {{baseServiceClass}} } from '../{{baseServiceFile}}';
{{#if customApiConfiguration}}
import { {{configurationClass}} } from '{{configurationFile}}';
{{else}}
import { {{configurationClass}} } from '../{{configurationFile}}';
{{/if}}
import { {{responseClass}} } from '../{{responseFile}}';
import { {{requestBuilderClass}} } from '../{{requestBuilderFile}}';
import { Observable } from 'rxjs';
Expand Down
4 changes: 4 additions & 0 deletions test/templates/service.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { {{baseServiceClass}} } from '../{{baseServiceFile}}';
{{#if customApiConfiguration}}
import { {{configurationClass}} } from '{{configurationFile}}';
{{else}}
import { {{configurationClass}} } from '../{{configurationFile}}';
{{/if}}
import { {{responseClass}} } from '../{{responseFile}}';
import { {{requestBuilderClass}} } from '../{{requestBuilderFile}}';
import { Observable } from 'rxjs';
Expand Down

0 comments on commit e651ed3

Please sign in to comment.