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

openapi-ts-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-ts-json-schema - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

dist/utils/convertOpenApiParameterToJsonSchema.d.ts

4

dist/utils/addSchemaToMetaData.js

@@ -23,2 +23,6 @@ "use strict";

const absoluteImportPath = node_path_1.default.join(absoluteDirName, schemaFileName);
// Convert components.parameters after convertOpenApiPathsParameters is called
if ((0, _1.isOpenApiParameter)(schema)) {
schema = (0, _1.convertOpenApiParameterToJsonSchema)(schema);
}
const metaInfo = {

@@ -25,0 +29,0 @@ id,

9

dist/utils/convertOpenApiPathsParameters.d.ts
import type { JSONSchema } from '../types';
/**
* Paths parameters field can only be found in:
* Convert parameters found in:
* - paths[path].parameters
* - paths[path][operation].parameters
*
* Parameters schema $refs are fully supported
* $ref parameters are currently always inlined
*
* OpenAPI parameters docs:
* https://swagger.io/docs/specification/describing-parameters/
*
* @NOTE The schema must be dereferenced since openapi-jsonschema-parameters
* doesn't handle $refs
* @NOTE The schema must be dereferenced since openapi-jsonschema-parameters doesn't handle $refs
*/
export declare function convertOpenApiPathsParameters(schema: JSONSchema): JSONSchema;

@@ -18,10 +18,13 @@ "use strict";

/**
* Paths parameters field can only be found in:
* Convert parameters found in:
* - paths[path].parameters
* - paths[path][operation].parameters
*
* Parameters schema $refs are fully supported
* $ref parameters are currently always inlined
*
* OpenAPI parameters docs:
* https://swagger.io/docs/specification/describing-parameters/
*
* @NOTE The schema must be dereferenced since openapi-jsonschema-parameters
* doesn't handle $refs
* @NOTE The schema must be dereferenced since openapi-jsonschema-parameters doesn't handle $refs
*/

@@ -28,0 +31,0 @@ function convertOpenApiPathsParameters(schema) {

@@ -10,9 +10,2 @@ "use strict";

const _1 = require("./");
const SECURITY_SCHEME_OBJECT_TYPES = [
'apiKey',
'http',
'mutualTLS',
'oauth2',
'openIdConnect',
];
function convertToJsonSchema(value) {

@@ -22,23 +15,22 @@ if (!(0, _1.isObject)(value)) {

}
if ('type' in value) {
/**
* Skip entities with "type" props defined and not a string
* (They should have already been converted, anyway)
* https://github.com/toomuchdesign/openapi-ts-json-schema/issues/211
*/
if (typeof value.type !== 'string') {
return value;
}
/**
* Skip security scheme object definitions
* https://swagger.io/specification/#security-scheme-object
*/
if (SECURITY_SCHEME_OBJECT_TYPES.includes(value.type)) {
return value;
}
/**
* Skip openAPI parameters since conversion causes data loss (they are not valid JSON schema)
* which makes impossible to aggregate them into JSON schema.
*
* Conversion is carried out later with "convertOpenApiPathsParameters"
*/
if ((0, _1.isOpenApiParameter)(value)) {
return value;
}
const schema = (0, openapi_schema_to_json_schema_1.fromSchema)(value);
// $schema is appended by @openapi-contrib/openapi-schema-to-json-schema
delete schema.$schema;
return schema;
try {
const schema = (0, openapi_schema_to_json_schema_1.fromSchema)(value, { strictMode: false });
// $schema is appended by @openapi-contrib/openapi-schema-to-json-schema
delete schema.$schema;
return schema;
}
catch (error) {
/* v8 ignore next 1 */
const errorMessage = error instanceof Error ? error.message : '';
throw new Error(`[openapi-ts-json-schema] OpenApi to JSON schema conversion failed: "${errorMessage}"`, { cause: value });
}
}

@@ -56,5 +48,9 @@ /**

return (0, map_obj_1.default)(schema, (key, value) => {
/**
* @NOTE map-obj only processes object values separately
*/
if (Array.isArray(value)) {
return [key, value.map((entry) => convertToJsonSchema(entry))];
}
// @NOTE map-obj transforms only arrays entries which are objects
return [key, convertToJsonSchema(value)];

@@ -61,0 +57,0 @@ }, { deep: true });

@@ -5,2 +5,3 @@ export { patchJsonSchema } from './makeTsJsonSchema/patchJsonSchema';

export { convertOpenApiToJsonSchema } from './convertOpenApiToJsonSchema';
export { convertOpenApiParameterToJsonSchema } from './convertOpenApiParameterToJsonSchema';
export { makeTsJsonSchemaFiles } from './makeTsJsonSchemaFiles';

@@ -16,2 +17,3 @@ export { parseId } from './parseId';

export { filenamify } from './filenamify';
export { isOpenApiParameter } from './isOpenApiParameter';
export { clearFolder } from './clearFolder';

@@ -18,0 +20,0 @@ export { makeRelativeModulePath } from './makeRelativeModulePath';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.saveFile = exports.formatTypeScript = exports.makeRelativeModulePath = exports.clearFolder = exports.filenamify = exports.isObject = exports.addSchemaToMetaData = exports.replacePlaceholdersWithImportedSchemas = exports.replaceInlinedRefsWithStringPlaceholder = exports.idToPlaceholder = exports.PLACEHOLDER_REGEX = exports.SCHEMA_ID_SYMBOL = exports.makeId = exports.refToId = exports.parseId = exports.makeTsJsonSchemaFiles = exports.convertOpenApiToJsonSchema = exports.convertOpenApiPathsParameters = exports.makeTsJsonSchema = exports.patchJsonSchema = void 0;
exports.saveFile = exports.formatTypeScript = exports.makeRelativeModulePath = exports.clearFolder = exports.isOpenApiParameter = exports.filenamify = exports.isObject = exports.addSchemaToMetaData = exports.replacePlaceholdersWithImportedSchemas = exports.replaceInlinedRefsWithStringPlaceholder = exports.idToPlaceholder = exports.PLACEHOLDER_REGEX = exports.SCHEMA_ID_SYMBOL = exports.makeId = exports.refToId = exports.parseId = exports.makeTsJsonSchemaFiles = exports.convertOpenApiParameterToJsonSchema = exports.convertOpenApiToJsonSchema = exports.convertOpenApiPathsParameters = exports.makeTsJsonSchema = exports.patchJsonSchema = void 0;
var patchJsonSchema_1 = require("./makeTsJsonSchema/patchJsonSchema");

@@ -12,2 +12,4 @@ Object.defineProperty(exports, "patchJsonSchema", { enumerable: true, get: function () { return patchJsonSchema_1.patchJsonSchema; } });

Object.defineProperty(exports, "convertOpenApiToJsonSchema", { enumerable: true, get: function () { return convertOpenApiToJsonSchema_1.convertOpenApiToJsonSchema; } });
var convertOpenApiParameterToJsonSchema_1 = require("./convertOpenApiParameterToJsonSchema");
Object.defineProperty(exports, "convertOpenApiParameterToJsonSchema", { enumerable: true, get: function () { return convertOpenApiParameterToJsonSchema_1.convertOpenApiParameterToJsonSchema; } });
var makeTsJsonSchemaFiles_1 = require("./makeTsJsonSchemaFiles");

@@ -35,2 +37,4 @@ Object.defineProperty(exports, "makeTsJsonSchemaFiles", { enumerable: true, get: function () { return makeTsJsonSchemaFiles_1.makeTsJsonSchemaFiles; } });

Object.defineProperty(exports, "filenamify", { enumerable: true, get: function () { return filenamify_1.filenamify; } });
var isOpenApiParameter_1 = require("./isOpenApiParameter");
Object.defineProperty(exports, "isOpenApiParameter", { enumerable: true, get: function () { return isOpenApiParameter_1.isOpenApiParameter; } });
var clearFolder_1 = require("./clearFolder");

@@ -37,0 +41,0 @@ Object.defineProperty(exports, "clearFolder", { enumerable: true, get: function () { return clearFolder_1.clearFolder; } });

@@ -32,2 +32,6 @@ "use strict";

return (0, map_obj_1.default)(schema, (key, value) => {
/**
* @NOTE map-obj transforms only arrays entries which are objects
* @NOTE map-obj only processes object values separately
*/
if (Array.isArray(value)) {

@@ -34,0 +38,0 @@ return [

@@ -13,7 +13,7 @@ "use strict";

const importedSchema = schemaMetaDataMap.get(id);
/* c8 ignore start */
/* v8 ignore start */
if (!importedSchema) {
throw new Error('[openapi-ts-json-schema] No matching schema found in "schemaMetaDataMap"');
}
/* c8 ignore stop */
/* v8 ignore stop */
// Evaluate imported schema relative path from current schema file

@@ -20,0 +20,0 @@ const importedSchemaRelativePath = (0, __1.makeRelativeModulePath)({

{
"name": "openapi-ts-json-schema",
"version": "0.10.0",
"version": "0.11.0",
"description": "OpenAPI to JSON schema generator with TypeScript in mind",

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

@@ -25,2 +25,4 @@ # openapi-ts-json-schema

`openapi-ts-json-schema` is currently in v0, which means it's still in its testing phase. I'm actively collecting feedback from users to improve its functionality and usability. **Please don't hesitate to open an issue if you encounter any problems or issues while using it.**
## Installation

@@ -92,2 +94,10 @@

`inline` and `import` are the more straightforward options, producing outputs that can be readily interpreted and resolved by both JavaScript engines and TypeScript type checkers. Nevertheless, a downside of these approaches is the absence of `$ref` references, causing entities initially designed as shareable (`$ref`-able) components (e.g. `components/schemas/Foo`) to lose their recognizability.
A significant limitation arises from consumer applications being unable to automatically expose an OpenAPI schema with proper shared `components/schemas` definitions, as everything becomes inlined.
One potential solution involves preserving `$ref`s using the `keep` option and crafting a plugin (as discussed in the [Plugins](#plugins) section) to facilitate the interpretation of `$ref` information by JavaScript and TypeScript. The implementation logic of this plugin hinges on the framework through which the generated schemas will be consumed.
`openapi-ts-json-schema` ships with a [`fastify` plugin](/docs/plugins.md) available out of the box, enabling seamless integration of schema types through [json-schema-to-ts](https://github.com/ThomasAribart/json-schema-to-ts).
#### Circular `$ref`s

@@ -156,2 +166,3 @@

- Consider implementing an option to inline circular $refs with a configurable nesting level
- Handle `$ref` parameters according to `refHandler` options

@@ -158,0 +169,0 @@ [ci-badge]: https://github.com/toomuchdesign/openapi-ts-json-schema/actions/workflows/ci.yml/badge.svg

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