openapi-json-schema
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -17,5 +17,4 @@ import type { JSONSchema7 } from 'json-schema'; | ||
license?: import("./types").OpenApiLicenseContact | undefined; | ||
} | { | ||
title: string; | ||
version: string; | ||
'x-id'?: string | undefined; | ||
'x-comment'?: string | undefined; | ||
}; | ||
@@ -22,0 +21,0 @@ paths: Record<string, unknown>; |
@@ -7,5 +7,15 @@ "use strict"; | ||
function decorateOpenApi(schema, { title, version, schemaVersion = '3.0.0', }) { | ||
const info = { title, version }; | ||
if (schema.$id) { | ||
info['x-id'] = schema.$id; | ||
delete schema.$id; | ||
} | ||
if (schema.$comment) { | ||
info['x-comment'] = schema.$comment; | ||
delete schema.$comment; | ||
} | ||
delete schema.$schema; | ||
return { | ||
openapi: schemaVersion, | ||
info: { title, version }, | ||
info, | ||
paths: {}, | ||
@@ -12,0 +22,0 @@ ...schema, |
@@ -18,2 +18,6 @@ "use strict"; | ||
const decorateType = (t, type) => (type === "any" || !type) ? t : ({ ...t, type }); | ||
if (typeof schema.const !== 'undefined') { | ||
rest.enum = [schema.const]; | ||
delete rest.const; | ||
} | ||
const decorateNullable = (t) => nullable ? ({ ...t, nullable }) : t; | ||
@@ -20,0 +24,0 @@ if (Array.isArray(type)) { |
@@ -11,2 +11,4 @@ import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'; | ||
license?: OpenApiLicenseContact; | ||
'x-id'?: string; | ||
'x-comment'?: string; | ||
}; | ||
@@ -13,0 +15,0 @@ paths: Record<string, unknown>; |
{ | ||
"name": "openapi-json-schema", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Minimalistic OpenAPI 3 ⬌ JSON Schema (draft 7) conversion", | ||
@@ -5,0 +5,0 @@ "author": "Gustaf Räntilä", |
@@ -15,2 +15,4 @@ [![npm version][npm-image]][npm-url] | ||
* `$ref`'s being converted `#/definitions` <-> `#/components/schemas` | ||
* `const` ➡ `enum` when converting to OpenAPI | ||
* `$id`/`$comment` ➡ `info['x-id']`/`info['x-comment']` when converting to OpenAPI | ||
* *PR's are welcome.* | ||
@@ -17,0 +19,0 @@ * JSON `$ref`s are not resolved. |
18885
346
52