UNPKG

openapi-diff

Version:

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

28 lines (27 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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: 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'); }; exports.parseOpenApi3BodyObjectJsonSchema = (bodyObject, pathBuilder, spec) => { const bodyObjectSchema = getSchemaFromBodyObject(bodyObject); const bodyObjectPath = getPathForBodyObject(pathBuilder); return bodyObjectSchema ? toParsedJsonSchema(bodyObjectSchema, bodyObjectPath, spec) : undefined; };