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

@samchon/openapi

Package Overview
Dependencies
Maintainers
1
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@samchon/openapi - npm Package Compare versions

Comparing version 2.0.0-dev.20241121-3 to 2.0.0-dev.20241121-4

lib/utils/OpenApiContraintShifter.d.ts

176

lib/converters/ChatGptConverter.js

@@ -40,14 +40,6 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatGptConverter = void 0;
var ChatGptTypeChecker_1 = require("../utils/ChatGptTypeChecker");
var OpenApiContraintShifter_1 = require("../utils/OpenApiContraintShifter");
var OpenApiTypeChecker_1 = require("../utils/OpenApiTypeChecker");

@@ -77,3 +69,3 @@ var ChatGptConverter;

var visit = function (input) {
var _a, _b;
var _a;
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(input)) {

@@ -94,6 +86,3 @@ input.oneOf.forEach(visit);

var out = function () {
return union.push({
schema: __assign(__assign({}, input), { $ref: "#/$defs/".concat(key_1), title: undefined, description: undefined }),
tags: [],
});
return union.push(__assign(__assign({}, input), { $ref: "#/$defs/".concat(key_1), title: undefined, description: undefined }));
};

@@ -110,6 +99,3 @@ if (props.$defs[key_1] !== undefined)

if (converted === null)
return union.push({
schema: null,
tags: [],
});
return union.push(null);
converted.description = OpenApiTypeChecker_1.OpenApiTypeChecker.writeReferenceDescription({

@@ -127,13 +113,9 @@ components: props.components,

visit(target);
if (length_1 === union.length - 1 &&
union[union.length - 1].schema !== null)
union[union.length - 1] = {
tags: union[union.length - 1].tags,
schema: __assign(__assign({}, union[union.length - 1].schema), { description: OpenApiTypeChecker_1.OpenApiTypeChecker.writeReferenceDescription({
components: props.components,
$ref: input.$ref,
description: (_b = union[union.length - 1].schema) === null || _b === void 0 ? void 0 : _b.description,
escape: true,
}) }),
};
if (length_1 === union.length - 1 && union[union.length - 1] !== null)
union[union.length - 1] = __assign(__assign({}, union[union.length - 1]), { description: OpenApiTypeChecker_1.OpenApiTypeChecker.writeReferenceDescription({
components: props.components,
$ref: input.$ref,
description: union[union.length - 1].description,
escape: true,
}) });
else

@@ -165,6 +147,3 @@ attribute.description =

if (Object.values(properties).some(function (v) { return v === null; }))
return union.push({
schema: null,
tags: [],
});
return union.push(null);
var additionalProperties = input.additionalProperties === undefined

@@ -182,10 +161,4 @@ ? false

if (additionalProperties === null)
return union.push({
schema: null,
tags: [],
});
return union.push({
schema: __assign(__assign({}, input), { properties: properties, additionalProperties: additionalProperties, required: Object.keys(properties) }),
tags: [],
});
return union.push(null);
return union.push(__assign(__assign({}, input), { properties: properties, additionalProperties: additionalProperties, required: Object.keys(properties) }));
}

@@ -200,56 +173,28 @@ else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isArray(input)) {

if (items === null)
return union.push({
schema: null,
tags: props.options.constraint ? [] : getArrayTags(input),
});
return union.push({
schema: __assign(__assign(__assign({}, input), { items: items }), (props.options.constraint
? {}
: {
maxItems: undefined,
minItems: undefined,
uniqueItems: undefined,
})),
tags: props.options.constraint ? [] : getArrayTags(input),
});
return union.push(null);
return union.push((props.options.constraint
? function (x) { return x; }
: function (x) {
return OpenApiContraintShifter_1.OpenApiContraintShifter.shiftArray(x);
})(__assign(__assign({}, input), { items: items })));
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isString(input))
return union.push({
schema: __assign(__assign({}, input), (props.options.constraint
? {}
: {
contentMediaType: undefined,
minLength: undefined,
maxLength: undefined,
format: undefined,
pattern: undefined,
})),
tags: props.options.constraint ? [] : getStringTags(input),
});
return union.push((props.options.constraint
? function (x) { return x; }
: function (x) {
return OpenApiContraintShifter_1.OpenApiContraintShifter.shiftString(x);
})(__assign({}, input)));
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isNumber(input) ||
OpenApiTypeChecker_1.OpenApiTypeChecker.isInteger(input))
return union.push({
schema: __assign(__assign({}, input), (props.options.constraint
? {}
: {
maximum: undefined,
minimum: undefined,
exclusiveMaximum: undefined,
exclusiveMinimum: undefined,
multipleOf: undefined,
})),
tags: props.options.constraint ? [] : getNumericTags(input),
});
return union.push((props.options.constraint
? function (x) { return x; }
: function (x) {
return OpenApiContraintShifter_1.OpenApiContraintShifter.shiftNumeric(x);
})(__assign({}, input)));
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(input))
return 0;
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(input))
return union.push({
schema: null,
tags: [],
});
return union.push(null);
else
return union.push({
schema: __assign({}, input),
tags: [],
});
return union.push(__assign({}, input));
};

@@ -260,19 +205,14 @@ var visitConstant = function (input) {

var _a;
var _b;
var matched = union.find(function (u) {
var _a;
return ((_a = u.schema) === null || _a === void 0 ? void 0 : _a.type) ===
return (u === null || u === void 0 ? void 0 : u.type) ===
typeof value;
});
if (matched !== undefined) {
(_a = (_b = matched.schema).enum) !== null && _a !== void 0 ? _a : (_b.enum = []);
matched.schema.enum.push(value);
(_a = matched.enum) !== null && _a !== void 0 ? _a : (matched.enum = []);
matched.enum.push(value);
}
else
union.push({
schema: {
type: typeof value,
enum: [value],
},
tags: [],
type: typeof value,
enum: [value],
});

@@ -302,17 +242,8 @@ };

else if (union.length === 1)
return __assign(__assign(__assign({}, attribute), union[0].schema), { description: ChatGptTypeChecker_1.ChatGptTypeChecker.isReference(union[0].schema)
return __assign(__assign(__assign({}, attribute), union[0]), { description: ChatGptTypeChecker_1.ChatGptTypeChecker.isReference(union[0])
? undefined
: writeTagWithDescription({
description: attribute.description,
tags: union[0].tags,
}) });
return __assign(__assign({}, attribute), { anyOf: union.map(function (u) {
var _a;
return (__assign(__assign({}, u.schema), { description: ChatGptTypeChecker_1.ChatGptTypeChecker.isReference(u.schema)
? undefined
: writeTagWithDescription({
description: (_a = u.schema) === null || _a === void 0 ? void 0 : _a.description,
tags: u.tags,
}) }));
}) });
: union[0].description });
return __assign(__assign({}, attribute), { anyOf: union.map(function (u) { return (__assign(__assign({}, u), { description: ChatGptTypeChecker_1.ChatGptTypeChecker.isReference(u)
? undefined
: u.description })); }) });
};

