Skip to content

Commit 6e2ae7a

Browse files
authored
fix: add route description (#182)
1 parent 126c2ed commit 6e2ae7a

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

src/routes/object/getObject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default async function routes(fastify: FastifyInstance) {
107107
params: getObjectParamsSchema,
108108
headers: { $ref: 'authSchema#' },
109109
summary,
110-
response: { '4xx': { $ref: 'errorSchema#' } },
110+
response: { '4xx': { $ref: 'errorSchema#', description: 'Error response' } },
111111
tags: ['object'],
112112
},
113113
},
@@ -123,7 +123,7 @@ export default async function routes(fastify: FastifyInstance) {
123123
schema: {
124124
params: getObjectParamsSchema,
125125
headers: { $ref: 'authSchema#' },
126-
summary: 'Get object (deprecated)',
126+
summary: 'Get object',
127127
description: 'use GET /object/authenticated/{bucketName} instead',
128128
response: { '4xx': { $ref: 'errorSchema#' } },
129129
tags: ['deprecated'],

src/routes/object/getPublicObject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default async function routes(fastify: FastifyInstance) {
4242
schema: {
4343
params: getPublicObjectParamsSchema,
4444
summary,
45-
response: { '4xx': { $ref: 'errorSchema#' } },
45+
response: { '4xx': { $ref: 'errorSchema#', description: 'Error response' } },
4646
tags: ['object'],
4747
},
4848
},

src/routes/object/getSignedObject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default async function routes(fastify: FastifyInstance) {
5858
params: getSignedObjectParamsSchema,
5959
querystring: getSignedObjectQSSchema,
6060
summary,
61-
response: { '4xx': { $ref: 'errorSchema#' } },
61+
response: { '4xx': { $ref: 'errorSchema#', description: 'Error response' } },
6262
tags: ['object'],
6363
},
6464
},

src/schemas/auth.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ export const authSchema = {
22
$id: 'authSchema',
33
type: 'object',
44
properties: {
5-
authorization: { type: 'string' },
5+
authorization: {
6+
type: 'string',
7+
examples: [
8+
'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs',
9+
],
10+
},
611
},
712
required: ['authorization'],
813
} as const

src/test/generic-routes.test.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,29 @@ describe('testing Generic Routes Utils', () => {
4747

4848
describe('creating generic schema [createDefaultSchema]', () => {
4949
test('create generic schema without additional properties', () => {
50-
const successResponseSchema = { generic: 'example' }
50+
const successResponseSchema = { generic: 'example', description: 'Successful response' }
5151
const response = {
5252
headers: { $ref: 'authSchema#' },
53-
response: { 200: successResponseSchema, '4xx': { $ref: 'errorSchema#' } },
53+
response: {
54+
200: successResponseSchema,
55+
'4xx': { $ref: 'errorSchema#', description: 'Error response' },
56+
},
5457
}
5558

5659
expect(createDefaultSchema(successResponseSchema, {})).toEqual(response)
5760
})
5861

5962
test('create generic schema with additional properties', () => {
60-
const successResponseSchema = { generic: 'example' }
63+
const successResponseSchema = { generic: 'example', description: 'Successful response' }
6164
const additionalProperties = { generic: 'example' }
6265
const response = {
63-
headers: { $ref: 'authSchema#' },
64-
response: { 200: successResponseSchema, '4xx': { $ref: 'errorSchema#' } },
66+
headers: {
67+
$ref: 'authSchema#',
68+
},
69+
response: {
70+
200: successResponseSchema,
71+
'4xx': { $ref: 'errorSchema#', description: 'Error response' },
72+
},
6573
...additionalProperties,
6674
}
6775

src/utils/generic-routes.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ function createResponse(message: string, status?: string, error?: string): Bucke
2727
function createDefaultSchema(successResponseSchema: any, properties: any): any {
2828
return {
2929
headers: { $ref: 'authSchema#' },
30-
response: { 200: successResponseSchema, '4xx': { $ref: 'errorSchema#' } },
30+
response: {
31+
200: { description: 'Successful response', ...successResponseSchema },
32+
'4xx': { description: 'Error response', $ref: 'errorSchema#' },
33+
},
3134
...properties,
3235
}
3336
}

0 commit comments

Comments
 (0)