Skip to content

Commit

Permalink
Merge pull request #163 from trojs/feature/no-example-value-in-response
Browse files Browse the repository at this point in the history
Feature/no example value in response
  • Loading branch information
w3nl authored Oct 4, 2024
2 parents fe36be4 + 370a565 commit 242e355
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 21.x, 22.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
Expand Down
119 changes: 60 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@trojs/openapi-server",
"description": "OpenAPI Server",
"version": "1.4.0",
"version": "1.5.0",
"author": {
"name": "Pieter Wigboldus",
"url": "https://trojs.org/"
Expand Down
13 changes: 7 additions & 6 deletions src/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export const parseParams = ({ query, spec }) =>
spec
.map((parameter) => {
const { name, schema } = parameter;
const {
type,
default: defaultValue,
example: exampleValue,
} = schema;
const { type, default: defaultValue } = schema;
const Type = types[type];
const paramName = query?.[name];

if (!paramName && defaultValue) {
return { name, value: defaultValue };
}

if (!paramName) {
return { name, value: defaultValue ?? exampleValue };
return undefined;
}

if (Type === Boolean) {
Expand All @@ -33,6 +33,7 @@ export const parseParams = ({ query, spec }) =>
const value = new Type(paramName).valueOf();
return { name, value };
})
.filter(Boolean)
.reduce((acc, { name, value }) => {
acc[name] = value;
return acc;
Expand Down
8 changes: 2 additions & 6 deletions src/params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ const TestCases = [
},
},
],
expectedResult: {
page: 0,
},
expectedResult: {},
},
{
description: 'It should not throw if no query params are given',
Expand All @@ -106,9 +104,7 @@ const TestCases = [
},
},
],
expectedResult: {
size: 10,
},
expectedResult: {},
},
{
description: 'Parse mixed params to the types defined in the spec',
Expand Down

0 comments on commit 242e355

Please sign in to comment.