@@ -107,10 +107,7 @@ function convertOpenAPIParamsToJSONSchema(
107
107
if ( param . schema ) {
108
108
schema = spec . getSchema ( param . schema ) ;
109
109
// eslint-disable-next-line no-param-reassign
110
- jsonSchema . properties [ param . name ] = convertOpenAPISchemaToJSONSchema (
111
- schema ,
112
- spec
113
- ) ;
110
+ jsonSchema . properties [ param . name ] = convertOpenAPISchemaToJSONSchema ( schema ) ;
114
111
} else if ( param . content ) {
115
112
const mediaTypeSchema = Object . values ( param . content ) [ 0 ] . schema ;
116
113
if ( mediaTypeSchema ) {
@@ -123,10 +120,7 @@ function convertOpenAPIParamsToJSONSchema(
123
120
schema . description = param . description ?? "" ;
124
121
}
125
122
// eslint-disable-next-line no-param-reassign
126
- jsonSchema . properties [ param . name ] = convertOpenAPISchemaToJSONSchema (
127
- schema ,
128
- spec
129
- ) ;
123
+ jsonSchema . properties [ param . name ] = convertOpenAPISchemaToJSONSchema ( schema ) ;
130
124
} else {
131
125
return jsonSchema ;
132
126
}
@@ -152,41 +146,9 @@ function convertOpenAPIParamsToJSONSchema(
152
146
* @returns The JSON schema representation of the OpenAPI schema.
153
147
*/
154
148
function convertOpenAPISchemaToJSONSchema (
155
- schema : OpenAPIV3_1 . SchemaObject ,
156
- spec : OpenAPISpec
157
- ) {
158
- if ( schema . type !== "object" && schema . type !== "array" ) {
159
- return {
160
- type : schema . type ?? "string" ,
161
- } as JsonSchema7Type ;
162
- }
163
- return Object . keys ( schema . properties ?? { } ) . reduce (
164
- ( jsonSchema : JsonSchema7ObjectType , propertyName ) => {
165
- if ( ! schema . properties ) {
166
- return jsonSchema ;
167
- }
168
- const openAPIProperty = spec . getSchema ( schema . properties [ propertyName ] ) ;
169
- if ( openAPIProperty . type === undefined ) {
170
- return jsonSchema ;
171
- }
172
- // eslint-disable-next-line no-param-reassign
173
- jsonSchema . properties [ propertyName ] = {
174
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
- type : openAPIProperty . type as any ,
176
- description : openAPIProperty . description ,
177
- } ;
178
- if ( openAPIProperty . required && jsonSchema . required !== undefined ) {
179
- jsonSchema . required . push ( propertyName ) ;
180
- }
181
- return jsonSchema ;
182
- } ,
183
- {
184
- type : "object" ,
185
- properties : { } ,
186
- required : [ ] ,
187
- additionalProperties : { } ,
188
- }
189
- ) ;
149
+ schema : OpenAPIV3_1 . SchemaObject
150
+ ) : JsonSchema7Type {
151
+ return schema ;
190
152
}
191
153
192
154
/**
@@ -258,10 +220,7 @@ function convertOpenAPISpecToOpenAIFunctions(spec: OpenAPISpec): {
258
220
) ) {
259
221
if ( mediaTypeObject . schema !== undefined ) {
260
222
const schema = spec . getSchema ( mediaTypeObject . schema ) ;
261
- requestBodySchemas [ mediaType ] = convertOpenAPISchemaToJSONSchema (
262
- schema ,
263
- spec
264
- ) as JsonSchema7ObjectType ;
223
+ requestBodySchemas [ mediaType ] = convertOpenAPISchemaToJSONSchema ( schema ) as JsonSchema7ObjectType ;
265
224
}
266
225
}
267
226
const mediaTypes = Object . keys ( requestBodySchemas ) ;
0 commit comments