@@ -4,6 +4,7 @@ import { File } from "formdata-node";
44import { OpenAPI , OpenAPIV2 , OpenAPIV3 , OpenAPIV3_1 } from "openapi-types" ;
55import swaggerClient from "swagger-client" ;
66import { ActionCategory } from "openblocks-sdk/dataSource" ;
7+ import SwaggerClient from "swagger-client" ;
78
89export const MediaTypeOctetStream = "application/octet-stream" ;
910export const MediaTypeUrlEncoded = "application/x-www-form-urlencoded" ;
@@ -186,7 +187,7 @@ export function findOas3FilePropertiesFromSchema(
186187 } ) ;
187188}
188189
189- export function findOperation ( id : string , spec : OpenAPI . Document ) {
190+ export function findOperation ( id : string , spec : OpenAPI . Document , specId : string = "" ) {
190191 if ( ! spec . paths ) {
191192 return null ;
192193 }
@@ -197,8 +198,11 @@ export function findOperation(id: string, spec: OpenAPI.Document) {
197198 }
198199 for ( const method of Object . keys ( pathObj ) ) {
199200 const operation : OpenAPI . Operation = ( pathObj as any ) [ method ] ;
200- if ( swaggerClient . helpers . opId ( operation , path , method ) === id ) {
201- return operation ;
201+ if ( getOperationId ( operation , path , method , specId ) === id ) {
202+ return {
203+ operation,
204+ realOperationId : getOperationId ( operation , path , method ) ,
205+ } ;
202206 }
203207 }
204208 }
@@ -345,13 +349,13 @@ export function getSchemaType(
345349 return schema . type ;
346350}
347351
348- export function getSchemaExample (
349- schema ?:
350- | OpenAPIV2 . SchemaObject
351- | OpenAPIV2 . ReferenceObject
352- | OpenAPIV3 . SchemaObject
353- | OpenAPIV3 . ReferenceObject
354- ) : any {
352+ type SchemaObject =
353+ | OpenAPIV2 . SchemaObject
354+ | OpenAPIV2 . ReferenceObject
355+ | OpenAPIV3 . SchemaObject
356+ | OpenAPIV3 . ReferenceObject ;
357+
358+ export function getSchemaExample ( schema ?: SchemaObject ) : any {
355359 if ( ! schema || isOas3RefObject ( schema ) || isSwagger2RefObject ( schema ) ) {
356360 return ;
357361 }
@@ -376,6 +380,22 @@ export function getSchemaExample(
376380 ) ;
377381 return _ . isNil ( itemExample ) ? [ ] : [ itemExample ] ;
378382 }
383+ if ( schema . oneOf && schema . oneOf . length > 0 ) {
384+ const firstSchema = schema . oneOf [ 0 ] ;
385+ return getSchemaExample ( firstSchema as SchemaObject ) ;
386+ }
387+ if ( schema . anyOf && schema . anyOf . length > 0 ) {
388+ const firstSchema = schema . anyOf [ 0 ] ;
389+ return getSchemaExample ( firstSchema as SchemaObject ) ;
390+ }
391+ if ( schema . allOf && schema . allOf . length > 0 ) {
392+ return ( schema . allOf as SchemaObject [ ] ) . reduce ( ( a : any , b : SchemaObject ) => {
393+ return {
394+ ...a ,
395+ ...getSchemaExample ( b ) ,
396+ } ;
397+ } , { } ) ;
398+ }
379399 let ret : any ;
380400 if ( schema . properties ) {
381401 Object . entries ( schema . properties ) . forEach ( ( [ name , def ] ) => {
@@ -419,3 +439,16 @@ export function appendCategories(a: ActionCategory[], b: ActionCategory[]) {
419439 a . push ( i ) ;
420440 } ) ;
421441}
442+
443+ export function getOperationId (
444+ operation : OpenAPI . Operation ,
445+ path : string ,
446+ method : string ,
447+ specId : string = ""
448+ ) {
449+ const operationId : string = SwaggerClient . helpers . opId ( operation , path , method ) ;
450+ if ( ! operationId ) {
451+ return "" ;
452+ }
453+ return operationId + specId ;
454+ }
0 commit comments