Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse required query params only #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openapi-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const parseParametersToQuery = function (openApi, parameters, values) {
}
}
}
if (typeof param.in !== 'undefined' && param.in.toLowerCase() === 'query') {
if (typeof param.in !== 'undefined' && param.in.toLowerCase() === 'query' && param.required) {
// param.name is a safe key, because the spec defines
// that name MUST be unique
queryStrings[param.name] = getParameterValues(param, values);
Expand Down
2 changes: 1 addition & 1 deletion test/instagram_swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"format": "int32",
"in": "query",
"name": "distance",
"required": false,
"required": true,
"type": "integer"
},
{
Expand Down
20 changes: 15 additions & 5 deletions test/parameter_example_swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"required": true,
"style": "form",
"example": ["dog", "cat"],
"schema": {
Expand All @@ -45,7 +45,7 @@
"in": "query",
"description": "maximum number of results to return",
"example": 10,
"required": false,
"required": true,
"schema": {
"type": "integer",
"format": "int32"
Expand Down Expand Up @@ -82,7 +82,7 @@
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"required": true,
"style": "form",
"example": ["dog", "cat"],
"schema": {
Expand All @@ -97,11 +97,21 @@
"in": "query",
"description": "maximum number of results to return",
"example": 10,
"required": false,
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "length",
"in": "query",
"description": "length property",
"example": "12",
"required": false,
"schema": {
"type": "integer"
}
}
],
"get": {
Expand Down Expand Up @@ -152,7 +162,7 @@
"name": "id",
"in": "query",
"description": "A comma-seperated list of species IDs",
"required": false,
"required": true,
"example": [1, 2],
"schema": {
"type": "array",
Expand Down
1 change: 1 addition & 0 deletions test/parameter_schema_reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"in": "query",
"name": "pet",
"description": "Pet to add to the store",
"required": true,
"schema": {
"$ref": "#/components/schemas/NewPet"
}
Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,17 @@ test('Testing the application/x-www-form-urlencoded example case', function (t)
t.match(snippet, /.*--data 'secret=secret\+example\+value'.*/);
t.end();
});

test('Testing only required parameters are parsed', function (t) {
t.plan(2);
const result = OpenAPISnippets.getEndpointSnippets(
ParameterExampleReferenceAPI,
'/animals',
'get',
['node_request']
);
const snippet = result.snippets[0].content;
t.true(/ {tags: 'dog,cat', limit: '10'}/.test(snippet));
t.false(/length: 12/.test(snippet));
t.end();
});
4 changes: 2 additions & 2 deletions test/watson_alchemy_language_swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@
"description": "Your API key",
"in": "query",
"name": "apikey",
"required": false,
"required": true,
"type": "string"
},
"content_type": {
Expand Down Expand Up @@ -1586,7 +1586,7 @@
"enum": [0, 1],
"in": "query",
"name": "showSourceText",
"required": false,
"required": true,
"type": "integer"
},
"sourceText_formData": {
Expand Down