@@ -453,25 +384,2 @@ ChatGptConverter.separate = function (props) {

};
var getNumericTags = function (schema) { return __spreadArray(__spreadArray(__spreadArray([], __read((schema.minimum !== undefined
? schema.exclusiveMinimum === true
? ["@exclusiveMinimum ".concat(schema.minimum)]
: ["@minimum ".concat(schema.minimum)]
: [])), false), __read((schema.maximum !== undefined
? schema.exclusiveMaximum === true
? ["@exclusiveMaximum ".concat(schema.maximum)]
: ["@maximum ".concat(schema.maximum)]
: [])), false), __read((schema.multipleOf !== undefined
? ["@multipleOf ".concat(schema.multipleOf)]
: [])), false); };
var getStringTags = function (schema) { return __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((schema.minLength !== undefined
? ["@minLength ".concat(schema.minLength)]
: [])), false), __read((schema.maxLength !== undefined
? ["@maxLength ".concat(schema.maxLength)]
: [])), false), __read((schema.format !== undefined ? ["@format ".concat(schema.format)] : [])), false), __read((schema.pattern !== undefined ? ["@pattern ".concat(schema.pattern)] : [])), false); };
var getArrayTags = function (schema) { return __spreadArray(__spreadArray([], __read((schema.minItems !== undefined ? ["@minItems ".concat(schema.minItems)] : [])), false), __read((schema.maxItems !== undefined ? ["@maxItems ".concat(schema.maxItems)] : [])), false); };
var writeTagWithDescription = function (props) {
var _a;
if (props.tags.length === 0)
return props.description;
return __spreadArray(__spreadArray([], __read((((_a = props.description) === null || _a === void 0 ? void 0 : _a.length) ? [props.description, "\n"] : [])), false), __read(props.tags), false).join("\n");
};
})(ChatGptConverter || (exports.ChatGptConverter = ChatGptConverter = {}));
import { OpenApi } from "../OpenApi";
import { IGeminiSchema } from "../structures/IGeminiSchema";
export declare namespace GeminiConverter {
const parameters: (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
recursive: false | number;
}) => IGeminiSchema.IParameters | null;
const schema: (props: {

@@ -5,0 +10,0 @@ components: OpenApi.IComponents;

@@ -5,5 +5,9 @@ "use strict";

var LlmTypeCheckerV3_1 = require("../utils/LlmTypeCheckerV3");
var OpenApiContraintShifter_1 = require("../utils/OpenApiContraintShifter");
var LlmConverterV3_1 = require("./LlmConverterV3");
var GeminiConverter;
(function (GeminiConverter) {
GeminiConverter.parameters = function (props) {
return GeminiConverter.schema(props);
};
GeminiConverter.schema = function (props) {

@@ -15,4 +19,27 @@ var schema = LlmConverterV3_1.LlmConverterV3.schema(props);

LlmTypeCheckerV3_1.LlmTypeCheckerV3.visit(schema, function (v) {
if (v.title !== undefined) {
if (v.description === undefined)
v.description = v.title;
else {
var title = v.title.endsWith(".")
? v.title.substring(0, v.title.length - 1)
: v.title;
v.description = v.description.startsWith(title)
? v.description
: "".concat(title, "\n\n").concat(v.description);
}
delete v.title;
}
if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isOneOf(v))
union = true;
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isObject(v)) {
if (v.properties !== undefined)
delete v.additionalProperties;
}
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isArray(v))
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftArray(v);
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isString(v))
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftString(v);
else if (LlmTypeCheckerV3_1.LlmTypeCheckerV3.isNumber(v) || LlmTypeCheckerV3_1.LlmTypeCheckerV3.isInteger(v))
OpenApiContraintShifter_1.OpenApiContraintShifter.shiftNumeric(v);
});

@@ -19,0 +46,0 @@ return union ? null : schema;

@@ -56,5 +56,6 @@ /**

* @reference https://platform.openai.com/docs/guides/structured-outputs
* @warning Specified not by the ChatGPT documentation, but by my experiments.
* Therefore, its definitions can be inaccurate or be changed in the future.
* If you find any wrong or outdated definitions, please let me know by issue
* @warning Specified not by the official documentation, but by my experiments.
* Therefore, its definitions can be inaccurate or be changed in the
* future. If you find any wrong or outdated definitions, please let me
* know by issue
* @issue https://github.com/samchon/openapi/issues

@@ -61,0 +62,0 @@ * @author Jeongho Nam - https://github.com/samchon

@@ -9,3 +9,3 @@ /**

* OpenAPI v3.0 specification; {@link OpenApiV3.IJsonSchema}. However,
* `IGeminiSchema` cannot understand union and reference types, referenced
* `IGeminiSchema` cannot understand union and reference types, represented
* by the `oneOf` and `$ref` properties. Also, as OpenAPI v3.0 specification

@@ -16,20 +16,42 @@ * does not support the tuple type, `IGeminiSchema` does not support the

* - Does not support
* - {@link OpenApiV3.IJsonSchema.IReference}
* - {@link OpenApiV3.IJsonSchema.IAllOf}
* - {@link OpenApiV3.IJsonSchema.IAnyOf}
* - {@link OpenApiV3.IJsonSchema.IOneOf}
* - {@link OpenApiV3.IJsonSchema.IObject.additionalProperties}
* - {@link OpenApiV3.IJsonSchema.__IAttribute.title}
*
* If compare with {@link OpenApi.IJsonSchema}, the emended JSON schema type,
* these are not supported in the Gemini schema. One thing interesting is,
* the Gemini does not support the `title` property, so it would be revealed
* in the {@link IGeminiSchema.__IAttribute.description} property instead.
*
* - {@link OpenApi.IJsonSchema.IReference}
* - {@link OpenApi.IJsonSchema.IOneOf}
* - {@link OpenApi.IJsonSchema.ITuple}
* - {@link OpenApi.IJsonSchema.IObject.additionalProperties}
* - {@link OpenApi.IJsonSchema.__IAttribute.title}
*
* Also, by the documents of Gemini, these constraint properties are not
* supported, either. However, I can't sure that these constraint properties
* are really not supported in the Geimni, because the Gemini seems like
* understanding them. Therefore, I've decided to keep them alive.
* Also, Gemini has banned below constraint properties. Instead, I'll will
* fill the {@link IGeminiSchema.__IAttribute.description} property with
* the comment text like `"@format uuid"`.
*
* - ex) constraint properties
* - {@link IGeminiSchema.IString.default}
* - {@link IGeminiSchema.__IAttribute.example}
* - {@link IGeminiSchema.__IAttribute.examples}
* - {@link IGeminiSchema.INumber.maximum}
* - {@link IGeminiSchema.IObject.additionalProperties}
* - {@link OpenApi.IJsonSchema.INumber.minimum}
* - {@link OpenApi.IJsonSchema.INumber.maximum}
* - {@link OpenApi.IJsonSchema.INumber.multipleOf}
* - {@link OpenApi.IJsonSchema.IString.minLength}
* - {@link OpenApi.IJsonSchema.IString.maxLength}
* - {@link OpenApi.IJsonSchema.IString.format}
* - {@link OpenApi.IJsonSchema.IString.pattern}
* - {@link OpenApi.IJsonSchema.IString.contentMediaType}
* - {@link OpenApi.IJsonSchema.IArray.minItems}
* - {@link OpenApi.IJsonSchema.IArray.maxItems}
* - {@link OpenApi.IJsonSchema.IArray.unique}
*
* @reference https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/function-calling
* @reference https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling
* @warning Specified not by the official documentation, but by my experiments.
* Therefore, its definitions can be inaccurate or be changed in the
* future. If you find any wrong or outdated definitions, please let me
* know by issue
* @author Jeongho Nam - https://github.com/samchon

@@ -42,8 +64,3 @@ */

*/
interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
type IParameters = IObject;
/**

@@ -81,46 +98,2 @@ * Boolean type schema info.

default?: number | null;
/**
* Minimum value restriction.
*
* @type int64
* @warning document of Gemini says not supported, but cannot sure
*/
minimum?: number;
/**
* Maximum value restriction.
*
* @type int64
* @warning document of Gemini says not supported, but cannot sure
*/
maximum?: number;
/**
* Exclusive minimum value restriction.
*
* For reference, even though your Swagger document has defined the
* `exclusiveMinimum` value as `number`, it has been forcibly converted
* to `boolean` type, and assigns the numeric value to the
* {@link minimum} property in the {@link OpenApi} conversion.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMinimum?: boolean;
/**
* Exclusive maximum value restriction.
*
* For reference, even though your Swagger document has defined the
* `exclusiveMaximum` value as `number`, it has been forcibly converted
* to `boolean` type, and assigns the numeric value to the
* {@link maximum} property in the {@link OpenApi} conversion.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMaximum?: boolean;
/**
* Multiple of value restriction.
*
* @type uint64
* @exclusiveMinimum 0
* @warning document of Gemini says not supported, but cannot sure
*/
multipleOf?: number;
}

