Skip to content

Commit feefce2

Browse files
committed
feat: add support for json:api content type
1 parent cc5e570 commit feefce2

File tree

5 files changed

+10
-0
lines changed

5 files changed

+10
-0
lines changed

src/schema-routes/schema-routes.ts

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { SpecificArgNameResolver } from "./util/specific-arg-name-resolver.js";
2222

2323
const CONTENT_KIND = {
2424
JSON: "JSON",
25+
JSON_API: "JSON_API",
2526
URL_ENCODED: "URL_ENCODED",
2627
FORM_DATA: "FORM_DATA",
2728
IMAGE: "IMAGE",
@@ -280,6 +281,10 @@ export class SchemaRoutes {
280281
);
281282

282283
getContentKind = (contentTypes) => {
284+
if (contentTypes.includes("application/vnd.api+json")) {
285+
return CONTENT_KIND.JSON_API;
286+
}
287+
283288
if (
284289
contentTypes.some((contentType) =>
285290
contentType.startsWith("application/json"),

templates/base/http-clients/axios-http-client.ejs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequest
3232

3333
export enum ContentType {
3434
Json = "application/json",
35+
JsonApi = "application/vnd.api+json",
3536
FormData = "multipart/form-data",
3637
UrlEncoded = "application/x-www-form-urlencoded",
3738
Text = "text/plain",

templates/base/http-clients/fetch-http-client.ejs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type CancelToken = Symbol | string | number;
4343

4444
export enum ContentType {
4545
Json = "application/json",
46+
JsonApi = "application/vnd.api+json",
4647
FormData = "multipart/form-data",
4748
UrlEncoded = "application/x-www-form-urlencoded",
4849
Text = "text/plain",
@@ -103,6 +104,7 @@ export class HttpClient<SecurityDataType = unknown> {
103104

104105
private contentFormatters: Record<ContentType, (input: any) => any> = {
105106
[ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
107+
[ContentType.JsonApi]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
106108
[ContentType.Text]: (input:any) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input,
107109
[ContentType.FormData]: (input: any) =>
108110
Object.keys(input || {}).reduce((formData, key) => {

templates/default/procedure-call.ejs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const wrapperArgs = _
4848
// RequestParams["type"]
4949
const requestContentKind = {
5050
"JSON": "ContentType.Json",
51+
"JSON_API": "ContentType.JsonApi",
5152
"URL_ENCODED": "ContentType.UrlEncoded",
5253
"FORM_DATA": "ContentType.FormData",
5354
"TEXT": "ContentType.Text",

templates/modular/procedure-call.ejs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const wrapperArgs = _
4848
// RequestParams["type"]
4949
const requestContentKind = {
5050
"JSON": "ContentType.Json",
51+
"JSON_API": "ContentType.JsonApi",
5152
"URL_ENCODED": "ContentType.UrlEncoded",
5253
"FORM_DATA": "ContentType.FormData",
5354
"TEXT": "ContentType.Text",

0 commit comments

Comments
 (0)