-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show custom status code field in API docs (#833)
- Loading branch information
1 parent
094e621
commit 7ecfa21
Showing
5 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/ui/app/src/api-page/utils/getSuccessMessageForStatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
type StatusCodeMessages = { | ||
[method: string]: string; | ||
}; | ||
|
||
type SuccessMessages = { | ||
[code: number]: StatusCodeMessages; | ||
}; | ||
|
||
export const COMMON_SUCCESS_NAMES: SuccessMessages = { | ||
200: { | ||
PUT: "Updated", | ||
DELETE: "Deleted", | ||
default: "Success", | ||
}, | ||
201: { | ||
PUT: "Updated", | ||
default: "Created", | ||
}, | ||
202: { | ||
default: "Accepted", | ||
}, | ||
203: { | ||
default: "Non-Authoritative Information", | ||
}, | ||
204: { | ||
default: "No Content", | ||
}, | ||
205: { | ||
default: "Reset Content", | ||
}, | ||
206: { | ||
default: "Partial Content", | ||
}, | ||
207: { | ||
default: "Multi-Status", | ||
}, | ||
208: { | ||
default: "Already Reported", | ||
}, | ||
226: { | ||
default: "IM Used", | ||
}, | ||
}; | ||
|
||
export function getSuccessMessageForStatus(statusCode: number, method: string): string { | ||
const messages = COMMON_SUCCESS_NAMES[statusCode]; | ||
if (!messages) { | ||
return "Success"; | ||
} | ||
return messages[method] ?? messages.default; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters