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

swagger2openapi

Package Overview
Dependencies
Maintainers
1
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger2openapi - npm Package Compare versions

Comparing version 2.11.14 to 2.11.15

1

docs/options.md

@@ -32,2 +32,3 @@ # Options documentation

quiet|Boolean|Input|Command-line flag used by `testRunner`
refmap|Object|Internal|Used as a mapping between old and new `$ref`s.
resolve|Boolean|Input|Flag to enable resolution of external `$ref`s.

@@ -34,0 +35,0 @@ stop|Boolean|Input|Command-line flag used by `testRunner`

@@ -182,2 +182,5 @@ // @ts-check

if (target === false) throwOrWarn('direct $ref not found '+obj[key],obj,options)
else if (options.refmap[obj[key]]) {
obj[key] = options.refmap[obj[key]];
}
else {

@@ -208,8 +211,12 @@ // we use a heuristic to determine what kind of thing is being referenced

let newRef = '#/components/'+type+'/'+prefix+suffix;
let refSuffix = '';
if (type === 'examples') {
target = { value: target };
newRef += '/value';
refSuffix = '/value';
}
jptr.jptr(options.openapi,newRef,target);
obj[key] = newRef;
options.refmap[obj[key]] = newRef+refSuffix;
obj[key] = newRef+refSuffix;
}

@@ -232,2 +239,12 @@ }

