MCPcopy Create free account
hub / github.com/chainjet/platform / openapi2schema

Function openapi2schema

libs/definitions/src/schema/utils/openapi2schema.ts:53–77  ·  view source on GitHub ↗
(
  spec: OpenAPIObject,
  options: OpenApi2SchemaOptions = {},
)

Source from the content-addressed store, hash-verified

51}
52
53export 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
79function buildPaths(
80 paths: PathsObject,

Callers 1

installIntegrationMethod · 0.90

Calls 1

buildPathsFunction · 0.85

Tested by

no test coverage detected