UNPKG

openapi-diff

Version:

A CLI tool to identify differences between Swagger/OpenAPI specs.

30 lines (29 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseOpenApi3BodyObjectJsonSchema = void 0; const to_diff_ready_openapi3_schema_1 = require("./to-diff-ready-openapi3-schema"); const toParsedJsonSchema = (bodyObjectSchema, pathBuilder, spec) => { return { originalValue: { originalPath: pathBuilder.build(), value: bodyObjectSchema }, schema: (0, to_diff_ready_openapi3_schema_1.toDiffReadyOpenApi3Schema)(bodyObjectSchema, spec) }; }; const getSchemaFromBodyObject = (bodyObject) => { return bodyObject.content && bodyObject.content['application/json'] ? bodyObject.content['application/json'].schema : undefined; }; const getPathForBodyObject = (pathBuilder) => { return pathBuilder.withChild('content').withChild('application/json').withChild('schema'); }; const parseOpenApi3BodyObjectJsonSchema = (bodyObject, pathBuilder, spec) => { const bodyObjectSchema = getSchemaFromBodyObject(bodyObject); const bodyObjectPath = getPathForBodyObject(pathBuilder); return bodyObjectSchema ? toParsedJsonSchema(bodyObjectSchema, bodyObjectPath, spec) : undefined; }; exports.parseOpenApi3BodyObjectJsonSchema = parseOpenApi3BodyObjectJsonSchema;