/*
* This has to happen as a separate pass because multiple $refs may point
* through elements of the same path
*/
function dedupeRefs(openapi, options) {
for (let ref in options.refmap) {
jptr.jptr(openapi,ref,{ $ref: options.refmap[ref] });
}
}
function processSecurity(securityObject) {

@@ -934,3 +951,5 @@ for (let s in securityObject) {

// fix all $refs to their new locations (and potentially new names)
options.refmap = {};
common.recurse(openapi, { payload: { options: options } }, fixupRefs);
dedupeRefs(openapi,options);

@@ -937,0 +956,0 @@ for (let p in openapi.components.parameters) {

@@ -23,3 +23,3 @@ 'use strict';

function lint(objectName,object,options) {
function lint(objectName,object,key,options) {
for (let r in rules) {

@@ -82,2 +82,9 @@ let rule = rules[r];

}
if (rule.notEndWith) {
let property = (rule.notEndWith.property === '$key') ? key : object[rule.notEndWith.property];
if (typeof object[property] === 'string') {
object[property].should.not.endWith(rule.notEndWith.value);
}
}
// speccy defines maxLength rule
}

@@ -84,0 +91,0 @@ }

6

linter/rules.json

@@ -12,5 +12,5 @@ {

"object": "parameter",
"enabled": false,
"enabled": true,
"description": "parameter names should match RFC6570",
"pattern": { "property": "name", "value": "" }
"pattern": { "property": "name", "value": "^[A-Za-z0-9?()]+$" }
},

@@ -42,3 +42,3 @@ "3": {

"object": "openapi",
"enabled": false,
"enabled": true,
"description": "path item keys should not end with a slash",

@@ -45,0 +45,0 @@ "notEndWith": { "property": "$key", "value": "/" }

{
"name": "swagger2openapi",
"version": "2.11.14",
"version": "2.11.15",
"description": "Convert Swagger 2.0 definitions to OpenApi 3.0 and validate",

@@ -35,7 +35,7 @@ "main": "index.js",

"js-yaml": "^3.6.1",
"node-fetch": "^1.6.3",
"node-fetch": "^2.0.0",
"node-readfiles": "^0.2.0",
"reftools": "0.0.20",
"should": "^13.0.1",
"yargs": "^10.0.3"
"yargs": "^11.0.0"
},

@@ -42,0 +42,0 @@ "keywords": [

@@ -112,5 +112,8 @@ # swagger2openapi

### Regression tests
Regression tests (thanks @domharrington) live in the `/test` directory and can be run with `npx mocha`. Each sub-directory should contain an input `swagger.yaml` file, an expected output `openapi.yaml` file and an optional `options.yaml` file. You can put private test cases in sub-directories starting with an underscore character.
## License
[BSD-3-Clause](LICENSE) except the `openapi-3.0.json` schema, which is taken from the [OpenAPI-Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json) and the alternative `gnostic-3.0.json` schema, which is originally from [Google Gnostic](https://github.com/googleapis/gnostic/blob/master/OpenAPIv3/openapi-3.0.json). Both of these are licensed under the [Apache-2](http://www.apache.org/licenses/LICENSE-2.0) license.
[BSD-3-Clause](LICENSE) except the `openapi-3.0.json` schema, which is taken from the [OpenAPI-Specification](https://github.com/OAI/OpenAPI-Specification/blob/49e784d7b7800da8732103aa3ac56bc7ccde5cfb/schemas/v3.0/schema.yaml) and the alternative `gnostic-3.0.json` schema, which is originally from [Google Gnostic](https://github.com/googleapis/gnostic/blob/master/OpenAPIv3/openapi-3.0.json). Both of these are licensed under the [Apache-2](http://www.apache.org/licenses/LICENSE-2.0) license.

@@ -206,2 +206,6 @@ #!/usr/bin/env node

if ((options.source.indexOf('!')>=0) && (options.source.indexOf('swagger.')>=0)) {
expectFailure = true;
}
if (file.startsWith('http')) {

@@ -208,0 +212,0 @@ swagger2openapi.convertUrl(file, common.clone(options))

@@ -85,3 +85,3 @@ // @ts-check

if (prop) contextAppend(state.options, prop);
if (state.options.lint) state.options.linter('schema',schema,state.options);
if (state.options.lint) state.options.linter('schema',schema,'schema',state.options);
schema.should.be.an.Object();

@@ -91,3 +91,3 @@

schema.$ref.should.be.a.String();
if (state.options.lint) state.options.linter('reference',schema,state.options);
if (state.options.lint) state.options.linter('reference',schema,'$ref',state.options);
if (prop) state.options.context.pop();

@@ -188,3 +188,4 @@ return; // all other properties SHALL be ignored

}
if (schema.patternProperties) {
schema.should.not.have.property('patternProperties');
/*if (schema.patternProperties) {
schema.patternProperties.should.be.an.Object();

@@ -199,3 +200,3 @@ for (let prop in schema.patternProperties) {

}
}
}*/
if (typeof schema.enum !== 'undefined') {

@@ -330,3 +331,3 @@ schema.enum.should.be.an.Array();

}
if (options.lint) options.linter('example',ex,options);
if (options.lint) options.linter('example',ex,'example',options);
}

@@ -359,3 +360,3 @@

if (ex.$ref) {
if (options.lint) options.linter('reference',ex,options);
if (options.lint) options.linter('reference',ex,'$ref',options);
}

@@ -400,3 +401,3 @@ else {

}
if (options.lint) options.linter('serverVariable',server.variables[v],options);
if (options.lint) options.linter('serverVariable',server.variables[v],v,options);
options.context.pop();

@@ -407,3 +408,3 @@ }

}
if (options.lint) options.linter('server',server,options);
if (options.lint) options.linter('server',server,'server',options);
}

@@ -448,3 +449,3 @@

}
if (options.lint) options.linter('link',link,options);
if (options.lint) options.linter('link',link,'link',options);
}

@@ -456,3 +457,3 @@

should(header.$ref).be.type('string');
if (options.lint) options.linter('reference',header,options);
if (options.lint) options.linter('reference',header,'$ref',options);
header = common.resolveInternal(openapi, ref);

@@ -493,3 +494,3 @@ should(header).not.be.exactly(false, 'Cannot resolve reference: ' + ref);

}
if (options.lint) options.linter('header',header,options);
if (options.lint) options.linter('header',header,'header',options);
}

@@ -501,3 +502,3 @@

should(response.$ref).be.type('string');
if (options.lint) options.linter('reference',response,options);
if (options.lint) options.linter('reference',response,'$ref',options);
response = common.resolveInternal(openapi, ref);

