Skip to content

Commit ca687de

Browse files
committed
chore: add typings
1 parent 4fa8642 commit ca687de

File tree

5 files changed

+40
-31
lines changed

5 files changed

+40
-31
lines changed

.changeset/green-hairs-suffer.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/respect-core/src/modules/arazzo-description-generator/generate-arazzo-description.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ export async function generateArazzoDescription({
5454
descriptionPaths: pathsObject,
5555
sourceDescriptionName,
5656
rootSecurity,
57-
inputsComponents,
57+
inputsComponents: inputsComponents || {},
5858
securitySchemes: components?.securitySchemes,
5959
}),
6060
...(inputsComponents && {
61-
components: {
62-
...inputsComponents,
63-
},
61+
components: inputsComponents,
6462
}),
6563
};
6664

packages/respect-core/src/modules/arazzo-description-generator/generate-inputs-arazzo-components.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
import { type ArazzoDefinition } from 'core/src/typings/arazzo';
12
import { type Oas3SecurityScheme } from 'core/src/typings/openapi';
23

34
export function generateSecurityInputsArazzoComponents(
45
securitySchemes: Record<string, Oas3SecurityScheme>
56
) {
6-
const inputs: {
7-
[key: string]: {
8-
[key: string]: any;
9-
};
10-
} = {};
7+
const inputs: NonNullable<ArazzoDefinition['components']>['inputs'] = {};
118

129
for (const [name, securityScheme] of Object.entries(securitySchemes)) {
1310
if (securityScheme.type !== 'http' && securityScheme.type !== 'apiKey') {

packages/respect-core/src/modules/arazzo-description-generator/generate-workflow-security-inputs.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
export function generateWorkflowSecurityInputs(inputsComponents: any, security: any[]) {
2-
if (security?.length > 0) {
3-
for (const securityRequirement of security) {
4-
for (const securityName of Object.keys(securityRequirement)) {
5-
if (inputsComponents?.inputs?.[securityName]) {
6-
return {
7-
$ref: `#/components/inputs/${securityName}`,
8-
};
9-
}
2+
if (!security?.length) {
3+
return undefined;
4+
}
5+
6+
for (const securityRequirement of security) {
7+
for (const securityName of Object.keys(securityRequirement)) {
8+
if (inputsComponents?.inputs?.[securityName]) {
9+
return {
10+
$ref: `#/components/inputs/${securityName}`,
11+
};
1012
}
1113
}
1214
}

packages/respect-core/src/modules/arazzo-description-generator/generate-workflows-from-description.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import { sortMethods } from '../../utils/sort';
22
import { generateWorkflowSecurityInputs } from './generate-workflow-security-inputs';
3-
import { type OperationMethod, type Workflow, type Step } from '../../types';
43
import { generateWorkflowSecurityParameters } from './generate-workflow-security-parameters';
4+
import {
5+
type Oas3SecurityScheme,
6+
type Oas3SecurityRequirement,
7+
type Oas3PathItem,
8+
type Oas3_1Schema,
9+
type Oas3Operation,
10+
} from 'core/src/typings/openapi';
11+
import { type OperationMethod, type Workflow, type Step } from '../../types';
12+
import {
13+
type ArazzoDefinition,
14+
type ExtendedOperation,
15+
} from '@redocly/openapi-core/lib/typings/arazzo';
16+
17+
type HttpMethod = Lowercase<ExtendedOperation['method']>;
518

619
export type WorkflowsFromDescriptionInput = {
7-
descriptionPaths: any;
20+
descriptionPaths: {
21+
[name: string]: Oas3PathItem<Oas3_1Schema> & {
22+
connect?: Oas3Operation<Oas3_1Schema>;
23+
query?: Oas3Operation<Oas3_1Schema>;
24+
};
25+
};
826
sourceDescriptionName: string;
9-
rootSecurity: any;
10-
inputsComponents: any;
11-
securitySchemes: any;
27+
rootSecurity: Oas3SecurityRequirement[];
28+
inputsComponents: NonNullable<ArazzoDefinition['components']>;
29+
securitySchemes: Record<string, Oas3SecurityScheme>;
1230
};
1331

1432
export function generateWorkflowsFromDescription({
@@ -22,7 +40,7 @@ export function generateWorkflowsFromDescription({
2240

2341
for (const pathItemKey in descriptionPaths) {
2442
for (const pathItemObjectKey of Object.keys(descriptionPaths[pathItemKey]).sort(sortMethods)) {
25-
const methodToCheck = pathItemObjectKey.toLocaleLowerCase();
43+
const methodToCheck = pathItemObjectKey.toLocaleLowerCase() as HttpMethod;
2644

2745
if (
2846
[
@@ -44,7 +62,7 @@ export function generateWorkflowsFromDescription({
4462
.split('/')
4563
.join('-');
4664

47-
const operation = descriptionPaths[pathItemKey][method];
65+
const operation = descriptionPaths[pathItemKey][methodToCheck.toLowerCase() as HttpMethod];
4866
const operationSecurity = operation?.security || undefined;
4967
const operationId = operation?.operationId || generateOperationId(pathItemKey, method);
5068
const workflowSecurityInputs = generateWorkflowSecurityInputs(
@@ -68,7 +86,7 @@ export function generateWorkflowsFromDescription({
6886
stepId: pathKey ? `${method}-${pathKey}-step` : `${method}-step`,
6987
operationId: `$sourceDescriptions.${sourceDescriptionName}.${operationId}`,
7088
...generateParametersWithSuccessCriteria(
71-
descriptionPaths[pathItemKey][method].responses
89+
descriptionPaths[pathItemKey][methodToCheck.toLowerCase() as HttpMethod]?.responses
7290
),
7391
} as unknown as Step,
7492
],

0 commit comments

Comments
 (0)