-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
OperationParser.ts
60 lines (50 loc) · 1.97 KB
/
OperationParser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {OpenAPIV3} from "openapi-types";
import * as lodash from "lodash";
import {OperationContext} from "./openapi/OpenAPIVisitor";
/**
* Extract information for n8n node from OpenAPI operation
*/
export interface IOperationParser {
/**
* Name of the operation (e.g. "Create User")
*/
name(operation: OpenAPIV3.OperationObject, context: OperationContext): string
/**
* Value of the operation (e.g. "create-user")
*/
value(operation: OpenAPIV3.OperationObject, context: OperationContext): string
/**
* Action of the operation (e.g. "Create User") - will be visible in list of actions
*/
action(operation: OpenAPIV3.OperationObject, context: OperationContext): string
/**
* Description of the operation
*/
description(operation: OpenAPIV3.OperationObject, context: OperationContext): string
/**
* Should skip this operation or not
*/
shouldSkip(operation: OpenAPIV3.OperationObject, context: OperationContext): boolean;
}
/**
* Default behaviour for OpenAPI to n8n operation parser
* It will use operationId as name, value and action and summary as description
* Skip deprecated operations
*/
export class DefaultOperationParser implements IOperationParser {
shouldSkip(operation: OpenAPIV3.OperationObject, context: OperationContext): boolean {
return !!operation.deprecated
}
name(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
return lodash.startCase(operation.operationId)
}
value(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
return lodash.startCase(operation.operationId)
}
action(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
return operation.summary || this.name(operation, context)
}
description(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
return operation.description || operation.summary || '';
}
}