@@ -141,43 +114,2 @@ /**

default?: number | null;
/**
* Minimum value restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
minimum?: number;
/**
* Maximum value restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
maximum?: number;
/**
* Exclusive minimum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMinimum` value as `number`, {@link OpenAiComposer}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link minimum} property.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMinimum?: boolean;
/**
* Exclusive maximum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMaximum` value as `number`, {@link OpenAiComposer}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link maximum} property.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMaximum?: boolean;
/**
* Multiple of value restriction.
*
* @exclusiveMinimum 0
* @warning document of Gemini says not supported, but cannot sure
*/
multipleOf?: number;
}

@@ -192,40 +124,2 @@ /**

enum?: Array<string | null>;
/**
* Default value.
*
* @warning document of Gemini says not supported, but cannot sure
*/
default?: string | null;
/**
* Format restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
format?: "binary" | "byte" | "password" | "regex" | "uuid" | "email" | "hostname" | "idn-email" | "idn-hostname" | "iri" | "iri-reference" | "ipv4" | "ipv6" | "uri" | "uri-reference" | "uri-template" | "url" | "date-time" | "date" | "time" | "duration" | "json-pointer" | "relative-json-pointer" | (string & {});
/**
* Pattern restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
pattern?: string;
/**
* Minimum length restriction.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
minLength?: number;
/**
* Maximum length restriction.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
maxLength?: number;
/**
* Content media type restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
contentMediaType?: string;
}

@@ -243,28 +137,2 @@ /**

items: IGeminiSchema;
/**
* Unique items restriction.
*
* If this property value is `true`, target array must have unique items.
*
* @warning document of Gemini says not supported, but cannot sure
*/
uniqueItems?: boolean;
/**
* Minimum items restriction.
*
* Restriction of minumum number of items in the array.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
minItems?: number;
/**
* Maximum items restriction.
*
* Restriction of maximum number of items in the array.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
maxItems?: number;
}

@@ -283,3 +151,3 @@ /**

* If you need additional properties that is represented by dynamic key,
* you can use the {@link additionalProperties} instead.
* it is not possible to compose because the Gemini does not support it.
*/

@@ -321,20 +189,2 @@ properties: Record<string, IGeminiSchema>;

required?: string[];
/**
* Additional properties' info.
*
* The `additionalProperties` means the type schema info of the additional
* properties that are not listed in the {@link properties}.
*
* If the value is `true`, it means that the additional properties
* are not restricted. They can be any type. Otherwise, if the value is
* {@link IGeminiSchema} type, it means that the additional properties
* must follow the type schema info.
*
* - `false`: only regular properties
* - `true`: `Record<string, any>`
* - `IGeminiSchema`: `Record<string, T>`
*
* @warning document of Gemini says not supported, but cannot sure
*/
additionalProperties?: boolean | IGeminiSchema;
}

@@ -385,6 +235,2 @@ /**

/**
* Title of the schema.
*/
title?: string;
/**
* Detailed description of the schema.

@@ -391,0 +237,0 @@ */

@@ -39,5 +39,2 @@ "use strict";

});
if (typeof schema.additionalProperties === "object" &&
schema.additionalProperties !== null)
GeminiTypeChecker.visit(schema.additionalProperties, closure);
}

@@ -92,18 +89,18 @@ else if (GeminiTypeChecker.isArray(schema))

