Socket
Socket
Sign inDemoInstall

@samchon/openapi

Package Overview
Dependencies
Maintainers
1
Versions
79
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 0.1.2 to 0.1.3

18

lib/internal/OpenApiV3_1Converter.js

@@ -129,4 +129,9 @@ "use strict";

const attribute = Object.assign({ title: input.title, description: input.description }, Object.fromEntries(Object.entries(input).filter(([key, value]) => key.startsWith("x-") && value !== undefined)));
const nullable = { value: false };
const visit = (schema) => {
var _a, _b, _c, _d, _e, _f, _g;
// NULLABLE PROPERTY
if (schema.nullable ===
true)
nullable.value || (nullable.value = true);
// MIXED TYPE CASE

@@ -246,3 +251,3 @@ if (TypeChecker.isMixed(schema)) {

// OBJECT TYPE CASE
else if (TypeChecker.isObject(schema)) {
else if (TypeChecker.isObject(schema))
union.push(Object.assign(Object.assign({}, schema), {

@@ -261,3 +266,7 @@ properties: schema.properties

}));
}
else if (TypeChecker.isRecursiveReference(schema))
union.push(Object.assign(Object.assign({}, schema), {
$ref: schema.$recursiveRef,
$recursiveRef: undefined,
}));
// THE OTHERS

@@ -268,2 +277,5 @@ else

visit(input);
if (nullable.value === true &&
!union.some((e) => e.type === "null"))
union.push({ type: "null" });
return Object.assign(Object.assign({}, (union.length === 0

@@ -284,2 +296,4 @@ ? { type: undefined }

TypeChecker.isReference = (schema) => schema.$ref !== undefined;
TypeChecker.isRecursiveReference = (schema) => schema.$recursiveRef !==
undefined;
TypeChecker.isOneOf = (schema) => schema.oneOf !== undefined;

@@ -286,0 +300,0 @@ TypeChecker.isAnyOf = (schema) => schema.anyOf !== undefined;

@@ -120,2 +120,3 @@ "use strict";

var _a;
// NULLABLE PROPERTY
if (schema.nullable === true)

@@ -122,0 +123,0 @@ nullable.value || (nullable.value = true);

@@ -7,2 +7,29 @@ import { OpenApiV3 } from "./OpenApiV3";

*
* `OpenApi` is a namespace containing functions and interfaces for emended
* OpenAPI v3.1 specification. The keyword "emended" means that `OpenApi` is
* not a direct OpenAPI v3.1 specification ({@link OpenApiV3_1}), but a little
* bit shrinked to remove ambiguous and duplicated expressions of OpenAPI v3.1
* for the convenience of `typia` and `nestia`.
*
* 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`) to be simple and easy to implement.
*
* 1. `type: ["string", "null"]`
* 2. `type: "string", nullable: true`
* 3. `oneOf: [{ type: "string" }, { type: "null" }]`
*
* Here is the entire list of differences between OpenAPI v3.1 and emended `OpenApi`.
*
* - Operation
* - Merged {@link OpenApiV3_1.IPathItem.parameters} to {@link OpenApi.IOperation.parameters}
* - Resolved {@link OpenApi.IJsonSchema.IReference references} of {@link OpenApiV3_1.IOperation} mebers
* - JSON Schema
* - Decomposed mixed type: {@link OpenApiV3_1.IJsonSchema.IMixed}
* - Resolved nullable property: {@link OpenApiV3_1.IJsonSchema.__ISignificant.nullable}
* - Array type utilizes only single {@link OpenAPI.IJsonSchema.IArray.items}
* - Tuple type utilizes only {@link OpenApi.IJsonSchema.ITuple.prefixItems}
* - Merged {@link OpenApiV3_1.IJsonSchema.IAnyOf} to {@link OpenApi.IJsonSchema.IOneOf}
* - Merged {@link OpenApiV3_1.IJsonSchema.IRecursiveReference} to {@link OpenApi.IJsonSchema.IReference}
*
* @author Jeongho Nam - https://github.com/samchon

@@ -148,3 +175,2 @@ */

interface ITuple extends __ISignificant<"array"> {
items: never;
prefixItems: IJsonSchema[];

@@ -151,0 +177,0 @@ additionalItems: boolean | IJsonSchema;

@@ -13,2 +13,29 @@ "use strict";

*
* `OpenApi` is a namespace containing functions and interfaces for emended
* OpenAPI v3.1 specification. The keyword "emended" means that `OpenApi` is
* not a direct OpenAPI v3.1 specification ({@link OpenApiV3_1}), but a little
* bit shrinked to remove ambiguous and duplicated expressions of OpenAPI v3.1
* for the convenience of `typia` and `nestia`.
*
* 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`) to be simple and easy to implement.
*
* 1. `type: ["string", "null"]`
* 2. `type: "string", nullable: true`
* 3. `oneOf: [{ type: "string" }, { type: "null" }]`
*
* Here is the entire list of differences between OpenAPI v3.1 and emended `OpenApi`.
*
* - Operation
* - Merged {@link OpenApiV3_1.IPathItem.parameters} to {@link OpenApi.IOperation.parameters}
* - Resolved {@link OpenApi.IJsonSchema.IReference references} of {@link OpenApiV3_1.IOperation} mebers
* - JSON Schema
* - Decomposed mixed type: {@link OpenApiV3_1.IJsonSchema.IMixed}
* - Resolved nullable property: {@link OpenApiV3_1.IJsonSchema.__ISignificant.nullable}
* - Array type utilizes only single {@link OpenAPI.IJsonSchema.IArray.items}
* - Tuple type utilizes only {@link OpenApi.IJsonSchema.ITuple.prefixItems}
* - Merged {@link OpenApiV3_1.IJsonSchema.IAnyOf} to {@link OpenApi.IJsonSchema.IOneOf}
* - Merged {@link OpenApiV3_1.IJsonSchema.IRecursiveReference} to {@link OpenApi.IJsonSchema.IReference}
*
* @author Jeongho Nam - https://github.com/samchon

@@ -15,0 +42,0 @@ */

@@ -181,4 +181,8 @@ /**

}
interface IRecursiveReference extends __IAttribute {
$recursiveRef: string;
}
interface __ISignificant<Type extends string> extends __IAttribute {
type: Type;
nullable?: boolean;
}

@@ -185,0 +189,0 @@ interface __IAttribute {

2

package.json
{
"name": "@samchon/openapi",
"version": "0.1.2",
"version": "0.1.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -0,1 +1,6 @@

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/openapi/blob/master/LICENSE)
[![npm version](https://img.shields.io/npm/v/@samchon/openapi.svg)](https://www.npmjs.com/package/@samchon/openapi)
[![Downloads](https://img.shields.io/npm/dm/@samchon/openapi.svg)](https://www.npmjs.com/package/@samchon/openapi)
[![Build Status](https://github.com/samchon/openapi/workflows/build/badge.svg)](https://github.com/samchon/openapi/actions?query=workflow%3Abuild)
OpenAPI definitions and converters for [typia](https://github.com/samchon/typia) and [nestia](https://github.com/samchon/nestia).

@@ -227,3 +227,11 @@ import { OpenApi } from "../OpenApi";

};
const nullable: { value: boolean } = { value: false };
const visit = (schema: OpenApiV3_1.IJsonSchema): void => {
// NULLABLE PROPERTY
if (
(schema as OpenApiV3_1.IJsonSchema.__ISignificant<any>).nullable ===
true
)
nullable.value ||= true;
// MIXED TYPE CASE

@@ -411,3 +419,3 @@ if (TypeChecker.isMixed(schema)) {

// OBJECT TYPE CASE
else if (TypeChecker.isObject(schema)) {
else if (TypeChecker.isObject(schema))
union.push({

@@ -433,3 +441,10 @@ ...schema,

});
}
else if (TypeChecker.isRecursiveReference(schema))
union.push({
...schema,
...{
$ref: schema.$recursiveRef,
$recursiveRef: undefined,
},
});
// THE OTHERS

@@ -440,2 +455,7 @@ else union.push(schema);

visit(input);
if (
nullable.value === true &&
!union.some((e) => (e as OpenApi.IJsonSchema.INull).type === "null")
)
union.push({ type: "null" });
return {

@@ -484,2 +504,7 @@ ...(union.length === 0

(schema as OpenApiV3_1.IJsonSchema.IReference).$ref !== undefined;
export const isRecursiveReference = (
schema: OpenApiV3_1.IJsonSchema,
): schema is OpenApiV3_1.IJsonSchema.IRecursiveReference =>
(schema as OpenApiV3_1.IJsonSchema.IRecursiveReference).$recursiveRef !==
undefined;
export const isOneOf = (

@@ -486,0 +511,0 @@ schema: OpenApiV3_1.IJsonSchema,

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

const visit = (schema: OpenApiV3.IJsonSchema): void => {
// NULLABLE PROPERTY
if (

@@ -209,0 +210,0 @@ (schema as OpenApiV3.IJsonSchema.__ISignificant<any>).nullable === true

@@ -11,2 +11,29 @@ import { OpenApiV3 } from "./OpenApiV3";

*
* `OpenApi` is a namespace containing functions and interfaces for emended
* OpenAPI v3.1 specification. The keyword "emended" means that `OpenApi` is
* not a direct OpenAPI v3.1 specification ({@link OpenApiV3_1}), but a little
* bit shrinked to remove ambiguous and duplicated expressions of OpenAPI v3.1
* for the convenience of `typia` and `nestia`.
*
* 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`) to be simple and easy to implement.
*
* 1. `type: ["string", "null"]`
* 2. `type: "string", nullable: true`
* 3. `oneOf: [{ type: "string" }, { type: "null" }]`
*
* Here is the entire list of differences between OpenAPI v3.1 and emended `OpenApi`.
*
* - Operation
* - Merged {@link OpenApiV3_1.IPathItem.parameters} to {@link OpenApi.IOperation.parameters}
* - Resolved {@link OpenApi.IJsonSchema.IReference references} of {@link OpenApiV3_1.IOperation} mebers
* - JSON Schema
* - Decomposed mixed type: {@link OpenApiV3_1.IJsonSchema.IMixed}
* - Resolved nullable property: {@link OpenApiV3_1.IJsonSchema.__ISignificant.nullable}
* - Array type utilizes only single {@link OpenAPI.IJsonSchema.IArray.items}
* - Tuple type utilizes only {@link OpenApi.IJsonSchema.ITuple.prefixItems}
* - Merged {@link OpenApiV3_1.IJsonSchema.IAnyOf} to {@link OpenApi.IJsonSchema.IOneOf}
* - Merged {@link OpenApiV3_1.IJsonSchema.IRecursiveReference} to {@link OpenApi.IJsonSchema.IReference}
*
* @author Jeongho Nam - https://github.com/samchon

@@ -224,3 +251,2 @@ */

export interface ITuple extends __ISignificant<"array"> {
items: never;
prefixItems: IJsonSchema[];

@@ -227,0 +253,0 @@ additionalItems: boolean | IJsonSchema;

@@ -281,5 +281,9 @@ /**

}
export interface IRecursiveReference extends __IAttribute {
$recursiveRef: string;
}
export interface __ISignificant<Type extends string> extends __IAttribute {
type: Type;
nullable?: boolean;
}

@@ -286,0 +290,0 @@ export interface __IAttribute {

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