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

openapi-jsonschema-parameters

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-jsonschema-parameters - npm Package Compare versions

Comparing version 1.2.0 to 7.0.0

dist/tsconfig.tsbuildinfo

2

CHANGELOG.md

@@ -9,3 +9,3 @@ # openapi-jsonschema-parameters Changelog

### Aded
- Added support for 'examples' (fixes #513) (#514)
- Added support for 'examples' (fixes #513) (#514)

@@ -12,0 +12,0 @@ ### Fixed

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
exports.__esModule = true;
exports.convertParametersToJSONSchema = void 0;
function convertParametersToJSONSchema(parameters) {

@@ -34,2 +46,3 @@ var parametersSchema = {};

'enum',
'examples',
'exclusiveMaximum',

@@ -49,3 +62,3 @@ 'exclusiveMinimum',

'type',
'uniqueItems'
'uniqueItems',
];

@@ -63,15 +76,51 @@ function copyValidationKeywords(src) {

}
function handleNullable(params, paramSchema, param) {
if (params.nullable) {
if (param.hasOwnProperty('examples')) {
paramSchema.examples = param.examples;
function handleNullable(schema) {
return { anyOf: [schema, { type: 'null' }] };
}
var SUBSCHEMA_KEYWORDS = [
'additionalItems',
'items',
'contains',
'additionalProperties',
'propertyNames',
'not',
];
var SUBSCHEMA_ARRAY_KEYWORDS = ['items', 'allOf', 'anyOf', 'oneOf'];
var SUBSCHEMA_OBJECT_KEYWORDS = [
'definitions',
'properties',
'patternProperties',
'dependencies',
];
function handleNullableSchema(schema) {
if (typeof schema !== 'object' || schema === null) {
return schema;
}
var newSchema = __assign({}, schema);
SUBSCHEMA_KEYWORDS.forEach(function (keyword) {
if (typeof schema[keyword] === 'object' &&
schema[keyword] !== null &&
!Array.isArray(schema[keyword])) {
newSchema[keyword] = handleNullableSchema(schema[keyword]);
}
return {
anyOf: [paramSchema, { type: 'null' }]
};
});
SUBSCHEMA_ARRAY_KEYWORDS.forEach(function (keyword) {
if (Array.isArray(schema[keyword])) {
newSchema[keyword] = schema[keyword].map(handleNullableSchema);
}
});
SUBSCHEMA_OBJECT_KEYWORDS.forEach(function (keyword) {
if (typeof schema[keyword] === 'object' && schema[keyword] !== null) {
newSchema[keyword] = __assign({}, schema[keyword]);
Object.keys(schema[keyword]).forEach(function (prop) {
newSchema[keyword][prop] = handleNullableSchema(schema[keyword][prop]);
});
}
});
delete newSchema.$ref;
if (schema.nullable) {
delete newSchema.nullable;
return handleNullable(newSchema);
}
if (param.hasOwnProperty('examples')) {
paramSchema.examples = param.examples;
}
return paramSchema;
return newSchema;
}

@@ -93,4 +142,19 @@ function getBodySchema(parameters) {

params.forEach(function (param) {
var paramSchema = copyValidationKeywords(param.schema || param);
schema.properties[param.name] = handleNullable(param.schema || param, paramSchema, param);
var paramSchema;
if ('schema' in param) {
paramSchema = handleNullableSchema(param.schema);
if ('examples' in param) {
paramSchema.examples = getExamples(param.examples);
}
schema.properties[param.name] = paramSchema;
}
else {
paramSchema = copyValidationKeywords(param);
if ('examples' in paramSchema) {
paramSchema.examples = getExamples(paramSchema.examples);
}
schema.properties[param.name] = param.nullable
? handleNullable(paramSchema)
: paramSchema;
}
});

@@ -104,2 +168,5 @@ schema.required = getRequiredParams(params);

}
function getExamples(exampleSchema) {
return Object.keys(exampleSchema).map(function (k) { return exampleSchema[k].value; });
}
function byIn(str) {

@@ -106,0 +173,0 @@ return function (param) { return param["in"] === str && param.type !== 'file'; };

{
"name": "openapi-jsonschema-parameters",
"version": "1.2.0",
"version": "7.0.0",
"description": "Converts openapi parameters to a jsonschema format.",

@@ -8,7 +8,6 @@ "main": "./dist/index.js",

"scripts": {
"cover": "nyc",
"prepare": "tsc",
"test-watch": "tsc && mocha --watch-extensions ts -w",
"test": "mocha",
"travis-test": "npm run cover"
"cover": "../../bin/nyc",
"prepare": "../../bin/tsc",
"test-watch": "../../bin/tsc && ../../bin/mocha --watch-extensions ts -w",
"test": "../../bin/mocha"
},

@@ -30,4 +29,5 @@ "repository": "https://github.com/kogosoftwarellc/open-api/tree/master/packages/openapi-jsonschema-parameters",

"dependencies": {
"openapi-types": "1.3.5"
}
"openapi-types": "^7.0.0"
},
"gitHead": "f5ec9959092d45193e9b6464501c143cb17aaaf7"
}

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