x.type === y.type,
x.minimum === undefined ||
(y.minimum !== undefined && x.minimum <= y.minimum),
x.maximum === undefined ||
(y.maximum !== undefined && x.maximum >= y.maximum),
x.exclusiveMinimum !== true ||
x.minimum === undefined ||
(y.minimum !== undefined &&
(y.exclusiveMinimum === true || x.minimum < y.minimum)),
x.exclusiveMaximum !== true ||
x.maximum === undefined ||
(y.maximum !== undefined &&
(y.exclusiveMaximum === true || x.maximum > y.maximum)),
x.multipleOf === undefined ||
(y.multipleOf !== undefined &&
y.multipleOf / x.multipleOf ===
Math.floor(y.multipleOf / x.multipleOf)),
// x.minimum === undefined ||
// (y.minimum !== undefined && x.minimum <= y.minimum),
// x.maximum === undefined ||
// (y.maximum !== undefined && x.maximum >= y.maximum),
// x.exclusiveMinimum !== true ||
// x.minimum === undefined ||
// (y.minimum !== undefined &&
// (y.exclusiveMinimum === true || x.minimum < y.minimum)),
// x.exclusiveMaximum !== true ||
// x.maximum === undefined ||
// (y.maximum !== undefined &&
// (y.exclusiveMaximum === true || x.maximum > y.maximum)),
// x.multipleOf === undefined ||
// (y.multipleOf !== undefined &&
// y.multipleOf / x.multipleOf ===
// Math.floor(y.multipleOf / x.multipleOf)),
].every(function (v) { return v; });

@@ -119,18 +116,18 @@ };

x.type === y.type,
x.minimum === undefined ||
(y.minimum !== undefined && x.minimum <= y.minimum),
x.maximum === undefined ||
(y.maximum !== undefined && x.maximum >= y.maximum),
x.exclusiveMinimum !== true ||
x.minimum === undefined ||
(y.minimum !== undefined &&
(y.exclusiveMinimum === true || x.minimum < y.minimum)),
x.exclusiveMaximum !== true ||
x.maximum === undefined ||
(y.maximum !== undefined &&
(y.exclusiveMaximum === true || x.maximum > y.maximum)),
x.multipleOf === undefined ||
(y.multipleOf !== undefined &&
y.multipleOf / x.multipleOf ===
Math.floor(y.multipleOf / x.multipleOf)),
// x.minimum === undefined ||
// (y.minimum !== undefined && x.minimum <= y.minimum),
// x.maximum === undefined ||
// (y.maximum !== undefined && x.maximum >= y.maximum),
// x.exclusiveMinimum !== true ||
// x.minimum === undefined ||
// (y.minimum !== undefined &&
// (y.exclusiveMinimum === true || x.minimum < y.minimum)),
// x.exclusiveMaximum !== true ||
// x.maximum === undefined ||
// (y.maximum !== undefined &&
// (y.exclusiveMaximum === true || x.maximum > y.maximum)),
// x.multipleOf === undefined ||
// (y.multipleOf !== undefined &&
// y.multipleOf / x.multipleOf ===
// Math.floor(y.multipleOf / x.multipleOf)),
].every(function (v) { return v; });

@@ -145,32 +142,43 @@ };

return [
x.format === undefined ||
(y.format !== undefined && coverFormat(x.format, y.format)),
x.pattern === undefined || x.pattern === y.pattern,
x.minLength === undefined ||
(y.minLength !== undefined && x.minLength <= y.minLength),
x.maxLength === undefined ||
(y.maxLength !== undefined && x.maxLength >= y.maxLength),
x.type === y.type,
// x.format === undefined ||
// (y.format !== undefined && coverFormat(x.format, y.format)),
// x.pattern === undefined || x.pattern === y.pattern,
// x.minLength === undefined ||
// (y.minLength !== undefined && x.minLength <= y.minLength),
// x.maxLength === undefined ||
// (y.maxLength !== undefined && x.maxLength >= y.maxLength),
].every(function (v) { return v; });
};
// /**
// * @internal
// */
// const coverFormat = (
// x: Required<IGeminiSchema.IString>["format"],
// y: Required<IGeminiSchema.IString>["format"],
// ): boolean =>
// x === y ||
// (x === "idn-email" && y === "email") ||
// (x === "idn-hostname" && y === "hostname") ||
// (["uri", "iri"].includes(x) && y === "url") ||
// (x === "iri" && y === "uri") ||
// (x === "iri-reference" && y === "uri-reference");
/**
* @internal
*/
var coverFormat = function (x, y) {
return x === y ||
(x === "idn-email" && y === "email") ||
(x === "idn-hostname" && y === "hostname") ||
(["uri", "iri"].includes(x) && y === "url") ||
(x === "iri" && y === "uri") ||
(x === "iri-reference" && y === "uri-reference");
};
/**
* @internal
*/
var coverArray = function (x, y) {
if (!(x.minItems === undefined ||
(y.minItems !== undefined && x.minItems <= y.minItems)))
return false;
else if (!(x.maxItems === undefined ||
(y.maxItems !== undefined && x.maxItems >= y.maxItems)))
return false;
// if (
// !(
// x.minItems === undefined ||
// (y.minItems !== undefined && x.minItems <= y.minItems)
// )
// )
// return false;
// else if (
// !(
// x.maxItems === undefined ||
// (y.maxItems !== undefined && x.maxItems >= y.maxItems)
// )
// )
// return false;
return GeminiTypeChecker.covers(x.items, y.items);

@@ -183,12 +191,2 @@ };

