Skip to content

Commit cc643f9

Browse files
committed
feat: improve generate-arazzo commang output
1 parent 54b462e commit cc643f9

File tree

12 files changed

+793
-82
lines changed

12 files changed

+793
-82
lines changed

packages/core/src/typings/openapi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ export interface Oas3SecurityRequirement {
292292
}
293293

294294
export interface Oas3SecurityScheme {
295-
type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
295+
type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect' | 'mutualTLS';
296296
description?: string;
297297
name?: string;
298298
in?: 'query' | 'header' | 'cookie';
299299
scheme?: string;
300-
bearerFormat: string;
300+
bearerFormat?: string;
301301
flows: {
302302
implicit?: {
303303
refreshUrl?: string;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Oas3SecurityScheme } from 'core/src/typings/openapi';
2+
import { generateSecurityInputsArazzoComponents } from '../../arazzo-description-generator';
3+
4+
describe('generateSecurityInputsArazzoComponents', () => {
5+
it('should generate empty inputs for the security schemes if there are no security schemes', () => {
6+
const securitySchemes = {};
7+
const result = generateSecurityInputsArazzoComponents(securitySchemes);
8+
expect(result).toEqual({ inputs: {} });
9+
});
10+
11+
it('should generate the correct inputs for the Basic auth security scheme', () => {
12+
const securitySchemes = {
13+
basicAuth: {
14+
type: 'http' as const,
15+
scheme: 'basic',
16+
} as Oas3SecurityScheme,
17+
};
18+
const result = generateSecurityInputsArazzoComponents(securitySchemes);
19+
expect(result).toEqual({
20+
inputs: {
21+
basicAuth: {
22+
type: 'object',
23+
properties: {
24+
username: { type: 'string', description: 'Username for basic authentication' },
25+
password: {
26+
type: 'string',
27+
format: 'password',
28+
description: 'Password for basic authentication',
29+
},
30+
},
31+
required: ['username', 'password'],
32+
},
33+
},
34+
});
35+
});
36+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { generateWorkflowSecurityInputs } from '../../arazzo-description-generator';
2+
3+
describe('generateWorkflowSecurityInputs', () => {
4+
it('should return undefined if there are no security requirements', () => {
5+
const inputsComponents = {};
6+
const security = [] as any[];
7+
const result = generateWorkflowSecurityInputs(inputsComponents, security);
8+
expect(result).toBeUndefined();
9+
});
10+
11+
it('should return the correct workflow security inputs reference', () => {
12+
const inputsComponents = {
13+
inputs: {
14+
basicAuth: {
15+
type: 'object',
16+
},
17+
bearerAuth: {
18+
type: 'string',
19+
},
20+
},
21+
};
22+
const security = [{ basicAuth: [] }];
23+
const result = generateWorkflowSecurityInputs(inputsComponents, security);
24+
expect(result).toEqual({
25+
$ref: '#/components/inputs/basicAuth',
26+
});
27+
});
28+
29+
it('should return undefined if the security requirement is not found in the inputs components', () => {
30+
const inputsComponents = {
31+
inputs: {
32+
basicAuth: {
33+
type: 'object',
34+
},
35+
bearerAuth: {
36+
type: 'string',
37+
},
38+
},
39+
};
40+
const security = [{ apiKey: [] }];
41+
const result = generateWorkflowSecurityInputs(inputsComponents, security);
42+
expect(result).toBeUndefined();
43+
});
44+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { generateWorkflowSecurityParameters } from '../../arazzo-description-generator';
2+
3+
describe('generateWorkflowSecurityParameters', () => {
4+
it('should return the correct workflow security parameters for Basic authentication', () => {
5+
const inputsComponents = {
6+
inputs: {
7+
basicAuth: {
8+
type: 'object',
9+
properties: {
10+
username: {
11+
type: 'string',
12+
description: 'Username for basic authentication',
13+
},
14+
password: {
15+
type: 'string',
16+
description: 'Password for basic authentication',
17+
format: 'password',
18+
},
19+
},
20+
},
21+
},
22+
};
23+
24+
const security = [{ basicAuth: [] }];
25+
26+
const securitySchemes = {
27+
basicAuth: {
28+
type: 'http',
29+
scheme: 'basic',
30+
},
31+
} as any;
32+
33+
const result = generateWorkflowSecurityParameters(inputsComponents, security, securitySchemes);
34+
35+
expect(result).toEqual([
36+
{
37+
name: 'Authorization',
38+
value: `Basic ....`,
39+
in: 'header',
40+
},
41+
]);
42+
});
43+
44+
it('should return the correct workflow security parameters for Bearer authentication', () => {
45+
const inputsComponents = {
46+
inputs: {
47+
bearerAuth: {
48+
type: 'string',
49+
description: 'Bearer token',
50+
format: 'password',
51+
},
52+
},
53+
};
54+
55+
const security = [{ bearerAuth: [] }];
56+
57+
const securitySchemes = {
58+
bearerAuth: {
59+
type: 'http',
60+
scheme: 'bearer',
61+
},
62+
} as any;
63+
64+
const result = generateWorkflowSecurityParameters(inputsComponents, security, securitySchemes);
65+
66+
expect(result).toEqual([
67+
{
68+
name: 'Authorization',
69+
value: `Bearer {$inputs.bearerAuth}`,
70+
in: 'header',
71+
},
72+
]);
73+
});
74+
75+
it('should return an empty array if there are no security parameters', () => {
76+
const inputsComponents = {};
77+
const security = [] as any;
78+
const securitySchemes = {};
79+
80+
const result = generateWorkflowSecurityParameters(inputsComponents, security, securitySchemes);
81+
82+
expect(result).toEqual([]);
83+
});
84+
85+
it('should return an empty array if the security scheme is not supported', () => {
86+
const inputsComponents = {
87+
inputs: {
88+
oauth2Auth: {
89+
type: 'string',
90+
description: 'OAuth2 token',
91+
},
92+
},
93+
};
94+
const security = [{ oauth2Auth: [] }] as any;
95+
const securitySchemes = {
96+
oauth2Auth: {
97+
type: 'oauth2',
98+
},
99+
} as any;
100+
101+
const result = generateWorkflowSecurityParameters(inputsComponents, security, securitySchemes);
102+
103+
expect(result).toEqual([]);
104+
});
105+
});

0 commit comments

Comments
 (0)