Skip to content

Commit e4e45d9

Browse files
author
Adrian Gutierrez
committed
Add excludeParameters functionality, this is useful when you have interceptors in the angular app for example Tenant-Code or X-Authorization
1 parent 8633e04 commit e4e45d9

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
.directory
33
dist
4-
out
4+
out
5+
.idea

lib/operation.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,28 @@ export class Operation {
7070
const result: Parameter[] = [];
7171
if (params) {
7272
for (let param of params) {
73-
if (param.$ref) {
74-
param = resolveRef(this.openApi, param.$ref);
75-
}
76-
param = param as ParameterObject;
77-
if (param.in === 'cookie') {
78-
console.warn(`Ignoring cookie parameter ${this.id}.${param.name} as cookie parameters cannot be sent in XmlHttpRequests.`);
79-
} else {
80-
result.push(new Parameter(param as ParameterObject, this.options));
73+
74+
if (param.$ref) {
75+
param = resolveRef(this.openApi, param.$ref);
76+
}
77+
param = param as ParameterObject;
78+
79+
if (param.in === 'cookie') {
80+
console.warn(`Ignoring cookie parameter ${this.id}.${param.name} as cookie parameters cannot be sent in XmlHttpRequests.`);
81+
} else if (this.paramIsNotExcluded(param)) {
82+
result.push(new Parameter(param as ParameterObject, this.options));
83+
}
8184
}
82-
}
85+
8386
}
8487
return result;
8588
}
8689

90+
private paramIsNotExcluded (param: ParameterObject): boolean {
91+
const excludedParameters = this.options.excludeParameters || [];
92+
93+
return !excludedParameters.includes(param.name);
94+
}
8795
private collectContent(desc: ContentObject | undefined): Content[] {
8896
const result: Content[] = [];
8997
if (desc) {

lib/options.ts

+3
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,7 @@ export interface Options {
7373
/** Custom templates directory. Any `.handlebars` files here will be used instead of the corresponding default. */
7474
templates?: string;
7575

76+
/** When specified, filters the generated services, excluding any param corresponding to this list of params. */
77+
excludeParameters?: string[];
78+
7679
}

ng-openapi-gen-schema.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@
135135
"templates": {
136136
"description": "Custom templates directory. Any `.handlebars` files here will be used instead of the corresponding default.",
137137
"type": "string"
138+
},
139+
"excludeParameters": {
140+
"description": "When specified, filters the generated services, excluding any param corresponding to this list of params.",
141+
"type": "array",
142+
"items": {
143+
"type": "string"
144+
}
138145
}
139146
}
140-
}
147+
}

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-openapi-gen",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"license": "MIT",
55
"author": "Cyclos development team",
66
"description": "An OpenAPI 3 codegen for Angular 6+",

0 commit comments

Comments
 (0)