@@ -538,3 +539,3 @@ should(response).not.be.exactly(false, 'Cannot resolve reference: ' + ref);

}
if (options.lint) options.linter('response',response,options);
if (options.lint) options.linter('response',response,'response',options);
}

@@ -546,3 +547,3 @@

should(param.$ref).be.type('string');
if (options.lint) options.linter('reference',param,options);
if (options.lint) options.linter('reference',param,'$ref',options);
var ref = param.$ref;

@@ -638,3 +639,3 @@ param = common.resolveInternal(openapi, ref);

}
if (options.lint) options.linter('parameter',param,options);
if (options.lint) options.linter('parameter',param,index,options);
options.context.pop();

@@ -651,2 +652,3 @@ return param;

let pathParameters = {};
if (typeof pathItem.parameters !== 'undefined') should(pathItem.parameters).be.an.Array();
for (let p in pathItem.parameters) {

@@ -671,3 +673,3 @@ contextAppend(options, 'parameters');

should(op.startsWith('#/')).equal(false,'PathItem $refs must be external ('+op+')');
if (options.lint) options.linter('reference',op,options);
if (options.lint) options.linter('reference',op,'$ref',options);
}

@@ -739,3 +741,4 @@ else if (o === 'parameters') {

if (op.parameters) {
if (typeof op.parameters !== 'undefined') {
should(op.parameters).be.an.Array();
let localPathParameters = common.clone(pathParameters);

@@ -778,3 +781,3 @@ let opParameters = {};

if (callback.$ref) {
if (options.lint) options.linter('reference',callback,options);
if (options.lint) options.linter('reference',callback,'$ref',options);
}

@@ -797,7 +800,7 @@ else {

}
if (options.lint) options.linter('operation',op,options);
if (options.lint) options.linter('operation',op,o,options);
}
options.context.pop();
}
if (options.lint) options.linter('pathItem',pathItem,options);
if (options.lint) options.linter('pathItem',pathItem,path,options);
return true;

@@ -820,3 +823,3 @@ }

}
if (options.lint) options.linter('security',security,options);
if (options.lint) options.linter('security',security,'security',options);
options.context.pop();

@@ -869,3 +872,3 @@ }

}
if (options.lint) options.linter('license',openapi.info.license,options);
if (options.lint) options.linter('license',openapi.info.license,'license',options);
options.context.pop();

@@ -887,3 +890,3 @@ }

}
if (options.lint) options.linter('contact',openapi.info.contact,options);
if (options.lint) options.linter('contact',openapi.info.contact,'contact',options);
for (let k in openapi.info.contact) {

@@ -896,3 +899,3 @@ if (!k.startsWith('x-')) {

}
if (options.lint) options.linter('info',openapi.info,options);
if (options.lint) options.linter('info',openapi.info,'info',options);
options.context.pop();

@@ -929,3 +932,3 @@

}
if (options.lint) options.linter('tag',tag,options);
if (options.lint) options.linter('tag',tag,tag.name,options); // should be index
options.context.pop();

@@ -1137,3 +1140,3 @@ }

if (ex.$ref) {
if (options.lint) options.linter('reference',ex,options);
if (options.lint) options.linter('reference',ex,'$ref',options);
}

@@ -1156,3 +1159,3 @@ else {

if (cb.$ref) {
if (options.lint) options.linter('reference',cb,options);
if (options.lint) options.linter('reference',cb,'$ref',options);
}

@@ -1181,3 +1184,3 @@ else {

if (link.$ref) {
if (options.lint) options.linter('reference',link,options);
if (options.lint) options.linter('reference',link,'$ref',options);
}

@@ -1199,3 +1202,3 @@ else {

options.valid = !options.expectFailure;
if (options.lint) options.linter('openapi',openapi,options);
if (options.lint) options.linter('openapi',openapi,'',options);
if (callback) callback(null, options);

@@ -1202,0 +1205,0 @@ return options.valid;

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