(
spec: OpenAPIObject,
options: OpenApi2SchemaOptions = {},
)
| 51 | } |
| 52 | |
| 53 | export async function openapi2schema( |
| 54 | spec: OpenAPIObject, |
| 55 | options: OpenApi2SchemaOptions = {}, |
| 56 | ): Promise<ConvertedJsonSchema> { |
| 57 | logger.debug('Converting OpenAPI3 to JSON Schema') |
| 58 | |
| 59 | const schemaOptions: SchemaOptions = { |
| 60 | dateToDateTime: !!options.dateToDateTime, |
| 61 | supportPatternProperties: !!options.supportPatternProperties, |
| 62 | |
| 63 | // keep deprecated value, so we can detect and remove deprecated propertise |
| 64 | keepNotSupported: ['deprecated'], |
| 65 | } |
| 66 | |
| 67 | // $RefParser.dereference takes the file path of an OpenAPI3 schema and returns an object with all the $ref pointers |
| 68 | // replaced with its value |
| 69 | const dereferenced: any = await $RefParser.dereference(spec) |
| 70 | if (!dereferenced.paths) { |
| 71 | throw new Error('no paths defined in the specification file') |
| 72 | } |
| 73 | |
| 74 | const result = buildPaths(dereferenced.paths, options, schemaOptions) |
| 75 | logger.debug('OpenAPI3 successfully converted to JSON Schema') |
| 76 | return result |
| 77 | } |
| 78 | |
| 79 | function buildPaths( |
| 80 | paths: PathsObject, |
no test coverage detected