@samchon/openapi
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -167,3 +167,3 @@ "use strict"; | ||
const visit = (schema) => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
// NULLABLE PROPERTY | ||
@@ -176,2 +176,6 @@ if (schema.nullable === | ||
} | ||
if (Array.isArray(schema.enum) && | ||
((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.length) && | ||
((_b = schema.enum) === null || _b === void 0 ? void 0 : _b.some((e) => e === null))) | ||
nullable.value || (nullable.value = true); | ||
// MIXED TYPE CASE | ||
@@ -211,3 +215,3 @@ if (TypeChecker.isMixed(schema)) { | ||
visit(Object.assign(Object.assign(Object.assign({}, schema), { | ||
enum: ((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.length) | ||
enum: ((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length) && schema.enum.filter((e) => e !== null) | ||
? schema.enum.filter((x) => typeof x === type) | ||
@@ -218,4 +222,6 @@ : undefined, | ||
visit(Object.assign(Object.assign(Object.assign({}, schema), { | ||
enum: ((_b = schema.enum) === null || _b === void 0 ? void 0 : _b.length) | ||
? schema.enum.filter((x) => Number.isInteger(x)) | ||
enum: ((_d = schema.enum) === null || _d === void 0 ? void 0 : _d.length) && schema.enum.filter((e) => e !== null) | ||
? schema.enum.filter((x) => x !== null && | ||
typeof x === "number" && | ||
Number.isInteger(x)) | ||
: undefined, | ||
@@ -235,15 +241,16 @@ }), { type: type })); | ||
else if (TypeChecker.isBoolean(schema)) | ||
if ((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length) | ||
for (const value of schema.enum) | ||
if (((_e = schema.enum) === null || _e === void 0 ? void 0 : _e.length) && | ||
schema.enum.filter((e) => e !== null).length) | ||
for (const value of schema.enum.filter((e) => e !== null)) | ||
union.push(Object.assign({ const: value }, Object.assign(Object.assign({}, schema), { type: undefined, enum: undefined, default: undefined }))); | ||
else | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: (_d = schema.default) !== null && _d !== void 0 ? _d : undefined }), { | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: (_f = schema.default) !== null && _f !== void 0 ? _f : undefined }), { | ||
enum: undefined, | ||
})); | ||
else if (TypeChecker.isInteger(schema) || TypeChecker.isNumber(schema)) | ||
if ((_e = schema.enum) === null || _e === void 0 ? void 0 : _e.length) | ||
for (const value of schema.enum) | ||
if (((_g = schema.enum) === null || _g === void 0 ? void 0 : _g.length) && schema.enum.filter((e) => e !== null)) | ||
for (const value of schema.enum.filter((e) => e !== null)) | ||
union.push(Object.assign({ const: value }, Object.assign(Object.assign({}, schema), { type: undefined, enum: undefined, default: undefined, minimum: undefined, maximum: undefined, exclusiveMinimum: undefined, exclusiveMaximum: undefined, multipleOf: undefined }))); | ||
else | ||
union.push(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, schema), { default: (_f = schema.default) !== null && _f !== void 0 ? _f : undefined }), { | ||
union.push(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, schema), { default: (_h = schema.default) !== null && _h !== void 0 ? _h : undefined }), { | ||
enum: undefined, | ||
@@ -266,7 +273,8 @@ }), (typeof schema.exclusiveMinimum === "number" | ||
else if (TypeChecker.isString(schema)) | ||
if ((_g = schema.enum) === null || _g === void 0 ? void 0 : _g.length) | ||
for (const value of schema.enum) | ||
if (((_j = schema.enum) === null || _j === void 0 ? void 0 : _j.length) && | ||
schema.enum.filter((e) => e !== null).length) | ||
for (const value of schema.enum.filter((e) => e !== null)) | ||
union.push(Object.assign({ const: value }, Object.assign(Object.assign({}, schema), { type: undefined, enum: undefined, default: undefined }))); | ||
else | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: (_h = schema.default) !== null && _h !== void 0 ? _h : undefined }), { | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: (_k = schema.default) !== null && _k !== void 0 ? _k : undefined }), { | ||
enum: undefined, | ||
@@ -273,0 +281,0 @@ })); |
@@ -153,3 +153,3 @@ "use strict"; | ||
const visit = (schema) => { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
// NULLABLE PROPERTY | ||
@@ -162,2 +162,6 @@ if (schema.nullable === | ||
} | ||
if (Array.isArray(schema.enum) && | ||
((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.length) && | ||
((_b = schema.enum) === null || _b === void 0 ? void 0 : _b.some((e) => e === null))) | ||
nullable.value || (nullable.value = true); | ||
// UNION TYPE CASE | ||
@@ -175,6 +179,9 @@ if (TypeChecker.isAnyOf(schema)) | ||
TypeChecker.isString(schema)) | ||
if ((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.length) | ||
union.push(...schema.enum.map((value) => ({ const: value }))); | ||
if (((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length) && | ||
schema.enum.filter((e) => e !== null).length) | ||
union.push(...schema.enum | ||
.filter((v) => v !== null) | ||
.map((value) => ({ const: value }))); | ||
else | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: ((_b = schema.default) !== null && _b !== void 0 ? _b : undefined) }), { enum: undefined })); | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: ((_d = schema.default) !== null && _d !== void 0 ? _d : undefined) }), { enum: undefined })); | ||
// INSTANCE TYPE CASE | ||
@@ -181,0 +188,0 @@ else if (TypeChecker.isArray(schema)) |
@@ -205,3 +205,3 @@ "use strict"; | ||
const visit = (schema) => { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
// NULLABLE PROPERTY | ||
@@ -214,2 +214,6 @@ if (schema["x-nullable"] === | ||
} | ||
if (Array.isArray(schema.enum) && | ||
((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.length) && | ||
((_b = schema.enum) === null || _b === void 0 ? void 0 : _b.some((e) => e === null))) | ||
nullable.value || (nullable.value = true); | ||
// UNION TYPE CASE | ||
@@ -225,6 +229,8 @@ if (TypeChecker.isAnyOf(schema)) | ||
TypeChecker.isString(schema)) | ||
if ((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.length) | ||
union.push(...schema.enum.map((value) => ({ const: value }))); | ||
if (((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length) && schema.enum.filter((e) => e !== null).length) | ||
union.push(...schema.enum | ||
.filter((v) => v !== null) | ||
.map((value) => ({ const: value }))); | ||
else | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: ((_b = schema.default) !== null && _b !== void 0 ? _b : undefined) }), { enum: undefined })); | ||
union.push(Object.assign(Object.assign(Object.assign({}, schema), { default: ((_d = schema.default) !== null && _d !== void 0 ? _d : undefined) }), { enum: undefined })); | ||
// INSTANCE TYPE CASE | ||
@@ -231,0 +237,0 @@ else if (TypeChecker.isArray(schema)) |
@@ -131,7 +131,7 @@ /** | ||
default?: boolean | null; | ||
enum?: boolean[]; | ||
enum?: Array<boolean | null>; | ||
} | ||
interface IInteger extends __ISignificant<"integer"> { | ||
/** @type int64 */ default?: number | null; | ||
/** @type int64 */ enum?: number[]; | ||
/** @type int64 */ enum?: Array<number | null>; | ||
/** @type int64 */ minimum?: number; | ||
@@ -149,3 +149,3 @@ /** @type int64 */ maximum?: number; | ||
default?: number | null; | ||
enum?: number[]; | ||
enum?: Array<number | null>; | ||
minimum?: number; | ||
@@ -160,3 +160,3 @@ maximum?: number; | ||
default?: string | null; | ||
enum?: string[]; | ||
enum?: Array<string | null>; | ||
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 & {}); | ||
@@ -163,0 +163,0 @@ pattern?: string; |
@@ -119,7 +119,7 @@ /** | ||
default?: boolean | null; | ||
enum?: boolean[]; | ||
enum?: Array<boolean | null>; | ||
} | ||
interface IInteger extends __ISignificant<"integer"> { | ||
/** @type int64 */ default?: number | null; | ||
/** @type int64 */ enum?: number[]; | ||
/** @type int64 */ enum?: Array<number | null>; | ||
/** @type int64 */ minimum?: number; | ||
@@ -137,3 +137,3 @@ /** @type int64 */ maximum?: number; | ||
default?: number | null; | ||
enum?: number[]; | ||
enum?: Array<number | null>; | ||
minimum?: number; | ||
@@ -147,3 +147,3 @@ maximum?: number; | ||
default?: string | null; | ||
enum?: string[]; | ||
enum?: Array<string | null>; | ||
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 & {}); | ||
@@ -150,0 +150,0 @@ pattern?: string; |
@@ -88,7 +88,7 @@ /** | ||
default?: boolean | null; | ||
enum?: boolean[]; | ||
enum?: Array<boolean | null>; | ||
} | ||
interface IInteger extends __ISignificant<"integer"> { | ||
/** @type int64 */ default?: number | null; | ||
/** @type int64 */ enum?: number[]; | ||
/** @type int64 */ enum?: Array<number | null>; | ||
/** @type int64 */ minimum?: number; | ||
@@ -106,3 +106,3 @@ /** @type int64 */ maximum?: number; | ||
default?: number | null; | ||
enum?: number[]; | ||
enum?: Array<number | null>; | ||
minimum?: number; | ||
@@ -116,3 +116,3 @@ maximum?: number; | ||
default?: string | null; | ||
enum?: string[]; | ||
enum?: Array<string | null>; | ||
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 & {}); | ||
@@ -119,0 +119,0 @@ pattern?: string; |
{ | ||
"name": "@samchon/openapi", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
# `@samchon/openapi` | ||
![Nestia Editor](https://github.com/samchon/openapi/assets/13158709/350128f7-c159-4ba4-8f8c-743908ada8eb) | ||
@@ -10,5 +9,5 @@ | ||
OpenAPI definitions and converters (for [typia](https://github.com/samchon/typia) and [nestia](https://github.com/samchon/nestia)). | ||
OpenAPI definitions and converters. | ||
`@samchon/openapi` is a collection of OpenAPI definitions of below versions. Those type definitions does not contain every properties of OpenAPI specification, but just have only some features essentially required for `typia` and `nestia` (especially [`@nestia/editor`](https://nestia.io/docs/editor/)). | ||
`@samchon/openapi` is a collection of OpenAPI definitions of below versions. Those type definitions do not contain every properties of OpenAPI specification, but just have only significant features essentially required for `typia`, `nestia` (especially for [`@nestia/editor`](https://nestia.io/docs/editor/)). | ||
@@ -21,3 +20,3 @@ 1. [Swagger v2.0](https://github.com/samchon/openapi/blob/master/src/SwaggerV2.ts) | ||
For example, when representing nullable type, OpenAPI v3.1 supports three ways. In that case, OpenApi remains only the third way, so that makes `typia` and `nestia` (especially [`@nestia/editor`](https://nestia.io/docs/editor/)) to be simple and easy to implement. | ||
For example, when representing nullable type, OpenAPI v3.1 supports three ways. In that case, OpenApi remains only the third way, so that makes `typia` and `nestia` (especially for [`@nestia/editor`](https://nestia.io/docs/editor/)) to be simple and easy to implement. | ||
@@ -28,2 +27,11 @@ - `{ type: ["string", "null"] }` | ||
```mermaid | ||
flowchart | ||
v20(Swagger v2.0) --upgrades--> emended[["<b><u>OpenAPI v3.1 (emended)</u></b>"]] | ||
v30(OpenAPI v3.0) --upgrades--> emended | ||
v31(OpenAPI v3.1) --emends--> emended | ||
emended --downgrades--> v20d(Swagger v2.0) | ||
emended --downgrades--> v30d(Swagger v3.0) | ||
``` | ||
Here is the entire list of differences between OpenAPI v3.1 and emended OpenApi. | ||
@@ -44,7 +52,23 @@ | ||
Additionally, `@samchon/openapi` provides [`IMigrateDocument`](https://github.com/samchon/openapi/blob/master/src/IMigrateDocument.ts) for OpenAPI generators. If you're developing TypeScript, [`@nestia/editor`](https://nestia.io/docs/editor) would be the best project utilizing the [`IMigrateDocument`](https://github.com/samchon/openapi/blob/master/src/IMigrateDocument.ts) for the OpenAPI SDK generation. Otherwise, you wanna utilize OpenAPI document for OpenAI function calling, [`@wrtnio/openai-function-schema`](https://github.com/wrtnio/openai-function-schema/) has been prepared for you. | ||
Additionally, `@samchon/openapi` provides [`IMigrateDocument`](https://github.com/samchon/openapi/blob/master/src/IMigrateDocument.ts) for OpenAPI generators. | ||
If you're developing TypeScript, [`@nestia/editor`](https://nestia.io/docs/editor) would be the best project utilizing the [`IMigrateDocument`](https://github.com/samchon/openapi/blob/master/src/IMigrateDocument.ts) for the OpenAPI SDK generation. Otherwise, you wanna utilize OpenAPI document for OpenAI function calling, [`@wrtnio/openai-function-schema`](https://github.com/wrtnio/openai-function-schema/) has been prepared for you. | ||
```mermaid | ||
flowchart | ||
subgraph "OpenAPI Specification" | ||
v20(Swagger v2.0) --upgrades--> emended[["OpenAPI v3.1 (emended)"]] | ||
v30(OpenAPI v3.0) --upgrades--> emended | ||
v31(OpenAPI v3.1) --emends--> emended | ||
end | ||
subgraph "OpenAPI Generators" | ||
emended --normalizes--> migration[["<b><u>Migration Schema</u></b>"]] | ||
migration --A.I.--> lfc{{"LLM Function Call"}} | ||
migration --Uiltiy--> editor{{"@nestia/editor"}} | ||
end | ||
``` | ||
## How to use | ||
@@ -86,5 +110,43 @@ ```bash | ||
Just install `@samchon/openapi` library and import `OpenApi` module from there. | ||
Every features you need from `@samchon/openapi` are in the `OpenApi` module. If you want to connvert emended OpenAPI v3.1 type, just call `OpenApi.convert()` function with your document. Otherwise you want to downgrade from the OpenAPI v3.1 emended specification, call `OpenApi.migrate()` instead. Of course, if you combine both `OpenApi.convert()` and `OpenApi.migrate()` functions, you can transform every OpenAPI versions. | ||
By the way, if you want to validate whether your OpenAPI document is following the standard specification or not, you can do it on the playground website. Click one of below links, and paste your OpenAPI URL address. Of course, if you wanna validate in your local machine, just install [`typia`](https://github.com/samchon/typia) and write same code of playground. | ||
- [💻 Type assertion](https://typia.io/playground/?script=JYWwDg9gTgLgBAbzgeTAUwHYEEzADQrra4BqAzAapjsOQPoCMBAygO4CGA5p2lCQExwAvnABmUCCDgAiAAIBndiADGACwgYA9BCLtc0gNwAoUJFhwYAT1zsxEqdKs3DRo8o3z4IdsAxwAvHDs8pYYynAAFACUAFxwAAr2wPJoADwAbhDAACYAfAH5CEZwcJqacADiAKIAKnAAmsgAqgBKKPFVAHJY8QCScAAiyADCTQCyXTXFcO4YnnBQaPKQc2hxLUsrKQFBHMDwomgwahHTJdKqMDBg8jFlUOysAHSc+6oArgBG7ylQszCYGBPdwgTSKFTqLQ6TB6YCabyeXiaNAADyUYAANktNOkyE8AAzaXTAJ4AK3kGmk0yixhKs3m2QgyneIEBcXYGEsO0ePngi2WHjQZIpGGixmmZTgNXqHTgWGYzCqLRqvWQnWmTmA7CewV+MAq73YUGyqTOcAAPoRqKQyIwnr0BkyWYCzZaqMRaHiHU7WRgYK64GwuDw+Px7Y7mb7-SVchFGZHATTXCVJcM1SQlXUasg4FUJp0BlUBtN6fA0L7smhsnF3TRwz7ATta7hgRp0rwYHGG36k3SPBAsU9fKIIBFy5hK9kk0JjN5fNFgexjqoIvSB0LeBIoDSgA) | ||
- [💻 Detailed validation](https://typia.io/playground/?script=JYWwDg9gTgLgBAbzgeTAUwHYEEzADQrra4BqAzAapjsOQPoCMBAygO4CGA5p2lCQExwAvnABmUCCDgAiAAIBndiADGACwgYA9BCLtc0gNwAoUJFhwYAT1zsxEqdKs3DRo8o3z4IdsAxwAvHDs8pYYynAAFACUAFxwAAr2wPJoADwAbhDAACYAfAH5CEZwcJqacADiAKIAKnAAmsgAqgBKKPFVAHJY8QCScAAiyADCTQCyXTXFcO4YnnBQaPKQc2hxLUsrKQFBHMDwomgwahHTJdKqMDBg8jFlUOysAHSc+6oArgBG7ylQszCYGBPdwgTSKFTqLQ6TB6YCabyeXiaNAADyUYAANktNOkyE8AAzaXTAJ4AK3kGmk0yixhKs3m2QgyneIEBcXYGEsO0ePngi2WHjQZIpGGixmmZTgNXqHTgJCwABlegMsDVeshOtN6Xylu8MfBAk5gOwnul2BicuwAakznAAD6EaikMiMJ7KpkswG2h1UYi0PHu5msjAwb1wNhcHh8fhugYe4Ohkq5CKMoOAmnTYCiSL8vVA+TvZTKJbyAL+QKic0pKKIW30iBYp6+UQQCK5-VPXgSKDyDMlEqLGDvKAYWnCVwlSXDDUkKotOo1ZBwKoTToDKoDLUeeBoYPZNDZOK+mix+OAnbH3DAjTpXgwFNnkN9mYeBtC5ut3eYffZDNCYzeL40TAlaJz1o2XbQDSQA) | ||
```typescript | ||
import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi"; | ||
import typia from "typia"; | ||
const main = async (): Promise<void> => { | ||
// GET YOUR OPENAPI DOCUMENT | ||
const response: Response = await fetch( | ||
"https://raw.githubusercontent.com/samchon/openapi/master/examples/v3.0/openai.json" | ||
); | ||
const document: any = await response.json(); | ||
// TYPE VALIDATION | ||
const result = typia.validate< | ||
| OpenApiV3_1.IDocument | ||
| OpenApiV3.IDocument | ||
| SwaggerV2.IDocument | ||
>(document); | ||
if (result.success === false) { | ||
console.error(result.errors); | ||
return; | ||
} | ||
// CONVERT TO EMENDED | ||
const emended: OpenApi.IDocument = OpenApi.convert(document); | ||
console.info(emended); | ||
}; | ||
main().catch(console.error); | ||
``` | ||
## Related Projects | ||
@@ -91,0 +153,0 @@ - `typia`: https://github.com/samchon/typia |
@@ -300,2 +300,11 @@ import { OpenApi } from "../OpenApi"; | ||
} | ||
if ( | ||
Array.isArray((schema as OpenApiV3_1.IJsonSchema.INumber).enum) && | ||
(schema as OpenApiV3_1.IJsonSchema.INumber).enum?.length && | ||
(schema as OpenApiV3_1.IJsonSchema.INumber).enum?.some( | ||
(e) => e === null, | ||
) | ||
) | ||
nullable.value ||= true; | ||
// MIXED TYPE CASE | ||
@@ -349,5 +358,6 @@ if (TypeChecker.isMixed(schema)) { | ||
...{ | ||
enum: schema.enum?.length | ||
? schema.enum.filter((x) => typeof x === type) | ||
: undefined, | ||
enum: | ||
schema.enum?.length && schema.enum.filter((e) => e !== null) | ||
? schema.enum.filter((x) => typeof x === type) | ||
: undefined, | ||
}, | ||
@@ -360,5 +370,11 @@ type: type as any, | ||
...{ | ||
enum: schema.enum?.length | ||
? schema.enum.filter((x) => Number.isInteger(x)) | ||
: undefined, | ||
enum: | ||
schema.enum?.length && schema.enum.filter((e) => e !== null) | ||
? schema.enum.filter( | ||
(x) => | ||
x !== null && | ||
typeof x === "number" && | ||
Number.isInteger(x), | ||
) | ||
: undefined, | ||
}, | ||
@@ -376,4 +392,7 @@ type: type as any, | ||
else if (TypeChecker.isBoolean(schema)) | ||
if (schema.enum?.length) | ||
for (const value of schema.enum) | ||
if ( | ||
schema.enum?.length && | ||
schema.enum.filter((e) => e !== null).length | ||
) | ||
for (const value of schema.enum.filter((e) => e !== null)) | ||
union.push({ | ||
@@ -397,4 +416,4 @@ const: value, | ||
else if (TypeChecker.isInteger(schema) || TypeChecker.isNumber(schema)) | ||
if (schema.enum?.length) | ||
for (const value of schema.enum) | ||
if (schema.enum?.length && schema.enum.filter((e) => e !== null)) | ||
for (const value of schema.enum.filter((e) => e !== null)) | ||
union.push({ | ||
@@ -439,4 +458,7 @@ const: value, | ||
else if (TypeChecker.isString(schema)) | ||
if (schema.enum?.length) | ||
for (const value of schema.enum) | ||
if ( | ||
schema.enum?.length && | ||
schema.enum.filter((e) => e !== null).length | ||
) | ||
for (const value of schema.enum.filter((e) => e !== null)) | ||
union.push({ | ||
@@ -443,0 +465,0 @@ const: value, |
@@ -271,2 +271,10 @@ import { OpenApi } from "../OpenApi"; | ||
} | ||
if ( | ||
Array.isArray((schema as OpenApiV3.IJsonSchema.INumber).enum) && | ||
(schema as OpenApiV3.IJsonSchema.INumber).enum?.length && | ||
(schema as OpenApiV3.IJsonSchema.INumber).enum?.some( | ||
(e) => e === null, | ||
) | ||
) | ||
nullable.value ||= true; | ||
// UNION TYPE CASE | ||
@@ -284,4 +292,11 @@ if (TypeChecker.isAnyOf(schema)) schema.anyOf.forEach(visit); | ||
) | ||
if (schema.enum?.length) | ||
union.push(...schema.enum.map((value) => ({ const: value }))); | ||
if ( | ||
schema.enum?.length && | ||
schema.enum.filter((e) => e !== null).length | ||
) | ||
union.push( | ||
...schema.enum | ||
.filter((v) => v !== null) | ||
.map((value) => ({ const: value })), | ||
); | ||
else | ||
@@ -288,0 +303,0 @@ union.push({ |
@@ -279,2 +279,8 @@ import { OpenApi } from "../OpenApi"; | ||
} | ||
if ( | ||
Array.isArray((schema as SwaggerV2.IJsonSchema.INumber).enum) && | ||
(schema as SwaggerV2.IJsonSchema.INumber).enum?.length && | ||
(schema as SwaggerV2.IJsonSchema.INumber).enum?.some((e) => e === null) | ||
) | ||
nullable.value ||= true; | ||
// UNION TYPE CASE | ||
@@ -290,4 +296,8 @@ if (TypeChecker.isAnyOf(schema)) schema["x-anyOf"].forEach(visit); | ||
) | ||
if (schema.enum?.length) | ||
union.push(...schema.enum.map((value) => ({ const: value }))); | ||
if (schema.enum?.length && schema.enum.filter((e) => e !== null).length) | ||
union.push( | ||
...schema.enum | ||
.filter((v) => v !== null) | ||
.map((value) => ({ const: value })), | ||
); | ||
else | ||
@@ -294,0 +304,0 @@ union.push({ |
@@ -220,7 +220,7 @@ /** | ||
default?: boolean | null; | ||
enum?: boolean[]; | ||
enum?: Array<boolean | null>; | ||
} | ||
export interface IInteger extends __ISignificant<"integer"> { | ||
/** @type int64 */ default?: number | null; | ||
/** @type int64 */ enum?: number[]; | ||
/** @type int64 */ enum?: Array<number | null>; | ||
/** @type int64 */ minimum?: number; | ||
@@ -238,3 +238,3 @@ /** @type int64 */ maximum?: number; | ||
default?: number | null; | ||
enum?: number[]; | ||
enum?: Array<number | null>; | ||
minimum?: number; | ||
@@ -249,3 +249,3 @@ maximum?: number; | ||
default?: string | null; | ||
enum?: string[]; | ||
enum?: Array<string | null>; | ||
format?: | ||
@@ -252,0 +252,0 @@ | "binary" |
@@ -185,7 +185,7 @@ /** | ||
default?: boolean | null; | ||
enum?: boolean[]; | ||
enum?: Array<boolean | null>; | ||
} | ||
export interface IInteger extends __ISignificant<"integer"> { | ||
/** @type int64 */ default?: number | null; | ||
/** @type int64 */ enum?: number[]; | ||
/** @type int64 */ enum?: Array<number | null>; | ||
/** @type int64 */ minimum?: number; | ||
@@ -203,3 +203,3 @@ /** @type int64 */ maximum?: number; | ||
default?: number | null; | ||
enum?: number[]; | ||
enum?: Array<number | null>; | ||
minimum?: number; | ||
@@ -213,3 +213,3 @@ maximum?: number; | ||
default?: string | null; | ||
enum?: string[]; | ||
enum?: Array<string | null>; | ||
format?: | ||
@@ -216,0 +216,0 @@ | "binary" |
@@ -135,7 +135,7 @@ /** | ||
default?: boolean | null; | ||
enum?: boolean[]; | ||
enum?: Array<boolean | null>; | ||
} | ||
export interface IInteger extends __ISignificant<"integer"> { | ||
/** @type int64 */ default?: number | null; | ||
/** @type int64 */ enum?: number[]; | ||
/** @type int64 */ enum?: Array<number | null>; | ||
/** @type int64 */ minimum?: number; | ||
@@ -153,3 +153,3 @@ /** @type int64 */ maximum?: number; | ||
default?: number | null; | ||
enum?: number[]; | ||
enum?: Array<number | null>; | ||
minimum?: number; | ||
@@ -163,3 +163,3 @@ maximum?: number; | ||
default?: string | null; | ||
enum?: string[]; | ||
enum?: Array<string | null>; | ||
format?: | ||
@@ -166,0 +166,0 @@ | "binary" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
750883
11870
150