Socket
Socket
Sign inDemoInstall

openapi-snippet

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-snippet - npm Package Compare versions

Comparing version 0.9.3 to 0.10.0

test/parameter_example_swagger.json

55

openapi-to-har.js

@@ -155,2 +155,30 @@ /**

/**
* Gets an object describing the the paremeters (header or query) in a given OpenAPI method
* @param {Object} param parameter values to use in snippet
* @param {Object} values Optional: query parameter values to use in the snippet if present
* @returns {Object} Object describing the parameters in a given OpenAPI method
*/
const getParameterValues = function (param, values) {
let value =
'SOME_' + (param.type || param.schema.type).toUpperCase() + '_VALUE';
if (values && typeof values[param.name] !== 'undefined') {
value =
values[param.name] + ''; /* adding a empty string to convert to string */
} else if (typeof param.default !== 'undefined') {
value = param.default + '';
} else if (
typeof param.schema !== 'undefined' &&
typeof param.schema.example !== 'undefined'
) {
value = param.schema.example + '';
} else if (typeof param.example !== 'undefined') {
value = param.example + '';
}
return {
name: param.name,
value: value,
};
};
/**
* Get array of objects describing the query parameters for a path and method

@@ -195,20 +223,3 @@ * pair described in the given OpenAPI document.

) {
let value =
'SOME_' + (param.type || param.schema.type).toUpperCase() + '_VALUE';
if (typeof values[param.name] !== 'undefined') {
value =
values[param.name] +
''; /* adding a empty string to convert to string */
} else if (typeof param.default !== 'undefined') {
value = param.default + '';
} else if (
typeof param.schema !== 'undefined' &&
typeof param.schema.example !== 'undefined'
) {
value = param.schema.example + '';
}
queryStrings.push({
name: param.name,
value: value,
});
queryStrings.push(getParameterValues(param, values));
}

@@ -307,9 +318,3 @@ }

) {
headers.push({
name: param.name,
value:
'SOME_' +
(param.type || param.schema.type).toUpperCase() +
'_VALUE',
});
headers.push(getParameterValues(param));
}

@@ -316,0 +321,0 @@ }

{
"name": "openapi-snippet",
"version": "0.9.3",
"version": "0.10.0",
"description": "Generates code snippets from Open API (previously Swagger) documents.",

@@ -5,0 +5,0 @@ "repository": {

@@ -14,2 +14,3 @@ 'use strict';

const ParameterSchemaReferenceAPI = require('./parameter_schema_reference');
const ParameterExampleReferenceAPI = require('./parameter_example_swagger.json');

@@ -185,1 +186,15 @@ test('Getting snippets should not result in error or undefined', function (t) {

});
test('Testing the case when an example is provided, use the provided example value', function (t) {
t.plan(2);
const result = OpenAPISnippets.getEndpointSnippets(
ParameterExampleReferenceAPI,
'/pets',
'get',
['node_request']
);
const snippet = result.snippets[0].content;
t.true(/ {tags: 'dog,cat', limit: '10'}/.test(snippet));
t.false(/SOME_INTEGER_VALUE/.test(snippet));
t.end();
});
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