Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mintlify/validation

Package Overview
Dependencies
Maintainers
5
Versions
233
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mintlify/validation - npm Package Compare versions

Comparing version 0.1.92 to 0.1.93

dist/openapi/generateExampleFromSchema.d.ts

8

dist/openapi/convertOpenApi.d.ts
import { OpenAPIV3_1 } from 'openapi-types';
import type { BodySchema, DataSchemaArray, Endpoint, HttpMethod, ResponseSchema } from './types/endpoint.js';
import type { ContentSchema, DataSchemaArray, Endpoint, ExampleSchema, HttpMethod, ResponseSchema } from './types/endpoint.js';
export declare const generateMessage: (path: string[], messages?: string[]) => string;

@@ -13,7 +13,5 @@ export declare class InvalidSchemaError extends Error {

}
export declare const convertBody: (path: string[], body: OpenAPIV3_1.RequestBodyObject | undefined) => BodySchema;
export declare const convertContent: (path: string[], content: Record<string, OpenAPIV3_1.MediaTypeObject> | undefined, required?: boolean) => Record<string, ContentSchema>;
export declare const convertExamples: (examples: Record<string, OpenAPIV3_1.ExampleObject> | undefined, example: unknown | undefined, schemaArray: DataSchemaArray) => Record<string, ExampleSchema>;
export declare const convertResponses: (path: string[], responses: OpenAPIV3_1.ResponsesObject) => ResponseSchema;
export declare const convertResponse: (path: string[], response: OpenAPIV3_1.ResponseObject) => {
[contentType: string]: DataSchemaArray;
};
export declare const convertOpenAPIV3_1ToEndpoint: (spec: OpenAPIV3_1.Document, path: string, method: HttpMethod) => Endpoint | undefined;

@@ -5,2 +5,3 @@ import { convertParameters } from './convertParameters.js';

