Skip to content

Commit

Permalink
fix: Use parameters spec.
Browse files Browse the repository at this point in the history
Fixes #10.
  • Loading branch information
ShogunPanda committed Mar 29, 2023
1 parent 05fe63d commit d623592
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/spec.ts
Expand Up @@ -43,11 +43,14 @@ function parseParameters(instance: FastifyInstance, schema: Schema): Schema | un

// For each property
/* c8 ignore next */
for (const name of Object.keys(specs.properties ?? {})) {
for (const [name, rawSpec] of Object.entries(specs.properties ?? {})) {
const spec = rawSpec as Schema

params.push({
name,
in: where,
description: specs.description,
description: spec.description,
schema: { type: spec.type ?? 'string' },
required: required.includes(name)
})
}
Expand Down
40 changes: 37 additions & 3 deletions test/spec.test.ts
Expand Up @@ -76,6 +76,13 @@ t.test('Spec generation', t => {
method: 'POST',
url: '/path',
schema: {
headers: {
type: 'object',
properties: {
why: { description: 'The reason' }
},
required: ['x-app-id']
},
body: { $ref: 'request#' },
response: {
200: { $ref: 'response#' }
Expand Down Expand Up @@ -153,6 +160,13 @@ paths:
description: Makes a request
tags:
- service
parameters:
- name: why
in: header
description: The reason
schema:
type: string
required: false
responses:
'200':
content:
Expand Down Expand Up @@ -241,6 +255,17 @@ paths:
summary: 'Main route',
description: 'Makes a request',
tags: ['service'],
parameters: [
{
name: 'why',
in: 'header',
description: 'The reason',
required: false,
schema: {
type: 'string'
}
}
],
responses: {
200: {
content: {
Expand Down Expand Up @@ -380,7 +405,10 @@ paths:
{
name: 'id',
in: 'path',
required: true
required: true,
schema: {
type: 'string'
}
}
],
responses: {
Expand Down Expand Up @@ -525,7 +553,10 @@ paths:
{
name: 'id',
in: 'path',
required: true
required: true,
schema: {
type: 'string'
}
}
],
responses: {
Expand Down Expand Up @@ -825,7 +856,10 @@ paths:
{
name: 'id',
in: 'path',
required: true
required: true,
schema: {
type: 'string'
}
}
],
responses: {
Expand Down

0 comments on commit d623592

Please sign in to comment.