var _a;
if (!x.additionalProperties && !!y.additionalProperties)
return false;
else if (!!x.additionalProperties &&
!!y.additionalProperties &&
((typeof x.additionalProperties === "object" &&
y.additionalProperties === true) ||
(typeof x.additionalProperties === "object" &&
typeof y.additionalProperties === "object" &&
!GeminiTypeChecker.covers(x.additionalProperties, y.additionalProperties))))
return false;
return Object.entries((_a = y.properties) !== null && _a !== void 0 ? _a : {}).every(function (_a) {

@@ -195,0 +193,0 @@ var _b, _c, _d, _e, _f;

{
"name": "@samchon/openapi",
"version": "2.0.0-dev.20241121-3",
"version": "2.0.0-dev.20241121-4",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",

@@ -35,2 +35,3 @@ "main": "./lib/index.js",

"devDependencies": {
"@google/generative-ai": "^0.21.0",
"@nestia/core": "4.0.0-dev.20241116",

@@ -37,0 +38,0 @@ "@nestia/e2e": "0.7.0",

@@ -17,3 +17,7 @@ > ## Next version is coming.

emended --normalizes--> migration[["Migration Schema"]]
migration --"Artificial Intelligence"--> lfc{{"LLM Function Calling Application"}}
migration --"Artificial Intelligence"--> lfc{{"LLM Function Calling"}}
lfc --"OpenAI"--> chatgpt("ChatGPT")
lfc --"Anthropic"--> claude("Claude")
lfc --"Google"--> gemini("Gemini")
lfc --"Meta (Facebook)"--> llama("Llama")
end

@@ -41,7 +45,9 @@ ```

- [`IHttpLlmFunction<Schema>`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmFunction.ts)
- Supported schemes
- [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
- [`IGeminiSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IGeminiSchema.ts)
- [`ILlmSchemaV3`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3.ts)
- [`ILlmSchemaV3_1`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3_1.ts)
- Supported schemas
- ✔️[`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts): OpenAI ChatGPT
- ✔️[`IGeminiSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IGeminiSchema.ts): Google Gemini
- ✍️`ILlamaSchema`: Meta (Facebook) Llama
- ✍️`IClaudeSchema`: Anthropic Claude
- ✔️[`ILlmSchemaV3`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3.ts): middle layer of OpenAPI v3.0
- ✔️[`ILlmSchemaV3_1`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3_1.ts): middle layer of OpenAPI v3.1

@@ -201,3 +207,3 @@ > [!TIP]

```mermaid
flowchart
flowchart TD
subgraph "OpenAPI Specification"

@@ -210,3 +216,7 @@ v20("Swagger v2.0") --upgrades--> emended[["OpenAPI v3.1 (emended)"]]

emended --normalizes--> migration[["Migration Schema"]]
migration --"Artificial Intelligence"--> lfc{{"<b><u>LLM Function Calling Application</b></u>"}}
migration --"Artificial Intelligence"--> lfc{{"<b><u>LLM Function Calling</b></u>"}}
lfc --"OpenAI"--> chatgpt("ChatGPT")
lfc --"Anthropic"--> claude("Claude")
lfc --"Google"--> gemini("Gemini")
lfc --"Meta (Facebook)"--> llama("Llama")
end

@@ -213,0 +223,0 @@ ```

@@ -5,2 +5,3 @@ import { OpenApi } from "../OpenApi";

import { ChatGptTypeChecker } from "../utils/ChatGptTypeChecker";
import { OpenApiContraintShifter } from "../utils/OpenApiContraintShifter";
import { OpenApiTypeChecker } from "../utils/OpenApiTypeChecker";

@@ -32,3 +33,3 @@

}): IChatGptSchema | null => {
const union: Array<IUnionElement> = [];
const union: Array<IChatGptSchema | null> = [];
const attribute: IChatGptSchema.__IAttribute = {

@@ -63,9 +64,6 @@ title: props.schema.title,

union.push({
schema: {
...input,
$ref: `#/$defs/${key}`,
title: undefined,
description: undefined,
},
tags: [],
...input,
$ref: `#/$defs/${key}`,
title: undefined,
description: undefined,
});

@@ -80,7 +78,3 @@ if (props.$defs[key] !== undefined) return out();

});
if (converted === null)
return union.push({
schema: null,
tags: [],
});
if (converted === null) return union.push(null);
converted.description = OpenApiTypeChecker.writeReferenceDescription({

@@ -97,17 +91,11 @@ components: props.components,

visit(target);
if (
length === union.length - 1 &&
union[union.length - 1].schema !== null
)
if (length === union.length - 1 && union[union.length - 1] !== null)
union[union.length - 1] = {
tags: union[union.length - 1].tags,
schema: {
...union[union.length - 1].schema,
description: OpenApiTypeChecker.writeReferenceDescription({
components: props.components,
$ref: input.$ref,
description: union[union.length - 1].schema?.description,
escape: true,
}),
},
...union[union.length - 1]!,
description: OpenApiTypeChecker.writeReferenceDescription({
components: props.components,
$ref: input.$ref,
description: union[union.length - 1]!.description,
escape: true,
}),
};

@@ -141,6 +129,3 @@ else

if (Object.values(properties).some((v) => v === null))
return union.push({
schema: null,
tags: [],
});
return union.push(null);
const additionalProperties =

@@ -158,15 +143,8 @@ input.additionalProperties === undefined

: input.additionalProperties;
if (additionalProperties === null)
return union.push({
schema: null,
tags: [],
});
if (additionalProperties === null) return union.push(null);
return union.push({
schema: {
...input,
properties: properties as Record<string, IChatGptSchema>,
additionalProperties,
required: Object.keys(properties),
},
tags: [],
...input,
properties: properties as Record<string, IChatGptSchema>,
additionalProperties,
required: Object.keys(properties),
});

@@ -180,37 +158,21 @@ } else if (OpenApiTypeChecker.isArray(input)) {

});
if (items === null)
return union.push({
schema: null,
tags: props.options.constraint ? [] : getArrayTags(input),
});
return union.push({
schema: {
if (items === null) return union.push(null);
return union.push(
(props.options.constraint
? (x: IChatGptSchema.IArray) => x
: (x: IChatGptSchema.IArray) =>
OpenApiContraintShifter.shiftArray(x))({
...input,
items,
...(props.options.constraint
? {}
: {
maxItems: undefined,
minItems: undefined,
uniqueItems: undefined,
}),
},
tags: props.options.constraint ? [] : getArrayTags(input),
});
}),
);
} else if (OpenApiTypeChecker.isString(input))
return union.push({
schema: {
return union.push(
(props.options.constraint
? (x: IChatGptSchema.IString) => x
: (x: IChatGptSchema.IString) =>
OpenApiContraintShifter.shiftString(x))({
...input,
...(props.options.constraint
? {}
: {
contentMediaType: undefined,
minLength: undefined,
maxLength: undefined,
format: undefined,
pattern: undefined,
}),
},
tags: props.options.constraint ? [] : getStringTags(input),
});
}),
);
else if (

@@ -220,47 +182,28 @@ OpenApiTypeChecker.isNumber(input) ||

)
return union.push({
schema: {
return union.push(
(props.options.constraint
? (x: IChatGptSchema.INumber | IChatGptSchema.IInteger) => x
: (x: IChatGptSchema.INumber | IChatGptSchema.IInteger) =>
OpenApiContraintShifter.shiftNumeric(x))({
...input,
...(props.options.constraint
? {}
: {
maximum: undefined,
minimum: undefined,
exclusiveMaximum: undefined,
exclusiveMinimum: undefined,
multipleOf: undefined,
}),
},
tags: props.options.constraint ? [] : getNumericTags(input),
});
}),
);
else if (OpenApiTypeChecker.isConstant(input)) return 0;
else if (OpenApiTypeChecker.isTuple(input))
return union.push({
schema: null,
tags: [],
});
else
return union.push({
schema: { ...input },
tags: [],
});
else if (OpenApiTypeChecker.isTuple(input)) return union.push(null);
else return union.push({ ...input });
};
const visitConstant = (input: OpenApi.IJsonSchema): void => {
const insert = (value: any): void => {
const matched: IUnionElement<IChatGptSchema.IString> | undefined =
union.find(
(u) =>
(u.schema as IChatGptSchema.__ISignificant<any>)?.type ===
typeof value,
) as IUnionElement<IChatGptSchema.IString> | undefined;
const matched: IChatGptSchema.IString | undefined = union.find(
(u) =>
(u as IChatGptSchema.__ISignificant<any> | undefined)?.type ===
typeof value,
) as IChatGptSchema.IString | undefined;
if (matched !== undefined) {
matched.schema!.enum ??= [];
matched.schema!.enum.push(value);
matched.enum ??= [];
matched.enum.push(value);
} else
union.push({
schema: {
type: typeof value as "number",
enum: [value],
},
tags: [],
type: typeof value as "number",
enum: [value],
});

@@ -298,9 +241,6 @@ };

...attribute,
...union[0].schema,
description: ChatGptTypeChecker.isReference(union[0].schema!)
...union[0]!,
description: ChatGptTypeChecker.isReference(union[0]!)
? undefined
: writeTagWithDescription({
description: attribute.description,
tags: union[0].tags,
}),
: union[0]!.description,
};

