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

@openapi-contrib/json-schema-to-openapi-schema

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openapi-contrib/json-schema-to-openapi-schema - npm Package Compare versions

Comparing version 2.2.4 to 2.2.5

4

dist/cjs/index.d.ts

@@ -1,5 +0,5 @@

import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
import type { JSONSchema4 } from 'json-schema';
import type { Options } from './types.js';
import type { OpenAPIV3 } from 'openapi-types';
declare const convert: <T extends JSONSchema = JSONSchema>(schema: T, options?: Options) => Promise<OpenAPIV3.Document>;
declare const convert: <T extends object = JSONSchema4>(schema: T, options?: Options) => Promise<OpenAPIV3.Document>;
export default convert;

@@ -45,3 +45,3 @@ "use strict";

}
else if (Array.isArray(def)) {
if (Array.isArray(def)) {
// if it's an array, we might want to reconstruct the type;

@@ -96,2 +96,3 @@ const typeArr = def;

schema = convertDependencies(schema);
schema = convertNullable(schema);
schema = rewriteIfThenElse(schema);

@@ -177,2 +178,20 @@ schema = rewriteExclusiveMinMax(schema);

}
function convertNullable(schema) {
for (const key of ['oneOf', 'anyOf']) {
const schemas = schema[key];
if (!Array.isArray(schemas)) {
return schema;
}
const hasNullable = schemas.some((item) => item.type === 'null');
if (!hasNullable) {
return schema;
}
const filtered = schemas.filter((l) => l.type !== 'null');
for (const schemaEntry of filtered) {
schemaEntry.nullable = true;
}
schema[key] = filtered;
}
return schema;
}
function convertTypes(schema) {

@@ -179,0 +198,0 @@ if (typeof schema !== 'object') {

import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
import type $RefParser from '@apidevtools/json-schema-ref-parser';
export declare type addPrefixToObject = {
export type addPrefixToObject = {
[K in keyof JSONSchema as `x-${K}`]: JSONSchema[K];

@@ -12,4 +12,4 @@ };

}
declare type ExtendedJSONSchema = addPrefixToObject & JSONSchema;
export declare type SchemaType = ExtendedJSONSchema & {
type ExtendedJSONSchema = addPrefixToObject & JSONSchema;
export type SchemaType = ExtendedJSONSchema & {
example?: JSONSchema['examples'][number];

@@ -19,3 +19,3 @@ 'x-patternProperties'?: JSONSchema['patternProperties'];

};
export declare type SchemaTypeKeys = keyof SchemaType;
export type SchemaTypeKeys = keyof SchemaType;
export {};

@@ -1,5 +0,5 @@

import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
import type { JSONSchema4 } from 'json-schema';
import type { Options } from './types.js';
import type { OpenAPIV3 } from 'openapi-types';
declare const convert: <T extends JSONSchema = JSONSchema>(schema: T, options?: Options) => Promise<OpenAPIV3.Document>;
declare const convert: <T extends object = JSONSchema4>(schema: T, options?: Options) => Promise<OpenAPIV3.Document>;
export default convert;

@@ -38,3 +38,3 @@ import { Walker } from 'json-schema-walker';

}
else if (Array.isArray(def)) {
if (Array.isArray(def)) {
// if it's an array, we might want to reconstruct the type;

@@ -88,2 +88,3 @@ const typeArr = def;

schema = convertDependencies(schema);
schema = convertNullable(schema);
schema = rewriteIfThenElse(schema);

@@ -169,2 +170,20 @@ schema = rewriteExclusiveMinMax(schema);

}
function convertNullable(schema) {
for (const key of ['oneOf', 'anyOf']) {
const schemas = schema[key];
if (!Array.isArray(schemas)) {
return schema;
}
const hasNullable = schemas.some((item) => item.type === 'null');
if (!hasNullable) {
return schema;
}
const filtered = schemas.filter((l) => l.type !== 'null');
for (const schemaEntry of filtered) {
schemaEntry.nullable = true;
}
schema[key] = filtered;
}
return schema;
}
function convertTypes(schema) {

@@ -171,0 +190,0 @@ if (typeof schema !== 'object') {

import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
import type $RefParser from '@apidevtools/json-schema-ref-parser';
export declare type addPrefixToObject = {
export type addPrefixToObject = {
[K in keyof JSONSchema as `x-${K}`]: JSONSchema[K];

@@ -12,4 +12,4 @@ };

}
declare type ExtendedJSONSchema = addPrefixToObject & JSONSchema;
export declare type SchemaType = ExtendedJSONSchema & {
type ExtendedJSONSchema = addPrefixToObject & JSONSchema;
export type SchemaType = ExtendedJSONSchema & {
example?: JSONSchema['examples'][number];

@@ -19,3 +19,3 @@ 'x-patternProperties'?: JSONSchema['patternProperties'];

};
export declare type SchemaTypeKeys = keyof SchemaType;
export type SchemaTypeKeys = keyof SchemaType;
export {};
{
"name": "@openapi-contrib/json-schema-to-openapi-schema",
"version": "2.2.4",
"version": "2.2.5",
"description": "Converts a JSON Schema to OpenAPI Schema Object",

@@ -39,3 +39,3 @@ "bin": {

"json-schema-walker": "^1.1.0",
"openapi-types": "^12.0.2",
"openapi-types": "^12.1.0",
"yargs": "^17.6.2"

@@ -45,13 +45,13 @@ },

"@types/json-schema": "^7.0.11",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"c8": "^7.12.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
"nock": "^13.2.9",
"prettier": "^2.7.1",
"typescript": "^4.8.4",
"vitest": "^0.24.5"
"nock": "^13.3.0",
"prettier": "^2.8.3",
"typescript": "^4.9.4",
"vitest": "^0.28.1"
},

@@ -58,0 +58,0 @@ "prettier": {

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