( spec: OpenAPISpec, generator: ReturnType<typeof JsonSchemaGenerator.make>, resolveRef: (ref: string) => unknown, format: OpenApiGeneratorFormat, emitWarning: WarningEmitter, multipartSchemaRefs: HttpApiMultipartSchemaRefs | undefined )
| 209 | } |
| 210 | |
| 211 | const parseOpenApi = ( |
| 212 | spec: OpenAPISpec, |
| 213 | generator: ReturnType<typeof JsonSchemaGenerator.make>, |
| 214 | resolveRef: (ref: string) => unknown, |
| 215 | format: OpenApiGeneratorFormat, |
| 216 | emitWarning: WarningEmitter, |
| 217 | multipartSchemaRefs: HttpApiMultipartSchemaRefs | undefined |
| 218 | ): ParsedOperation.ParsedOpenApi => { |
| 219 | const operations: Array<ParsedOperation.ParsedOperation> = [] |
| 220 | const reservedSchemaNames = new Set<string>(Object.keys(spec.components?.schemas ?? {})) |
| 221 | const isHttpApi = format === "httpapi" |
| 222 | const securitySchemes = isHttpApi ? parseSecuritySchemes(spec, resolveRef) : [] |
| 223 | |
| 224 | const addSchema = ( |
| 225 | baseName: string, |
| 226 | schema: JsonSchema.JsonSchema, |
| 227 | operation: ParsedOperation.ParsedOperation |
| 228 | ): string => { |
| 229 | let candidate = baseName |
| 230 | let index = 2 |
| 231 | while (reservedSchemaNames.has(candidate)) { |
| 232 | candidate = `${baseName}${index}` |
| 233 | index += 1 |
| 234 | } |
| 235 | if (candidate !== baseName) { |
| 236 | warnForOperation(emitWarning, operation, { |
| 237 | code: "naming-collision", |
| 238 | message: `Schema name "${baseName}" collided with an existing name and was renamed to "${candidate}".` |
| 239 | }) |
| 240 | } |
| 241 | reservedSchemaNames.add(candidate) |
| 242 | return generator.addSchema(candidate, schema) |
| 243 | } |
| 244 | |
| 245 | for (const [path, methods] of Object.entries(spec.paths)) { |
| 246 | for (const method of methodNames) { |
| 247 | const operation = methods[method] |
| 248 | |
| 249 | if (Predicate.isUndefined(operation)) { |
| 250 | continue |
| 251 | } |
| 252 | |
| 253 | const id = operation.operationId |
| 254 | ? Utils.camelize(operation.operationId) |
| 255 | : `${method.toUpperCase()}${path}` |
| 256 | |
| 257 | const description = Utils.nonEmptyString(operation.description) ?? Utils.nonEmptyString(operation.summary) |
| 258 | |
| 259 | const { pathIds, pathTemplate } = processPath(path) |
| 260 | |
| 261 | const op = ParsedOperation.makeDeepMutable({ |
| 262 | id, |
| 263 | method, |
| 264 | description, |
| 265 | pathIds, |
| 266 | pathTemplate |
| 267 | }) |
| 268 | op.path = path |
no test coverage detected