import { convertServers } from './convertServers.js';
import { generateExampleFromSchema } from './generateExampleFromSchema.js';
export const generateMessage = (path, messages = []) => {

@@ -33,31 +34,38 @@ const pathString = path

}
export const convertBody = (path, body) => {
if (body === undefined) {
export const convertContent = (path, content, required) => {
if (content === undefined) {
return {};
}
const newEntries = Object.entries(body.content).map(([contentType, mediaObject]) => {
return [
contentType,
convertSchema([...path, contentType, 'schema'], mediaObject.schema, body.required),
];
const newEntries = Object.entries(content).map(([contentType, mediaObject]) => {
const schemaArray = convertSchema([...path, contentType, 'schema'], mediaObject.schema, required);
const examples = convertExamples(mediaObject.examples, mediaObject.example, schemaArray);
return [contentType, { schemaArray, examples }];
});
return Object.fromEntries(newEntries);
};
export const convertExamples = (examples, example, schemaArray) => {
if (examples && Object.values(examples).some(({ value }) => value !== undefined)) {
return Object.fromEntries(Object.entries(examples)
.filter(([_, { value }]) => value !== undefined)
.map(([key, example]) => [
key,
{
summary: example.summary,
description: example.description,
value: example.value,
},
]));
}
if (example !== undefined) {
return { example: { value: example } };
}
return { example: { value: generateExampleFromSchema(schemaArray[0]) } };
};
export const convertResponses = (path, responses) => {
const newEntries = Object.entries(responses).map(([statusCode, response]) => [
statusCode,
convertResponse([...path, statusCode], response),
convertContent([...path, statusCode, 'content'], response.content),
]);
return Object.fromEntries(newEntries);
};
export const convertResponse = (path, response) => {
if (response.content === undefined) {
return {};
}
const newEntries = Object.entries(response.content).map(([contentType, mediaType]) => [
contentType,
convertSchema([...path, 'content', contentType, 'schema'], mediaType.schema),
]);
return Object.fromEntries(newEntries);
};
export const convertOpenAPIV3_1ToEndpoint = (spec, path, method) => {

@@ -96,3 +104,3 @@ var _a, _b, _c, _d, _e;

const requestBody = operationObject.requestBody;
const body = convertBody(['#', 'paths', path, method, 'requestBody'], requestBody);
const body = convertContent(['#', 'paths', path, method, 'requestBody', 'content'], requestBody === null || requestBody === void 0 ? void 0 : requestBody.content, requestBody === null || requestBody === void 0 ? void 0 : requestBody.required);
const deprecated = !!operationObject.deprecated;

@@ -99,0 +107,0 @@ const response = convertResponses(['#', 'paths', path, method, 'responses'], operationObject.responses);

@@ -165,3 +165,3 @@ import lcm from 'lcm';

export const combineTopLevelSchemas = (path, schema1, schema2) => {
var _a, _b;
var _a, _b, _c, _d;
let type1 = schema1.type;

@@ -224,13 +224,15 @@ let type2 = schema2.type;

(schema2.minimum === combinedSchema.minimum ? schema2.exclusiveMinimum : undefined);
if (typeof schema1.example === 'object' &&
typeof schema2.example === 'object' &&
(schema1.example != null || schema2.example != null)) {
combinedSchema.example = Object.assign(Object.assign({}, schema1.example), schema2.example);
// don't use coalesce operator, since null is a valid example
const example1 = ((_a = schema1.examples) === null || _a === void 0 ? void 0 : _a[0]) !== undefined ? schema1.examples[0] : schema1.example;
const example2 = ((_b = schema2.examples) === null || _b === void 0 ? void 0 : _b[0]) !== undefined ? schema2.examples[0] : schema2.example;
if (example1 && example2 && typeof example1 === 'object' && typeof example2 === 'object') {
combinedSchema.example = Object.assign(Object.assign({}, example1), example2);
}
else {
combinedSchema.example = takeLast(schema1, schema2, 'example');
// don't use coalesce operator, since null is a valid example
combinedSchema.example = example2 !== undefined ? example2 : example1;
}
const type = type1 !== null && type1 !== void 0 ? type1 : type2;
if (type === 'array') {
return Object.assign({ type, items: combineReducedSchemas([...path, 'items'], (_a = schema1.items) !== null && _a !== void 0 ? _a : {}, (_b = schema2.items) !== null && _b !== void 0 ? _b : {}) }, combinedSchema);
return Object.assign({ type, items: combineReducedSchemas([...path, 'items'], (_c = schema1.items) !== null && _c !== void 0 ? _c : {}, (_d = schema2.items) !== null && _d !== void 0 ? _d : {}) }, combinedSchema);
}

@@ -279,2 +281,9 @@ if (schema1.properties && schema2.properties) {

};
const copyExampleIfDefined = (source, destination) => {
var _a;
const example = ((_a = source.examples) === null || _a === void 0 ? void 0 : _a[0]) !== undefined ? source.examples[0] : source.example;
if (example !== undefined) {
destination.example = example;
}
};
const takeLast = (schema1, schema2, key) => {

@@ -317,3 +326,3 @@ var _a;

copyKeyIfDefined('default', schema, booleanProps);
copyKeyIfDefined('example', schema, booleanProps);
copyExampleIfDefined(schema, booleanProps);
return Object.assign({ type: schema.type }, booleanProps);

@@ -325,3 +334,3 @@ case 'number':

copyKeyIfDefined('default', schema, numberEnumProps);
copyKeyIfDefined('example', schema, numberEnumProps);
copyExampleIfDefined(schema, numberEnumProps);
return Object.assign({ type: schema.type === 'number' ? 'enum<number>' : 'enum<integer>', enum: schema.enum }, numberEnumProps);

@@ -336,3 +345,3 @@ }

copyKeyIfDefined('default', schema, numberProps);
copyKeyIfDefined('example', schema, numberProps);
copyExampleIfDefined(schema, numberProps);
return Object.assign({ type: schema.type }, numberProps);

@@ -343,3 +352,3 @@ case 'string':

copyKeyIfDefined('default', schema, stringEnumProps);
copyKeyIfDefined('example', schema, stringEnumProps);
copyExampleIfDefined(schema, stringEnumProps);
return Object.assign({ type: 'enum<string>', enum: schema.enum }, stringEnumProps);

@@ -353,3 +362,3 @@ }

copyKeyIfDefined('default', schema, stringProps);
copyKeyIfDefined('example', schema, stringProps);
copyExampleIfDefined(schema, stringProps);
return Object.assign({ type: schema.type }, stringProps);

@@ -365,3 +374,3 @@ case 'array':

copyKeyIfDefined('default', schema, arrayProps);
copyKeyIfDefined('example', schema, arrayProps);
copyExampleIfDefined(schema, arrayProps);
return Object.assign({ type: schema.type, items }, arrayProps);

@@ -378,3 +387,3 @@ case 'object':

copyKeyIfDefined('default', schema, objectProperties);
copyKeyIfDefined('example', schema, objectProperties);
copyExampleIfDefined(schema, objectProperties);
return Object.assign({ type: schema.type, properties }, objectProperties);

@@ -384,3 +393,3 @@ case 'null':

copyKeyIfDefined('default', schema, nullProps);
copyKeyIfDefined('example', schema, nullProps);
copyExampleIfDefined(schema, nullProps);
return Object.assign({ type: schema.type }, nullProps);

@@ -387,0 +396,0 @@ default:

@@ -36,4 +36,15 @@ export type Endpoint = {

export type BodySchema = {
[contentType: string]: DataSchemaArray;
[contentType: string]: ContentSchema;
};
export type ContentSchema = {
schemaArray: DataSchemaArray;
examples: {
[title: string]: ExampleSchema;
};
};
export type ExampleSchema = {
summary?: string;
description?: string;
value: unknown;
};
export type ParameterSchema = {

@@ -40,0 +51,0 @@ schema: DataSchemaArray;

{
"name": "@mintlify/validation",
"version": "0.1.92",
"version": "0.1.93",
"description": "Validates mint.json files",

@@ -73,3 +73,3 @@ "author": "Mintlify, Inc.",

},
"gitHead": "90a18ff454f51ee80a2e3fe78b45bb8dcedbcd7f"
"gitHead": "e0c3120762e807b78eadac7fa884c8569fff32d5"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc