core-types-json-schema
Advanced tools
Comparing version 1.7.0 to 2.0.0
@@ -1,7 +0,7 @@ | ||
export type { ConvertCoreTypesToJsonSchemaOptions } from './lib/core-types-to-json-schema'; | ||
export { decorateSchema, convertCoreTypesToJsonSchema, } from './lib/core-types-to-json-schema'; | ||
export type { ConvertJsonSchemaToCoreTypesOptions } from './lib/json-schema-to-core-types'; | ||
export { convertJsonSchemaToCoreTypes } from './lib/json-schema-to-core-types'; | ||
export { CoreTypesToOpenApiOptions, convertCoreTypesToOpenApi, convertOpenApiToCoreTypes, } from './lib/open-api'; | ||
export type { ConvertCoreTypesToJsonSchemaOptions, } from './lib/core-types-to-json-schema.js'; | ||
export { decorateSchema, convertCoreTypesToJsonSchema, } from './lib/core-types-to-json-schema.js'; | ||
export type { ConvertJsonSchemaToCoreTypesOptions, } from './lib/json-schema-to-core-types.js'; | ||
export { convertJsonSchemaToCoreTypes, } from './lib/json-schema-to-core-types.js'; | ||
export { CoreTypesToOpenApiOptions, convertCoreTypesToOpenApi, convertOpenApiToCoreTypes, } from './lib/open-api.js'; | ||
export { OpenApiSchemaTypeDefinition, jsonSchemaDocumentToOpenApi, openApiToJsonSchema, } from 'openapi-json-schema'; | ||
export * as helpers from './lib/annotations'; | ||
export * as helpers from './lib/annotations.js'; |
@@ -1,15 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.helpers = exports.openApiToJsonSchema = exports.jsonSchemaDocumentToOpenApi = exports.convertOpenApiToCoreTypes = exports.convertCoreTypesToOpenApi = exports.convertJsonSchemaToCoreTypes = exports.convertCoreTypesToJsonSchema = exports.decorateSchema = void 0; | ||
var core_types_to_json_schema_1 = require("./lib/core-types-to-json-schema"); | ||
Object.defineProperty(exports, "decorateSchema", { enumerable: true, get: function () { return core_types_to_json_schema_1.decorateSchema; } }); | ||
Object.defineProperty(exports, "convertCoreTypesToJsonSchema", { enumerable: true, get: function () { return core_types_to_json_schema_1.convertCoreTypesToJsonSchema; } }); | ||
var json_schema_to_core_types_1 = require("./lib/json-schema-to-core-types"); | ||
Object.defineProperty(exports, "convertJsonSchemaToCoreTypes", { enumerable: true, get: function () { return json_schema_to_core_types_1.convertJsonSchemaToCoreTypes; } }); | ||
var open_api_1 = require("./lib/open-api"); | ||
Object.defineProperty(exports, "convertCoreTypesToOpenApi", { enumerable: true, get: function () { return open_api_1.convertCoreTypesToOpenApi; } }); | ||
Object.defineProperty(exports, "convertOpenApiToCoreTypes", { enumerable: true, get: function () { return open_api_1.convertOpenApiToCoreTypes; } }); | ||
var openapi_json_schema_1 = require("openapi-json-schema"); | ||
Object.defineProperty(exports, "jsonSchemaDocumentToOpenApi", { enumerable: true, get: function () { return openapi_json_schema_1.jsonSchemaDocumentToOpenApi; } }); | ||
Object.defineProperty(exports, "openApiToJsonSchema", { enumerable: true, get: function () { return openapi_json_schema_1.openApiToJsonSchema; } }); | ||
exports.helpers = require("./lib/annotations"); | ||
export { decorateSchema, convertCoreTypesToJsonSchema, } from './lib/core-types-to-json-schema.js'; | ||
export { convertJsonSchemaToCoreTypes, } from './lib/json-schema-to-core-types.js'; | ||
export { convertCoreTypesToOpenApi, convertOpenApiToCoreTypes, } from './lib/open-api.js'; | ||
export { jsonSchemaDocumentToOpenApi, openApiToJsonSchema, } from 'openapi-json-schema'; | ||
export * as helpers from './lib/annotations.js'; |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.annotateCoreTypes = exports.annotateJsonSchema = void 0; | ||
const core_types_1 = require("core-types"); | ||
function annotateJsonSchema(node, jsonSchema) { | ||
import { ensureArray, stringify, } from 'core-types'; | ||
export function annotateJsonSchema(node, jsonSchema) { | ||
const description = !node.description && !node.see | ||
@@ -18,6 +15,4 @@ ? undefined | ||
} | ||
exports.annotateJsonSchema = annotateJsonSchema; | ||
function annotateCoreTypes(node, jsonSchema) { | ||
var _a; | ||
const { description, see } = splitDescriptionAndSee((_a = jsonSchema.description) !== null && _a !== void 0 ? _a : ''); | ||
export function annotateCoreTypes(node, jsonSchema) { | ||
const { description, see } = splitDescriptionAndSee(jsonSchema.description ?? ''); | ||
const annotations = { | ||
@@ -28,6 +23,6 @@ ...(jsonSchema.title | ||
...(jsonSchema.default | ||
? { default: (0, core_types_1.stringify)(jsonSchema.default) } | ||
? { default: stringify(jsonSchema.default) } | ||
: {}), | ||
...(jsonSchema.examples | ||
? { examples: (0, core_types_1.stringify)(jsonSchema.examples) } | ||
? { examples: stringify(jsonSchema.examples) } | ||
: {}), | ||
@@ -42,8 +37,7 @@ ...(jsonSchema.$comment | ||
} | ||
exports.annotateCoreTypes = annotateCoreTypes; | ||
function mergeDescriptionAndSee(description, see) { | ||
const seeAsString = () => (0, core_types_1.ensureArray)(see) | ||
const seeAsString = () => ensureArray(see) | ||
.map(see => `@see ${see}`) | ||
.join("\n"); | ||
if (description && (see === null || see === void 0 ? void 0 : see.length)) { | ||
if (description && see?.length) { | ||
return description + "\n\n" + seeAsString(); | ||
@@ -54,3 +48,3 @@ } | ||
function splitDescriptionAndSee(data) { | ||
const lines = (data !== null && data !== void 0 ? data : '').split("\n"); | ||
const lines = (data ?? '').split("\n"); | ||
const see = []; | ||
@@ -57,0 +51,0 @@ while (lines.length > 0 |
@@ -1,11 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertCoreTypesToJsonSchema = exports.decorateSchema = void 0; | ||
const openapi_json_schema_1 = require("openapi-json-schema"); | ||
const core_types_1 = require("core-types"); | ||
const annotations_1 = require("./annotations"); | ||
function decorateSchema(schema, { filename, sourceFilename, userPackage, userPackageUrl, }, packageName = 'core-types-json-schema', packageUrl = 'https://github.com/grantila/core-types-json-schema') { | ||
var _a, _b; | ||
import { encodeRefNameJsonSchema } from 'openapi-json-schema'; | ||
import { UnsupportedError } from 'core-types'; | ||
import { annotateJsonSchema as annotate } from "./annotations.js"; | ||
export function decorateSchema(schema, { filename, sourceFilename, userPackage, userPackageUrl, }, packageName = 'core-types-json-schema', packageUrl = 'https://github.com/grantila/core-types-json-schema') { | ||
if (typeof filename !== 'undefined') | ||
(_a = schema.$id) !== null && _a !== void 0 ? _a : (schema.$id = filename); | ||
schema.$id ?? (schema.$id = filename); | ||
const onbehalf = !userPackage && !userPackageUrl | ||
@@ -19,15 +15,14 @@ ? '' | ||
: ''; | ||
(_b = schema.$comment) !== null && _b !== void 0 ? _b : (schema.$comment = `Generated${fromFilenameComment} by ` + | ||
schema.$comment ?? (schema.$comment = `Generated${fromFilenameComment} by ` + | ||
`${packageName} (${packageUrl})` + | ||
(onbehalf ? ` on behalf of ${onbehalf}` : '')); | ||
} | ||
exports.decorateSchema = decorateSchema; | ||
function convertCoreTypesToJsonSchema(doc, options) { | ||
export function convertCoreTypesToJsonSchema(doc, options) { | ||
const { version, types } = doc; | ||
if (version !== 1) | ||
throw new core_types_1.UnsupportedError(`core-types version ${version} not supported`); | ||
throw new UnsupportedError(`core-types version ${version} not supported`); | ||
const schema = { | ||
definitions: Object.fromEntries(types.map(node => [node.name, toJsonSchema(node)])) | ||
}; | ||
decorateSchema(schema, options !== null && options !== void 0 ? options : {}); | ||
decorateSchema(schema, options ?? {}); | ||
return { | ||
@@ -39,3 +34,2 @@ data: schema, | ||
} | ||
exports.convertCoreTypesToJsonSchema = convertCoreTypesToJsonSchema; | ||
function isOnlyType(node) { | ||
@@ -52,3 +46,3 @@ const keys = Object.keys(node).sort(); | ||
const anyOf = node.or.map(subNode => toJsonSchema(subNode)); | ||
const ret = (0, annotations_1.annotateJsonSchema)(node, { anyOf }); | ||
const ret = annotate(node, { anyOf }); | ||
if (anyOf.length > 1 && !anyOf.some(n => !isOnlyType(n))) { | ||
@@ -62,15 +56,15 @@ delete ret.anyOf; | ||
if (node.type === 'any') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, {})); | ||
return annotate(node, constEnum(node, {})); | ||
else if (node.type === 'null') | ||
return (0, annotations_1.annotateJsonSchema)(node, { type: 'null' }); | ||
return annotate(node, { type: 'null' }); | ||
else if (node.type === 'boolean') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { type: 'boolean' })); | ||
return annotate(node, constEnum(node, { type: 'boolean' })); | ||
else if (node.type === 'string') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { type: 'string' })); | ||
return annotate(node, constEnum(node, { type: 'string' })); | ||
else if (node.type === 'number') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { type: 'number' })); | ||
return annotate(node, constEnum(node, { type: 'number' })); | ||
else if (node.type === 'integer') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { type: 'integer' })); | ||
return annotate(node, constEnum(node, { type: 'integer' })); | ||
else if (node.type === 'and') | ||
return (0, annotations_1.annotateJsonSchema)(node, { | ||
return annotate(node, { | ||
allOf: node.and.map(subNode => toJsonSchema(subNode)), | ||
@@ -86,3 +80,3 @@ }); | ||
.map(prop => [prop, toJsonSchema(node.properties[prop].node)])); | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { | ||
return annotate(node, constEnum(node, { | ||
type: 'object', | ||
@@ -101,3 +95,3 @@ ...(allKeys.length > 0 ? { properties } : {}), | ||
else if (node.type === 'array') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { | ||
return annotate(node, constEnum(node, { | ||
type: 'array', | ||
@@ -107,3 +101,3 @@ items: toJsonSchema(node.elementType), | ||
else if (node.type === 'tuple') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { | ||
return annotate(node, constEnum(node, { | ||
type: 'array', | ||
@@ -119,7 +113,7 @@ items: node.elementTypes.map(item => toJsonSchema(item)), | ||
else if (node.type === 'ref') | ||
return (0, annotations_1.annotateJsonSchema)(node, constEnum(node, { | ||
$ref: (0, openapi_json_schema_1.encodeRefNameJsonSchema)(node.ref), | ||
return annotate(node, constEnum(node, { | ||
$ref: encodeRefNameJsonSchema(node.ref), | ||
})); | ||
else | ||
throw new core_types_1.UnsupportedError(`core-types node of type ${node.type} not supported`, node); | ||
throw new UnsupportedError(`core-types node of type ${node.type} not supported`, node); | ||
} | ||
@@ -126,0 +120,0 @@ function constEnum(node, jsonSchema) { |
import type { JSONSchema7 } from "json-schema"; | ||
import type { NodeDocument, ConversionResult } from "core-types"; | ||
declare type AdditionalProperties = Exclude<JSONSchema7['additionalProperties'], undefined>; | ||
type AdditionalProperties = Exclude<JSONSchema7['additionalProperties'], undefined>; | ||
export interface ConvertJsonSchemaToCoreTypesOptions { | ||
@@ -5,0 +5,0 @@ /** |
@@ -1,13 +0,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.complexProps = exports.convertJsonSchemaToCoreTypes = void 0; | ||
const jsonpos_1 = require("jsonpos"); | ||
const openapi_json_schema_1 = require("openapi-json-schema"); | ||
const core_types_1 = require("core-types"); | ||
const annotations_1 = require("./annotations"); | ||
import { getParsedByString, getParsedByObject, getLocation } from 'jsonpos'; | ||
import { decodeRefNameJsonSchema } from 'openapi-json-schema'; | ||
import { UnsupportedError, MalformedTypeError, isEqual, intersection, union, ensureArray, } from "core-types"; | ||
import { annotateCoreTypes as annotate } from "./annotations.js"; | ||
const walkDown = (ctx, child) => ({ ...ctx, path: [...ctx.path, child] }); | ||
function convertJsonSchemaToCoreTypes(schema, options = {}) { | ||
export function convertJsonSchemaToCoreTypes(schema, options = {}) { | ||
const parsed = typeof schema === 'string' | ||
? (0, jsonpos_1.getAstByString)(schema) | ||
: (0, jsonpos_1.getAstByObject)(schema); | ||
? getParsedByString(schema) | ||
: getParsedByObject(schema); | ||
const { json } = parsed; | ||
@@ -18,6 +15,5 @@ const { definitions } = json; | ||
types: Object | ||
.keys(definitions !== null && definitions !== void 0 ? definitions : {}) | ||
.keys(definitions ?? {}) | ||
.map(name => { | ||
var _a; | ||
const typeSchema = (definitions !== null && definitions !== void 0 ? definitions : {})[name]; | ||
const typeSchema = (definitions ?? {})[name]; | ||
const ctx = { | ||
@@ -27,3 +23,3 @@ locByPath() { | ||
path: this.path, | ||
loc: (0, jsonpos_1.getLocation)(parsed, { dataPath: this.path, markIdentifier: true }), | ||
loc: getLocation(parsed, { path: this.path, markIdentifier: true }), | ||
}; | ||
@@ -37,6 +33,6 @@ }, | ||
if (!meta.loc) | ||
meta.loc = (0, jsonpos_1.getLocation)(parsed, { dataPath: this.path, markIdentifier: true }); | ||
throw new core_types_1.UnsupportedError(message, meta); | ||
meta.loc = getLocation(parsed, { path: this.path, markIdentifier: true }); | ||
throw new UnsupportedError(message, meta); | ||
}, | ||
defaultAdditionalProperties: (_a = options.defaultAdditionalProperties) !== null && _a !== void 0 ? _a : true, | ||
defaultAdditionalProperties: options.defaultAdditionalProperties ?? true, | ||
}; | ||
@@ -54,4 +50,3 @@ const node = fromSchema(typeSchema, ctx); | ||
} | ||
exports.convertJsonSchemaToCoreTypes = convertJsonSchemaToCoreTypes; | ||
exports.complexProps = new Set(['anyOf', 'allOf', 'oneOf', 'then', 'else']); | ||
export const complexProps = new Set(['anyOf', 'allOf', 'oneOf', 'then', 'else']); | ||
/** | ||
@@ -87,4 +82,3 @@ * If a schema has an anyOf, allOf or oneOf, or (if-)then-else, the parent type | ||
const mergeDown = (container, subSchema) => { | ||
var _a, _b, _c, _d, _e; | ||
const isOnlyOrSame = (a, b) => !(a && b && !(0, core_types_1.isEqual)(a, b)); | ||
const isOnlyOrSame = (a, b) => !(a && b && !isEqual(a, b)); | ||
if (!isOnlyOrSame($ref, subSchema.$ref)) | ||
@@ -102,5 +96,5 @@ ctx.throwUnsupportedError(`Cannot have $ref in a node *and* in its '${container}'`, { | ||
else { | ||
const newEnum = (0, core_types_1.intersection)(_enum, subSchema.enum); | ||
const newEnum = intersection(_enum, subSchema.enum); | ||
if (newEnum.length === 0) | ||
throw new core_types_1.MalformedTypeError("Cannot merge types with non-intersecting enums", { | ||
throw new MalformedTypeError("Cannot merge types with non-intersecting enums", { | ||
path: ctx.path, | ||
@@ -116,4 +110,4 @@ blob: { | ||
if (subSchema.const !== undefined) { | ||
if ((0, core_types_1.isEqual)(_const, subSchema.const)) | ||
throw new core_types_1.MalformedTypeError("Cannot merge types with mismatching const", { | ||
if (isEqual(_const, subSchema.const)) | ||
throw new MalformedTypeError("Cannot merge types with mismatching const", { | ||
path: ctx.path, | ||
@@ -128,11 +122,11 @@ blob: { | ||
} | ||
subSchema.items = (_a = subSchema.items) !== null && _a !== void 0 ? _a : items; | ||
subSchema.items = subSchema.items ?? items; | ||
subSchema.additionalItems = | ||
(_b = subSchema.additionalItems) !== null && _b !== void 0 ? _b : additionalItems; | ||
subSchema.additionalItems ?? additionalItems; | ||
if (required !== undefined || subSchema.required !== undefined) | ||
subSchema.required = | ||
(0, core_types_1.union)((_c = subSchema.required) !== null && _c !== void 0 ? _c : [], required !== null && required !== void 0 ? required : []); | ||
union(subSchema.required ?? [], required ?? []); | ||
if ((typeof properties === 'undefined') !== | ||
(typeof subSchema.properties === 'undefined')) | ||
(_d = subSchema.properties) !== null && _d !== void 0 ? _d : (subSchema.properties = properties); | ||
subSchema.properties ?? (subSchema.properties = properties); | ||
else if (typeof properties !== 'undefined') { | ||
@@ -144,3 +138,3 @@ const propA = properties; | ||
const keysB = Object.keys(propB); | ||
const combinedKeys = (0, core_types_1.union)(keysA, keysB); | ||
const combinedKeys = union(keysA, keysB); | ||
const ret = {}; | ||
@@ -159,3 +153,3 @@ combinedKeys.forEach(key => { | ||
(typeof subSchema.additionalProperties === 'undefined')) | ||
(_e = subSchema.additionalProperties) !== null && _e !== void 0 ? _e : (subSchema.additionalProperties = additionalProperties); | ||
subSchema.additionalProperties ?? (subSchema.additionalProperties = additionalProperties); | ||
else if (typeof additionalProperties !== 'undefined') { | ||
@@ -240,3 +234,3 @@ // Merge | ||
return typeof schema === 'object' && | ||
Object.keys(schema).some(prop => exports.complexProps.has(prop)); | ||
Object.keys(schema).some(prop => complexProps.has(prop)); | ||
} | ||
@@ -250,3 +244,3 @@ function fromSchema(schema, ctx) { | ||
ctx.throwUnsupportedError(`Internal error`, { blob: { schema } }); | ||
const makeRefType = (ref) => ({ type: 'ref', ref: (0, openapi_json_schema_1.decodeRefNameJsonSchema)(ref) }); | ||
const makeRefType = (ref) => ({ type: 'ref', ref: decodeRefNameJsonSchema(ref) }); | ||
const wrapRefType = (node) => schema.$ref === undefined | ||
@@ -269,3 +263,3 @@ ? node | ||
} | ||
const types = (0, core_types_1.ensureArray)(schema.type) | ||
const types = ensureArray(schema.type) | ||
.map(type => fromSchemaAndType(schema, type, constEnum, ctx)); | ||
@@ -277,12 +271,11 @@ if (types.length === 1) | ||
function fromSchemaAndType(schema, type, constEnum, ctx) { | ||
var _a, _b, _c, _d; | ||
if (isPrimitiveType(type)) { | ||
if (type === 'null') | ||
return (0, annotations_1.annotateCoreTypes)({ type: 'null' }, schema); | ||
return annotate({ type: 'null' }, schema); | ||
else | ||
return (0, annotations_1.annotateCoreTypes)({ type, ...constEnum }, schema); | ||
return annotate({ type, ...constEnum }, schema); | ||
} | ||
else if (type === 'array') { | ||
if (Array.isArray(schema.items)) { | ||
return (0, annotations_1.annotateCoreTypes)({ | ||
return annotate({ | ||
type: 'tuple', | ||
@@ -295,3 +288,3 @@ elementTypes: schema.items.map(item => fromSchema(item, walkDown(ctx, 'items'))), | ||
: fromSchema(schema.additionalItems, walkDown(ctx, 'additionalItems')), | ||
minItems: (_a = schema.minItems) !== null && _a !== void 0 ? _a : 0, | ||
minItems: schema.minItems ?? 0, | ||
...constEnum, | ||
@@ -301,3 +294,3 @@ }, schema); | ||
else if (schema.items === false) { | ||
return (0, annotations_1.annotateCoreTypes)({ | ||
return annotate({ | ||
type: 'tuple', | ||
@@ -311,3 +304,3 @@ elementTypes: [], | ||
else { | ||
return (0, annotations_1.annotateCoreTypes)({ | ||
return annotate({ | ||
type: 'array', | ||
@@ -323,7 +316,7 @@ elementType: (typeof schema.items === 'undefined' || | ||
else if (type === 'object') { | ||
const required = new Set((_b = schema.required) !== null && _b !== void 0 ? _b : []); | ||
const additionalProperties = (_c = schema.additionalProperties) !== null && _c !== void 0 ? _c : ctx.defaultAdditionalProperties; | ||
return (0, annotations_1.annotateCoreTypes)({ | ||
const required = new Set(schema.required ?? []); | ||
const additionalProperties = schema.additionalProperties ?? ctx.defaultAdditionalProperties; | ||
return annotate({ | ||
type: 'object', | ||
properties: Object.fromEntries(Object.entries((_d = schema.properties) !== null && _d !== void 0 ? _d : {}) | ||
properties: Object.fromEntries(Object.entries(schema.properties ?? {}) | ||
.map(([prop, value]) => [ | ||
@@ -330,0 +323,0 @@ prop, |
import { ConversionResult, NodeDocument } from 'core-types'; | ||
import { PartialOpenApiSchema, JsonSchemaDocumentToOpenApiOptions } from 'openapi-json-schema'; | ||
import { ConvertCoreTypesToJsonSchemaOptions } from './core-types-to-json-schema'; | ||
export declare type CoreTypesToOpenApiOptions = JsonSchemaDocumentToOpenApiOptions & ConvertCoreTypesToJsonSchemaOptions; | ||
import { ConvertCoreTypesToJsonSchemaOptions } from './core-types-to-json-schema.js'; | ||
export type CoreTypesToOpenApiOptions = JsonSchemaDocumentToOpenApiOptions & ConvertCoreTypesToJsonSchemaOptions; | ||
export declare function convertCoreTypesToOpenApi(doc: NodeDocument, options: CoreTypesToOpenApiOptions): ConversionResult<PartialOpenApiSchema>; | ||
export declare function convertOpenApiToCoreTypes(schema: PartialOpenApiSchema | string): ConversionResult<NodeDocument>; |
@@ -1,22 +0,17 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertOpenApiToCoreTypes = exports.convertCoreTypesToOpenApi = void 0; | ||
const openapi_json_schema_1 = require("openapi-json-schema"); | ||
const core_types_to_json_schema_1 = require("./core-types-to-json-schema"); | ||
const json_schema_to_core_types_1 = require("./json-schema-to-core-types"); | ||
function convertCoreTypesToOpenApi(doc, options) { | ||
const { data: jsonSchema, ...rest } = (0, core_types_to_json_schema_1.convertCoreTypesToJsonSchema)(doc, options); | ||
import { jsonSchemaDocumentToOpenApi, openApiToJsonSchema, } from 'openapi-json-schema'; | ||
import { convertCoreTypesToJsonSchema, } from './core-types-to-json-schema.js'; | ||
import { convertJsonSchemaToCoreTypes } from './json-schema-to-core-types.js'; | ||
export function convertCoreTypesToOpenApi(doc, options) { | ||
const { data: jsonSchema, ...rest } = convertCoreTypesToJsonSchema(doc, options); | ||
return { | ||
...rest, | ||
data: (0, openapi_json_schema_1.jsonSchemaDocumentToOpenApi)(jsonSchema, options) | ||
data: jsonSchemaDocumentToOpenApi(jsonSchema, options) | ||
}; | ||
} | ||
exports.convertCoreTypesToOpenApi = convertCoreTypesToOpenApi; | ||
function convertOpenApiToCoreTypes(schema) { | ||
export function convertOpenApiToCoreTypes(schema) { | ||
// TODO: Implement JSON AST parsing and a source map separately to | ||
// the tree (src path -> target path) | ||
schema = typeof schema === 'string' ? JSON.parse(schema) : schema; | ||
const jsonSchema = (0, openapi_json_schema_1.openApiToJsonSchema)(schema); | ||
return (0, json_schema_to_core_types_1.convertJsonSchemaToCoreTypes)(jsonSchema); | ||
const jsonSchema = openApiToJsonSchema(schema); | ||
return convertJsonSchemaToCoreTypes(jsonSchema); | ||
} | ||
exports.convertOpenApiToCoreTypes = convertOpenApiToCoreTypes; |
{ | ||
"name": "core-types-json-schema", | ||
"version": "1.7.0", | ||
"version": "2.0.0", | ||
"description": "core-types ⬌ JSON Schema conversion", | ||
@@ -14,4 +14,6 @@ "author": "Gustaf Räntilä", | ||
"directories": {}, | ||
"type": "module", | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14.13.1 || >=16.0.0" | ||
}, | ||
@@ -23,3 +25,3 @@ "files": [ | ||
"build": "rimraf dist && tsc -p tsconfig.prod.json", | ||
"test": "jest", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest", | ||
"cz": "git-cz" | ||
@@ -42,13 +44,15 @@ }, | ||
"@types/json-schema": "^7.0.11", | ||
"core-types": "^1.10.0", | ||
"jsonpos": "^1.1.0", | ||
"core-types": "^2.0.1", | ||
"jsonpos": "^4.1.2", | ||
"openapi-json-schema": "^1.1.3" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^28.1.2", | ||
"@babel/preset-env": "^7.20.2", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@types/jest": "^29.4.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"jest": "^28.1.1", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^28.0.5", | ||
"typescript": "^4.7.4" | ||
"jest": "^29.4.1", | ||
"rimraf": "^4.1.2", | ||
"ts-jest-resolver": "^2.0.0", | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -59,3 +63,4 @@ "config": { | ||
} | ||
} | ||
}, | ||
"packageManager": "yarn@3.2.4" | ||
} |
@@ -5,3 +5,2 @@ [![npm version][npm-image]][npm-url] | ||
[![coverage status][coverage-image]][coverage-url] | ||
[![Language grade: JavaScript][lgtm-image]][lgtm-url] | ||
[![Node.JS version][node-version]][node-url] | ||
@@ -105,8 +104,6 @@ | ||
[downloads-image]: https://img.shields.io/npm/dm/core-types-json-schema.svg | ||
[build-image]: https://img.shields.io/github/workflow/status/grantila/core-types-json-schema/Master.svg | ||
[build-image]: https://img.shields.io/github/actions/workflow/status/grantila/core-types-json-schema/master.yml?branch=master | ||
[build-url]: https://github.com/grantila/core-types-json-schema/actions?query=workflow%3AMaster | ||
[coverage-image]: https://coveralls.io/repos/github/grantila/core-types-json-schema/badge.svg?branch=master | ||
[coverage-url]: https://coveralls.io/github/grantila/core-types-json-schema?branch=master | ||
[lgtm-image]: https://img.shields.io/lgtm/grade/javascript/g/grantila/core-types-json-schema.svg?logo=lgtm&logoWidth=18 | ||
[lgtm-url]: https://lgtm.com/projects/g/grantila/core-types-json-schema/context:javascript | ||
[node-version]: https://img.shields.io/node/v/core-types-json-schema | ||
@@ -113,0 +110,0 @@ [node-url]: https://nodejs.org/en/ |
Yes
30725
8
558
114
+ Addedcore-types@2.0.1(transitive)
+ Addedjson-cst@1.2.0(transitive)
+ Addedjson-lexer@1.2.0(transitive)
+ Addedjsonpos@4.1.2(transitive)
- Removedcode-error-fragment@0.0.230(transitive)
- Removedcore-types@1.10.0(transitive)
- Removedgrapheme-splitter@1.0.4(transitive)
- Removedjson-to-ast@2.1.0(transitive)
- Removedjsonpos@1.1.0(transitive)
Updatedcore-types@^2.0.1
Updatedjsonpos@^4.1.2