11import { N8NPropertiesBuilder , Override } from './N8NPropertiesBuilder' ;
2+
23import { BaseOperationsCollector } from "./OperationsCollector" ;
4+ import { OpenAPIV3 } from "openapi-types" ;
5+ import { OperationContext } from "./openapi/OpenAPIVisitor" ;
6+ import * as lodash from "lodash" ;
7+ import { DefaultOperationParser } from "./OperationParser" ;
8+
9+ export class CustomOperationParser extends DefaultOperationParser {
10+ name ( operation : OpenAPIV3 . OperationObject , context : OperationContext ) : string {
11+ let operationId : string = operation . operationId ! ! . split ( '_' ) . slice ( 1 ) . join ( '_' ) ;
12+ if ( ! operationId ) {
13+ operationId = operation . operationId as string
14+ }
15+ return lodash . startCase ( operationId )
16+ }
17+
18+ value ( operation : OpenAPIV3 . OperationObject , context : OperationContext ) : string {
19+ return this . name ( operation , context )
20+ }
21+
22+ action ( operation : OpenAPIV3 . OperationObject , context : OperationContext ) : string {
23+ return operation . summary || this . name ( operation , context )
24+ }
25+
26+ description ( operation : OpenAPIV3 . OperationObject , context : OperationContext ) : string {
27+ return operation . description || operation . summary || '' ;
28+ }
29+ }
330
431test ( 'query param' , ( ) => {
532 const paths = {
@@ -24,7 +51,7 @@ test('query param', () => {
2451 } ,
2552 } ;
2653
27- const parser = new N8NPropertiesBuilder ( { paths} ) ;
54+ const parser = new N8NPropertiesBuilder ( { paths} , { operation : new CustomOperationParser ( ) } ) ;
2855 const result = parser . build ( )
2956
3057 expect ( result ) . toEqual ( [
@@ -130,7 +157,10 @@ test('path param', () => {
130157 } ,
131158 } ;
132159
133- const parser = new N8NPropertiesBuilder ( { paths} , { OperationsCollector : BaseOperationsCollector } ) ;
160+ const parser = new N8NPropertiesBuilder ( { paths} , {
161+ OperationsCollector : BaseOperationsCollector ,
162+ operation : new CustomOperationParser ( )
163+ } ) ;
134164 const result = parser . build ( )
135165 expect ( result ) . toEqual ( [
136166 {
@@ -245,7 +275,10 @@ test('request body', () => {
245275 } ,
246276 } ;
247277
248- const parser = new N8NPropertiesBuilder ( { paths, components} , { OperationsCollector : BaseOperationsCollector } ) ;
278+ const parser = new N8NPropertiesBuilder ( { paths, components} , {
279+ OperationsCollector : BaseOperationsCollector ,
280+ operation : new CustomOperationParser ( )
281+ } ) ;
249282 const result = parser . build ( )
250283
251284 expect ( result ) . toEqual ( [
@@ -384,7 +417,10 @@ test('enum schema', () => {
384417 } ;
385418
386419 // @ts -ignore
387- const parser = new N8NPropertiesBuilder ( { paths} , { OperationsCollector : BaseOperationsCollector } ) ;
420+ const parser = new N8NPropertiesBuilder ( { paths} , {
421+ OperationsCollector : BaseOperationsCollector ,
422+ operation : new CustomOperationParser ( )
423+ } ) ;
388424 const result = parser . build ( )
389425
390426 expect ( result ) . toEqual ( [
@@ -486,7 +522,10 @@ test('body "array" param', () => {
486522 } ,
487523 } ;
488524
489- const parser = new N8NPropertiesBuilder ( { paths} , { OperationsCollector : BaseOperationsCollector } ) ;
525+ const parser = new N8NPropertiesBuilder ( { paths} , {
526+ OperationsCollector : BaseOperationsCollector ,
527+ operation : new CustomOperationParser ( )
528+ } ) ;
490529 const result = parser . build ( )
491530
492531 const expected : any [ ] = [
@@ -630,7 +669,8 @@ test('test overrides', () => {
630669 ] ;
631670
632671 const parser = new N8NPropertiesBuilder ( { paths, components} , {
633- OperationsCollector : BaseOperationsCollector
672+ OperationsCollector : BaseOperationsCollector ,
673+ operation : new CustomOperationParser ( )
634674 } ) ;
635675 const result = parser . build ( customDefaults )
636676
@@ -768,7 +808,9 @@ test('multiple tags', () => {
768808 } ,
769809 } ;
770810
771- const parser = new N8NPropertiesBuilder ( { paths} ) ;
811+ const parser = new N8NPropertiesBuilder ( { paths} , {
812+ operation : new CustomOperationParser ( )
813+ } )
772814 const result = parser . build ( )
773815
774816 expect ( result ) . toEqual (
@@ -961,7 +1003,9 @@ test('no tags - default tag', () => {
9611003 } ,
9621004 } ;
9631005
964- const parser = new N8NPropertiesBuilder ( { paths} ) ;
1006+ const parser = new N8NPropertiesBuilder ( { paths} , {
1007+ operation : new CustomOperationParser ( )
1008+ } ) ;
9651009 const result = parser . build ( )
9661010
9671011 expect ( result ) . toEqual (
0 commit comments