Skip to content

Commit ee9d522

Browse files
Merge pull request #527 from bitgopatmcl/VL-112-status-code-descriptions
feat: use http status description as default in openapi-generator
2 parents 52e0efa + 3d21db0 commit ee9d522

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
export const STATUS_CODES = {
2+
'100': 'Continue',
3+
'101': 'Switching Protocols',
4+
'102': 'Processing',
5+
'200': 'OK',
6+
'201': 'Created',
7+
'202': 'Accepted',
8+
'203': 'Non-Authoritative Information',
9+
'204': 'No Content',
10+
'205': 'Reset Content',
11+
'206': 'Partial Content',
12+
'207': 'Multi-Status',
13+
'226': 'IM Used',
14+
'300': 'Multiple Choices',
15+
'301': 'Moved Permanently',
16+
'302': 'Found',
17+
'303': 'See Other',
18+
'304': 'Not Modified',
19+
'305': 'Use Proxy',
20+
'307': 'Temporary Redirect',
21+
'308': 'Permanent Redirect',
22+
'400': 'Bad Request',
23+
'401': 'Unauthorized',
24+
'402': 'Payment Required',
25+
'403': 'Forbidden',
26+
'404': 'Not Found',
27+
'405': 'Method Not Allowed',
28+
'406': 'Not Acceptable',
29+
'407': 'Proxy Authentication Required',
30+
'408': 'Request Timeout',
31+
'409': 'Conflict',
32+
'410': 'Gone',
33+
'411': 'Length Required',
34+
'412': 'Precondition Failed',
35+
'413': 'Payload Too Large',
36+
'414': 'URI Too Long',
37+
'415': 'Unsupported Media Type',
38+
'416': 'Range Not Satisfiable',
39+
'417': 'Expectation Failed',
40+
'418': "I'm a teapot",
41+
'422': 'Unprocessable Entity',
42+
'423': 'Locked',
43+
'424': 'Failed Dependency',
44+
'426': 'Upgrade Required',
45+
'428': 'Precondition Required',
46+
'429': 'Too Many Requests',
47+
'431': 'Request Header Fields Too Large',
48+
'451': 'Unavailable For Legal Reasons',
49+
'500': 'Internal Server Error',
50+
'501': 'Not Implemented',
51+
'502': 'Bad Gateway',
52+
'503': 'Service Unavailable',
53+
'504': 'Gateway Time-out',
54+
'505': 'HTTP Version Not Supported',
55+
'506': 'Variant Also Negotiates',
56+
'507': 'Insufficient Storage',
57+
'511': 'Network Authentication Required',
58+
};

packages/openapi-generator/src/openapi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { OpenAPIV3_1 } from 'openapi-types';
22

3+
import { STATUS_CODES } from 'http';
34
import { parseCommentBlock } from './jsdoc';
45
import type { Components } from './ref';
56
import type { Route } from './route';
@@ -106,7 +107,7 @@ function routeToOpenAPI(route: Route): [string, string, OpenAPIV3_1.OperationObj
106107
? { requestBody: schemaToOpenAPI(route.body) as any }
107108
: {}),
108109
responses: Object.entries(route.response).reduce((acc, [code, response]) => {
109-
const description = response.comment?.description ?? '';
110+
const description = response.comment?.description ?? STATUS_CODES[code] ?? '';
110111

111112
return {
112113
...acc,

packages/openapi-generator/test/openapi.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ testCase('simple route', SIMPLE, {
167167
],
168168
responses: {
169169
200: {
170-
description: '',
170+
description: 'OK',
171171
content: {
172172
'application/json': {
173173
schema: {

0 commit comments

Comments
 (0)