(api: OpenAPIV3.Document)
| 171 | } |
| 172 | |
| 173 | private buildOperationsMap(api: OpenAPIV3.Document) { |
| 174 | const { components, paths } = api; |
| 175 | |
| 176 | Object.entries(paths).forEach(([route, path]) => { |
| 177 | if (path === undefined) { |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | const { parameters: pathParameters, ...pathOperations } = path; |
| 182 | let parameters = pathParameters ?? []; |
| 183 | |
| 184 | Object.entries(pathOperations).forEach(([method, operation]) => { |
| 185 | const { |
| 186 | summary, |
| 187 | description, |
| 188 | operationId, |
| 189 | requestBody, |
| 190 | parameters: innerParams, |
| 191 | } = operation as OpenAPIV3.OperationObject; |
| 192 | |
| 193 | parameters = innerParams ? [...parameters, ...innerParams] : parameters; |
| 194 | |
| 195 | const partialOperation: Partial<Oas.Operation> = { |
| 196 | name: summary, |
| 197 | path: route, |
| 198 | method: method as OpenAPIV3.HttpMethods, |
| 199 | description, |
| 200 | }; |
| 201 | |
| 202 | if (requestBody !== undefined) { |
| 203 | const { content } = requestBody as OpenAPIV3.RequestBodyObject; |
| 204 | const mediaType = content['application/json']; |
| 205 | |
| 206 | const body = |
| 207 | mediaType.schema === undefined |
| 208 | ? ({} as Oas.Body) |
| 209 | : this.parseRequestBody(mediaType.schema, components!); |
| 210 | |
| 211 | partialOperation.requestBody = body; |
| 212 | } |
| 213 | |
| 214 | if (parameters && parameters !== null && parameters.length > 0) { |
| 215 | const { pathParameter, queryParameter } = this.parseParameters( |
| 216 | parameters as OpenAPIV3.ParameterObject[], |
| 217 | ); |
| 218 | |
| 219 | // partialOperation.header = header; |
| 220 | partialOperation.pathParameter = pathParameter; |
| 221 | partialOperation.queryParameter = queryParameter; |
| 222 | } |
| 223 | |
| 224 | this.operations[operationId!] = partialOperation; |
| 225 | }); |
| 226 | }); |
| 227 | } |
| 228 | |
| 229 | getOperationById(operationId: string): Partial<Oas.Operation> | undefined { |
| 230 | return this.operations[operationId]; |
no test coverage detected