@@ -310,9 +250,6 @@ return {

anyOf: union.map((u) => ({
...u.schema,
description: ChatGptTypeChecker.isReference(u.schema!)
...u!,
description: ChatGptTypeChecker.isReference(u!)
? undefined
: writeTagWithDescription({
description: u.schema?.description,
tags: u.tags,
}),
: u!.description,
})),

@@ -495,52 +432,2 @@ };

};
const getNumericTags = (
schema: OpenApi.IJsonSchema.IInteger | OpenApi.IJsonSchema.INumber,
) => [
...(schema.minimum !== undefined
? schema.exclusiveMinimum === true
? [`@exclusiveMinimum ${schema.minimum}`]
: [`@minimum ${schema.minimum}`]
: []),
...(schema.maximum !== undefined
? schema.exclusiveMaximum === true
? [`@exclusiveMaximum ${schema.maximum}`]
: [`@maximum ${schema.maximum}`]
: []),
...(schema.multipleOf !== undefined
? [`@multipleOf ${schema.multipleOf}`]
: []),
];
const getStringTags = (schema: OpenApi.IJsonSchema.IString) => [
...(schema.minLength !== undefined
? [`@minLength ${schema.minLength}`]
: []),
...(schema.maxLength !== undefined
? [`@maxLength ${schema.maxLength}`]
: []),
...(schema.format !== undefined ? [`@format ${schema.format}`] : []),
...(schema.pattern !== undefined ? [`@pattern ${schema.pattern}`] : []),
];
const getArrayTags = (schema: OpenApi.IJsonSchema.IArray) => [
...(schema.minItems !== undefined ? [`@minItems ${schema.minItems}`] : []),
...(schema.maxItems !== undefined ? [`@maxItems ${schema.maxItems}`] : []),
];
const writeTagWithDescription = (props: {
description: string | undefined;
tags: string[];
}): string | undefined => {
if (props.tags.length === 0) return props.description;
return [
...(props.description?.length ? [props.description, "\n"] : []),
...props.tags,
].join("\n");
};
}
interface IUnionElement<Schema extends IChatGptSchema = IChatGptSchema> {
schema: Schema | null;
tags: string[];
}

@@ -5,5 +5,13 @@ import { OpenApi } from "../OpenApi";

