11/* eslint-disable security/detect-object-injection */
2- import { OpenAPIV2 , OpenAPIV3 , OpenAPIV3_1 } from " openapi-types" ;
3- import { ProcessedHeadersData } from " ../../../generators/typescript/headers" ;
4- import { pascalCase } from " ../../../generators/typescript/utils" ;
2+ import { OpenAPIV2 , OpenAPIV3 , OpenAPIV3_1 } from ' openapi-types' ;
3+ import { ProcessedHeadersData } from ' ../../../generators/typescript/headers' ;
4+ import { pascalCase } from ' ../../../generators/typescript/utils' ;
55
66// Helper function to convert OpenAPI parameter schema to JSON Schema
77function convertParameterSchemaToJsonSchema ( parameter : any ) : any {
88 let schema : any ;
9-
9+
1010 if ( parameter . schema ) {
1111 // OpenAPI 3.x format
12- schema = { ...parameter . schema } ;
12+ schema = { ...parameter . schema } ;
1313 } else if ( parameter . type ) {
1414 // OpenAPI 2.x format
1515 schema = {
1616 type : parameter . type ,
17- ...( parameter . format && { format : parameter . format } ) ,
18- ...( parameter . enum && { enum : parameter . enum } ) ,
19- ...( parameter . minimum !== undefined && { minimum : parameter . minimum } ) ,
20- ...( parameter . maximum !== undefined && { maximum : parameter . maximum } ) ,
21- ...( parameter . minLength !== undefined && { minLength : parameter . minLength } ) ,
22- ...( parameter . maxLength !== undefined && { maxLength : parameter . maxLength } ) ,
23- ...( parameter . pattern && { pattern : parameter . pattern } ) ,
17+ ...( parameter . format && { format : parameter . format } ) ,
18+ ...( parameter . enum && { enum : parameter . enum } ) ,
19+ ...( parameter . minimum !== undefined && { minimum : parameter . minimum } ) ,
20+ ...( parameter . maximum !== undefined && { maximum : parameter . maximum } ) ,
21+ ...( parameter . minLength !== undefined && {
22+ minLength : parameter . minLength
23+ } ) ,
24+ ...( parameter . maxLength !== undefined && {
25+ maxLength : parameter . maxLength
26+ } ) ,
27+ ...( parameter . pattern && { pattern : parameter . pattern } )
2428 } ;
2529 } else {
2630 // Fallback to string type
27- schema = { type : 'string' } ;
31+ schema = { type : 'string' } ;
2832 }
2933
3034 return schema ;
3135}
3236
3337// Extract header parameters from OpenAPI operations
34- function extractHeadersFromOperations ( paths : OpenAPIV3 . PathsObject | OpenAPIV2 . PathsObject | OpenAPIV3_1 . PathsObject ) : Record < string , any [ ] > {
38+ function extractHeadersFromOperations (
39+ paths : OpenAPIV3 . PathsObject | OpenAPIV2 . PathsObject | OpenAPIV3_1 . PathsObject
40+ ) : Record < string , any [ ] > {
3541 const operationHeaders : Record < string , any [ ] > = { } ;
3642
3743 for ( const [ pathKey , pathItem ] of Object . entries ( paths ) ) {
3844 for ( const [ method , operation ] of Object . entries ( pathItem ) ) {
39- const operationObj = operation as OpenAPIV3 . OperationObject | OpenAPIV2 . OperationObject | OpenAPIV3_1 . OperationObject ;
45+ const operationObj = operation as
46+ | OpenAPIV3 . OperationObject
47+ | OpenAPIV2 . OperationObject
48+ | OpenAPIV3_1 . OperationObject ;
4049 // Collect header parameters from operation and path-level
4150 const allParameters = operationObj . parameters ?? [ ] ;
4251
@@ -45,7 +54,9 @@ function extractHeadersFromOperations(paths: OpenAPIV3.PathsObject | OpenAPIV2.P
4554 } ) ;
4655
4756 if ( allParameters . length > 0 ) {
48- const operationId = operationObj . operationId ?? `${ method } ${ pathKey . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) } ` ;
57+ const operationId =
58+ operationObj . operationId ??
59+ `${ method } ${ pathKey . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) } ` ;
4960 operationHeaders [ operationId ] = headerParams ;
5061 }
5162 }
@@ -56,15 +67,24 @@ function extractHeadersFromOperations(paths: OpenAPIV3.PathsObject | OpenAPIV2.P
5667
5768// OpenAPI input processor
5869export function processOpenAPIHeaders (
59- openapiDocument : OpenAPIV3 . Document | OpenAPIV2 . Document | OpenAPIV3_1 . Document
70+ openapiDocument :
71+ | OpenAPIV3 . Document
72+ | OpenAPIV2 . Document
73+ | OpenAPIV3_1 . Document
6074) : ProcessedHeadersData {
61- const channelHeaders : Record < string , {
62- schema : any ;
63- schemaId : string ;
64- } | undefined > = { } ;
75+ const channelHeaders : Record <
76+ string ,
77+ | {
78+ schema : any ;
79+ schemaId : string ;
80+ }
81+ | undefined
82+ > = { } ;
6583
6684 // Extract header parameters from all operations
67- const operationHeaders = extractHeadersFromOperations ( openapiDocument . paths ?? { } ) ;
85+ const operationHeaders = extractHeadersFromOperations (
86+ openapiDocument . paths ?? { }
87+ ) ;
6888
6989 // Process each operation that has header parameters
7090 for ( const [ operationId , headerParams ] of Object . entries ( operationHeaders ) ) {
@@ -80,7 +100,7 @@ export function processOpenAPIHeaders(
80100 for ( const param of headerParams ) {
81101 const paramName = param . name ;
82102 const paramSchema = convertParameterSchemaToJsonSchema ( param ) ;
83-
103+
84104 // Add description if available
85105 if ( param . description ) {
86106 paramSchema . description = param . description ;
@@ -114,5 +134,5 @@ export function processOpenAPIHeaders(
114134 } ;
115135 }
116136
117- return { channelHeaders } ;
137+ return { channelHeaders} ;
118138}
0 commit comments