Skip to content

Commit b40b213

Browse files
committed
Added security check for operations
1 parent a9970e4 commit b40b213

File tree

8 files changed

+23
-7
lines changed

8 files changed

+23
-7
lines changed

src/client/interfaces/Operation.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ export interface Operation extends OperationParameters {
1313
errors: OperationError[];
1414
results: OperationResponse[];
1515
responseHeader: string | null;
16-
secured: boolean;
16+
security: {
17+
secured: boolean;
18+
optional: boolean;
19+
};
1720
}

src/openApi/v2/parser/getOperation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export const getOperation = (
4242
errors: [],
4343
results: [],
4444
responseHeader: null,
45+
security: {
46+
secured: !!op.security && op.security.length > 0,
47+
optional:
48+
!!op.security && op.security.length > 0
49+
? false
50+
: op.security!.some(item => Object.keys(item).length == 0),
51+
},
4552
};
4653

4754
// Parse the operation parameters (path, query, body, etc).

src/openApi/v3/parser/getOperation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ export const getOperation = (
4545
errors: [],
4646
results: [],
4747
responseHeader: null,
48-
secured: !!op.security,
48+
security: {
49+
secured: !!op.security && op.security.length > 0,
50+
optional:
51+
!!op.security && op.security.length > 0
52+
? false
53+
: op.security!.some(item => Object.keys(item).length == 0),
54+
},
4955
};
5056

5157
// Parse the operation parameters (path, query, body, etc).

src/templates/core/angular/getHeaders.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observable<HttpHeaders> => {
2-
const token = options.secured ? await resolve(options, config.TOKEN) : undefined;
2+
const token = options.security.secured ? await resolve(options, config.TOKEN) : undefined;
33
return forkJoin({
44
token,
55
username: resolve(options, config.USERNAME),

src/templates/core/axios/getHeaders.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, formData?: FormData): Promise<Record<string, string>> => {
2-
const token = options.secured ? await resolve(options, config.TOKEN) : undefined;
2+
const token = options.security.secured ? await resolve(options, config.TOKEN) : undefined;
33
const username = await resolve(options, config.USERNAME);
44
const password = await resolve(options, config.PASSWORD);
55
const additionalHeaders = await resolve(options, config.HEADERS);

src/templates/core/fetch/getHeaders.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
2-
const token = options.secured ? await resolve(options, config.TOKEN) : undefined;
2+
const token = options.security.secured ? await resolve(options, config.TOKEN) : undefined;
33
const username = await resolve(options, config.USERNAME);
44
const password = await resolve(options, config.PASSWORD);
55
const additionalHeaders = await resolve(options, config.HEADERS);

src/templates/core/node/getHeaders.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
2-
const token = await resolve(options, config.TOKEN);
2+
const token = options.security.secured ? await resolve(options, config.TOKEN) : undefined;
33
const username = await resolve(options, config.USERNAME);
44
const password = await resolve(options, config.PASSWORD);
55
const additionalHeaders = await resolve(options, config.HEADERS);

src/templates/core/xhr/getHeaders.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
2-
const token = options.secured ? await resolve(options, config.TOKEN) : undefined;
2+
const token = options.security.secured ? await resolve(options, config.TOKEN) : undefined;
33
const username = await resolve(options, config.USERNAME);
44
const password = await resolve(options, config.PASSWORD);
55
const additionalHeaders = await resolve(options, config.HEADERS);

0 commit comments

Comments
 (0)