import { LlmTypeCheckerV3 } from "../utils/LlmTypeCheckerV3";
import { OpenApiContraintShifter } from "../utils/OpenApiContraintShifter";
import { LlmConverterV3 } from "./LlmConverterV3";
export namespace GeminiConverter {
export const parameters = (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
recursive: false | number;
}): IGeminiSchema.IParameters | null =>
schema(props) as IGeminiSchema.IParameters | null;
export const schema = (props: {

@@ -19,3 +27,23 @@ components: OpenApi.IComponents;

LlmTypeCheckerV3.visit(schema, (v) => {
if (v.title !== undefined) {
if (v.description === undefined) v.description = v.title;
else {
const title: string = v.title.endsWith(".")
? v.title.substring(0, v.title.length - 1)
: v.title;
v.description = v.description.startsWith(title)
? v.description
: `${title}\n\n${v.description}`;
}
delete v.title;
}
if (LlmTypeCheckerV3.isOneOf(v)) union = true;
else if (LlmTypeCheckerV3.isObject(v)) {
if (v.properties !== undefined) delete v.additionalProperties;
} else if (LlmTypeCheckerV3.isArray(v))
OpenApiContraintShifter.shiftArray(v);
else if (LlmTypeCheckerV3.isString(v))
OpenApiContraintShifter.shiftString(v);
else if (LlmTypeCheckerV3.isNumber(v) || LlmTypeCheckerV3.isInteger(v))
OpenApiContraintShifter.shiftNumeric(v);
});

@@ -22,0 +50,0 @@ return union ? null : schema;

@@ -56,5 +56,6 @@ /**

* @reference https://platform.openai.com/docs/guides/structured-outputs
* @warning Specified not by the ChatGPT documentation, but by my experiments.
* Therefore, its definitions can be inaccurate or be changed in the future.
* If you find any wrong or outdated definitions, please let me know by issue
* @warning Specified not by the official documentation, but by my experiments.
* Therefore, its definitions can be inaccurate or be changed in the
* future. If you find any wrong or outdated definitions, please let me
* know by issue
* @issue https://github.com/samchon/openapi/issues

@@ -61,0 +62,0 @@ * @author Jeongho Nam - https://github.com/samchon

@@ -9,3 +9,3 @@ /**

* OpenAPI v3.0 specification; {@link OpenApiV3.IJsonSchema}. However,
* `IGeminiSchema` cannot understand union and reference types, referenced
* `IGeminiSchema` cannot understand union and reference types, represented
* by the `oneOf` and `$ref` properties. Also, as OpenAPI v3.0 specification

@@ -16,20 +16,42 @@ * does not support the tuple type, `IGeminiSchema` does not support the

* - Does not support
* - {@link OpenApiV3.IJsonSchema.IReference}
* - {@link OpenApiV3.IJsonSchema.IAllOf}
* - {@link OpenApiV3.IJsonSchema.IAnyOf}
* - {@link OpenApiV3.IJsonSchema.IOneOf}
* - {@link OpenApiV3.IJsonSchema.IObject.additionalProperties}
* - {@link OpenApiV3.IJsonSchema.__IAttribute.title}
*
* If compare with {@link OpenApi.IJsonSchema}, the emended JSON schema type,
* these are not supported in the Gemini schema. One thing interesting is,
* the Gemini does not support the `title` property, so it would be revealed
* in the {@link IGeminiSchema.__IAttribute.description} property instead.
*
* - {@link OpenApi.IJsonSchema.IReference}
* - {@link OpenApi.IJsonSchema.IOneOf}
* - {@link OpenApi.IJsonSchema.ITuple}
* - {@link OpenApi.IJsonSchema.IObject.additionalProperties}
* - {@link OpenApi.IJsonSchema.__IAttribute.title}
*
* Also, by the documents of Gemini, these constraint properties are not
* supported, either. However, I can't sure that these constraint properties
* are really not supported in the Geimni, because the Gemini seems like
* understanding them. Therefore, I've decided to keep them alive.
* Also, Gemini has banned below constraint properties. Instead, I'll will
* fill the {@link IGeminiSchema.__IAttribute.description} property with
* the comment text like `"@format uuid"`.
*
* - ex) constraint properties
* - {@link IGeminiSchema.IString.default}
* - {@link IGeminiSchema.__IAttribute.example}
* - {@link IGeminiSchema.__IAttribute.examples}
* - {@link IGeminiSchema.INumber.maximum}
* - {@link IGeminiSchema.IObject.additionalProperties}
* - {@link OpenApi.IJsonSchema.INumber.minimum}
* - {@link OpenApi.IJsonSchema.INumber.maximum}
* - {@link OpenApi.IJsonSchema.INumber.multipleOf}
* - {@link OpenApi.IJsonSchema.IString.minLength}
* - {@link OpenApi.IJsonSchema.IString.maxLength}
* - {@link OpenApi.IJsonSchema.IString.format}
* - {@link OpenApi.IJsonSchema.IString.pattern}
* - {@link OpenApi.IJsonSchema.IString.contentMediaType}
* - {@link OpenApi.IJsonSchema.IArray.minItems}
* - {@link OpenApi.IJsonSchema.IArray.maxItems}
* - {@link OpenApi.IJsonSchema.IArray.unique}
*
* @reference https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/function-calling
* @reference https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling
* @warning Specified not by the official documentation, but by my experiments.
* Therefore, its definitions can be inaccurate or be changed in the
* future. If you find any wrong or outdated definitions, please let me
* know by issue
* @author Jeongho Nam - https://github.com/samchon

@@ -50,8 +72,3 @@ */

*/
export interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
export type IParameters = IObject;

@@ -93,51 +110,2 @@ /**

default?: number | null;
/**
* Minimum value restriction.
*
* @type int64
* @warning document of Gemini says not supported, but cannot sure
*/
minimum?: number;
/**
* Maximum value restriction.
*
* @type int64
* @warning document of Gemini says not supported, but cannot sure
*/
maximum?: number;
/**
* Exclusive minimum value restriction.
*
* For reference, even though your Swagger document has defined the
* `exclusiveMinimum` value as `number`, it has been forcibly converted
* to `boolean` type, and assigns the numeric value to the
* {@link minimum} property in the {@link OpenApi} conversion.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMinimum?: boolean;
/**
* Exclusive maximum value restriction.
*
* For reference, even though your Swagger document has defined the
* `exclusiveMaximum` value as `number`, it has been forcibly converted
* to `boolean` type, and assigns the numeric value to the
* {@link maximum} property in the {@link OpenApi} conversion.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMaximum?: boolean;
/**
* Multiple of value restriction.
*
* @type uint64
* @exclusiveMinimum 0
* @warning document of Gemini says not supported, but cannot sure
*/
multipleOf?: number;
}

@@ -160,48 +128,2 @@

default?: number | null;
/**
* Minimum value restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
minimum?: number;
/**
* Maximum value restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
maximum?: number;
/**
* Exclusive minimum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMinimum` value as `number`, {@link OpenAiComposer}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link minimum} property.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMinimum?: boolean;
/**
* Exclusive maximum value restriction.
*
* For reference, even though your Swagger (or OpenAPI) document has
* defined the `exclusiveMaximum` value as `number`, {@link OpenAiComposer}
* forcibly converts it to `boolean` type, and assign the numeric value to
* the {@link maximum} property.
*
* @warning document of Gemini says not supported, but cannot sure
*/
exclusiveMaximum?: boolean;
/**
* Multiple of value restriction.
*
* @exclusiveMinimum 0
* @warning document of Gemini says not supported, but cannot sure
*/
multipleOf?: number;
}

@@ -217,70 +139,2 @@

enum?: Array<string | null>;
/**
* Default value.
*
* @warning document of Gemini says not supported, but cannot sure
*/
default?: string | null;
/**
* Format restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
format?:
| "binary"
| "byte"
| "password"
| "regex"
| "uuid"
| "email"
| "hostname"
| "idn-email"
| "idn-hostname"
| "iri"
| "iri-reference"
| "ipv4"
| "ipv6"
| "uri"
| "uri-reference"
| "uri-template"
| "url"
| "date-time"
| "date"
| "time"
| "duration"
| "json-pointer"
| "relative-json-pointer"
| (string & {});
/**
* Pattern restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
pattern?: string;
/**
* Minimum length restriction.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
minLength?: number;
/**
* Maximum length restriction.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
maxLength?: number;
/**
* Content media type restriction.
*
* @warning document of Gemini says not supported, but cannot sure
*/
contentMediaType?: string;
}

@@ -299,31 +153,2 @@

items: IGeminiSchema;
/**
* Unique items restriction.
*
* If this property value is `true`, target array must have unique items.
*
* @warning document of Gemini says not supported, but cannot sure
*/
uniqueItems?: boolean;
/**
* Minimum items restriction.
*
* Restriction of minumum number of items in the array.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
minItems?: number;
/**
* Maximum items restriction.
*
* Restriction of maximum number of items in the array.
*
* @type uint64
* @warning document of Gemini says not supported, but cannot sure
*/
maxItems?: number;
}

@@ -343,3 +168,3 @@

* If you need additional properties that is represented by dynamic key,
* you can use the {@link additionalProperties} instead.
* it is not possible to compose because the Gemini does not support it.
*/

@@ -382,21 +207,2 @@ properties: Record<string, IGeminiSchema>;

required?: string[];
/**
* Additional properties' info.
*
* The `additionalProperties` means the type schema info of the additional
* properties that are not listed in the {@link properties}.
*
* If the value is `true`, it means that the additional properties
* are not restricted. They can be any type. Otherwise, if the value is
* {@link IGeminiSchema} type, it means that the additional properties
* must follow the type schema info.
*
* - `false`: only regular properties
* - `true`: `Record<string, any>`
* - `IGeminiSchema`: `Record<string, T>`
*
* @warning document of Gemini says not supported, but cannot sure
*/
additionalProperties?: boolean | IGeminiSchema;
}

@@ -453,7 +259,2 @@

/**
* Title of the schema.
*/
title?: string;
/**
* Detailed description of the schema.

@@ -460,0 +261,0 @@ */

@@ -23,7 +23,2 @@ import { IGeminiSchema } from "../structures/IGeminiSchema";

);
if (
typeof schema.additionalProperties === "object" &&
schema.additionalProperties !== null
)
visit(schema.additionalProperties, closure);
} else if (isArray(schema)) visit(schema.items, closure);

@@ -73,18 +68,18 @@ };

x.type === y.type,
x.minimum === undefined ||
(y.minimum !== undefined && x.minimum <= y.minimum),
x.maximum === undefined ||
(y.maximum !== undefined && x.maximum >= y.maximum),
x.exclusiveMinimum !== true ||
x.minimum === undefined ||
(y.minimum !== undefined &&
(y.exclusiveMinimum === true || x.minimum < y.minimum)),
x.exclusiveMaximum !== true ||
x.maximum === undefined ||
(y.maximum !== undefined &&
(y.exclusiveMaximum === true || x.maximum > y.maximum)),
x.multipleOf === undefined ||
(y.multipleOf !== undefined &&
y.multipleOf / x.multipleOf ===
Math.floor(y.multipleOf / x.multipleOf)),
// x.minimum === undefined ||
// (y.minimum !== undefined && x.minimum <= y.minimum),
// x.maximum === undefined ||
// (y.maximum !== undefined && x.maximum >= y.maximum),
// x.exclusiveMinimum !== true ||
// x.minimum === undefined ||
// (y.minimum !== undefined &&
// (y.exclusiveMinimum === true || x.minimum < y.minimum)),
// x.exclusiveMaximum !== true ||
// x.maximum === undefined ||
// (y.maximum !== undefined &&
// (y.exclusiveMaximum === true || x.maximum > y.maximum)),
// x.multipleOf === undefined ||
// (y.multipleOf !== undefined &&
// y.multipleOf / x.multipleOf ===
// Math.floor(y.multipleOf / x.multipleOf)),
].every((v) => v);

@@ -104,18 +99,18 @@ };

x.type === y.type,
x.minimum === undefined ||
(y.minimum !== undefined && x.minimum <= y.minimum),
x.maximum === undefined ||
(y.maximum !== undefined && x.maximum >= y.maximum),
x.exclusiveMinimum !== true ||
x.minimum === undefined ||
(y.minimum !== undefined &&
(y.exclusiveMinimum === true || x.minimum < y.minimum)),
x.exclusiveMaximum !== true ||
x.maximum === undefined ||
(y.maximum !== undefined &&
(y.exclusiveMaximum === true || x.maximum > y.maximum)),
x.multipleOf === undefined ||
(y.multipleOf !== undefined &&
y.multipleOf / x.multipleOf ===
Math.floor(y.multipleOf / x.multipleOf)),
// x.minimum === undefined ||
// (y.minimum !== undefined && x.minimum <= y.minimum),
// x.maximum === undefined ||
// (y.maximum !== undefined && x.maximum >= y.maximum),
// x.exclusiveMinimum !== true ||
// x.minimum === undefined ||
// (y.minimum !== undefined &&
// (y.exclusiveMinimum === true || x.minimum < y.minimum)),
// x.exclusiveMaximum !== true ||
// x.maximum === undefined ||
// (y.maximum !== undefined &&
// (y.exclusiveMaximum === true || x.maximum > y.maximum)),
// x.multipleOf === undefined ||
// (y.multipleOf !== undefined &&
// y.multipleOf / x.multipleOf ===
// Math.floor(y.multipleOf / x.multipleOf)),
].every((v) => v);

@@ -134,25 +129,26 @@ };

return [
x.format === undefined ||
(y.format !== undefined && coverFormat(x.format, y.format)),
x.pattern === undefined || x.pattern === y.pattern,
x.minLength === undefined ||
(y.minLength !== undefined && x.minLength <= y.minLength),
x.maxLength === undefined ||
(y.maxLength !== undefined && x.maxLength >= y.maxLength),
x.type === y.type,
// x.format === undefined ||
// (y.format !== undefined && coverFormat(x.format, y.format)),
// x.pattern === undefined || x.pattern === y.pattern,
// x.minLength === undefined ||
// (y.minLength !== undefined && x.minLength <= y.minLength),
// x.maxLength === undefined ||
// (y.maxLength !== undefined && x.maxLength >= y.maxLength),
].every((v) => v);
};
/**
* @internal
*/
const coverFormat = (
x: Required<IGeminiSchema.IString>["format"],
y: Required<IGeminiSchema.IString>["format"],
): boolean =>
x === y ||
(x === "idn-email" && y === "email") ||
(x === "idn-hostname" && y === "hostname") ||
(["uri", "iri"].includes(x) && y === "url") ||
(x === "iri" && y === "uri") ||
(x === "iri-reference" && y === "uri-reference");
// /**
// * @internal
// */
// const coverFormat = (
// x: Required<IGeminiSchema.IString>["format"],
// y: Required<IGeminiSchema.IString>["format"],
// ): boolean =>
// x === y ||
// (x === "idn-email" && y === "email") ||
// (x === "idn-hostname" && y === "hostname") ||
// (["uri", "iri"].includes(x) && y === "url") ||
// (x === "iri" && y === "uri") ||
// (x === "iri-reference" && y === "uri-reference");

@@ -166,16 +162,16 @@ /**

): boolean => {
if (
!(
x.minItems === undefined ||
(y.minItems !== undefined && x.minItems <= y.minItems)
)
)
return false;
else if (
!(
x.maxItems === undefined ||
(y.maxItems !== undefined && x.maxItems >= y.maxItems)
)
)
return false;
// if (
// !(
// x.minItems === undefined ||
// (y.minItems !== undefined && x.minItems <= y.minItems)
// )
// )
// return false;
// else if (
// !(
// x.maxItems === undefined ||
// (y.maxItems !== undefined && x.maxItems >= y.maxItems)
// )
// )
// return false;
return covers(x.items, y.items);

@@ -191,13 +187,2 @@ };

): boolean => {
if (!x.additionalProperties && !!y.additionalProperties) return false;
else if (
!!x.additionalProperties &&
!!y.additionalProperties &&
((typeof x.additionalProperties === "object" &&
y.additionalProperties === true) ||
(typeof x.additionalProperties === "object" &&
typeof y.additionalProperties === "object" &&
!covers(x.additionalProperties, y.additionalProperties)))
)
return false;
return Object.entries(y.properties ?? {}).every(([key, b]) => {

@@ -204,0 +189,0 @@ const a: IGeminiSchema | undefined = x.properties?.[key];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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