Skip to content

Commit

Permalink
add feature #7 - add support for default response and 'application/js…
Browse files Browse the repository at this point in the history
…on; charset=UTF-8' media type.
  • Loading branch information
teobler committed Feb 8, 2023
1 parent 847371a commit 0627d63
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 32 deletions.
4 changes: 3 additions & 1 deletion src/resolvers/PathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ export class PathResolver {
get(responses, "200.content.application/json.schema") ||
get(responses, "200.content.*/*.schema") ||
get(responses, "201.content.application/json.schema") ||
get(responses, "201.content.*/*.schema"),
get(responses, "201.content.*/*.schema") ||
get(responses, "default.content.application/json.schema") ||
get(responses, "default.content.application/json; charset=UTF-8.schema"),
})
.resolve()
.getSchemaType();
Expand Down
7 changes: 4 additions & 3 deletions src/resolvers/__tests__/PathResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const expectedPathResolvedData = [
TReqCookie: {},
TReqPath: {},
TReqQuery: {
fruit: "Fruit",
"roleId?": "string",
scheduleDate: "number",
},
Expand All @@ -150,7 +151,7 @@ const expectedPathResolvedData = [
method: "get",
operationId: "getScheduleDetailsByDateUsingGET",
pathParams: [],
queryParams: ["scheduleDate", "roleId"],
queryParams: ["scheduleDate", "roleId", "fruit"],
url: "/schedules",
},
{
Expand Down Expand Up @@ -213,14 +214,14 @@ const expectedRequest = [
'export const useDownloadUsingGetRequest = ({id,accept}:{\n \'accept\': string;\n\'id\': string;\n }, SWRConfig?: ISWRConfig<Resource, IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useGetRequest<Resource, IResponseError>({\n url: `/${id}`,\n method: "get",headers: { "Accept": accept, },responseType: "blob",\n ...axiosConfig}, SWRConfig);',
"export const useFindBookByIdUsingGetRequest = ({id}:{\n 'id': string;\n }, SWRConfig?: ISWRConfig<BookDetailVo, IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useGetRequest<BookDetailVo, IResponseError>({\n url: `/book/${id}`,\n method: \"get\",headers: { },\n ...axiosConfig}, SWRConfig);",
"export const useGetDocumentByIdUsingGetRequest = ({documentId,from}:{\n 'documentId': string;\n'from'?: FromFrom;\n }, SWRConfig?: ISWRConfig<DocumentVo, IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useGetRequest<DocumentVo, IResponseError>({\n url: `/documents/${documentId}/doc`,\n method: \"get\",headers: { },\n params: {\n from\n },...axiosConfig}, SWRConfig);",
"export const useGetScheduleDetailsByDateUsingGetRequest = ({scheduleDate,roleId}:{\n 'roleId'?: string;\n'scheduleDate': number;\n }, SWRConfig?: ISWRConfig<ScheduleVo[], IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useGetRequest<ScheduleVo[], IResponseError>({\n url: `/schedules`,\n method: \"get\",headers: { },\n params: {\n scheduleDate,\nroleId\n },...axiosConfig}, SWRConfig);",
"export const useGetScheduleDetailsByDateUsingGetRequest = ({scheduleDate,roleId,fruit}:{\n 'fruit': Fruit;\n'roleId'?: string;\n'scheduleDate': number;\n }, SWRConfig?: ISWRConfig<ScheduleVo[], IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useGetRequest<ScheduleVo[], IResponseError>({\n url: `/schedules`,\n method: \"get\",headers: { },\n params: {\n scheduleDate,\nroleId,\nfruit\n },...axiosConfig}, SWRConfig);",
'export const useUpdateBookByIdUsingPutRequest = ({id}:{\n \'id\': string;\n }, mutationConfig?: SWRMutationConfig<UpdateBookByIdUsingPutRequest, AxiosResponse<undefined>, IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useMutationRequest<UpdateBookByIdUsingPutRequest, AxiosResponse<undefined>, IResponseError>({\n url: `/book/${id}`,\n method: "put",headers: { "Content-Type": "application/json"},\n mutationConfig,\n axiosConfig});',
'export const useUpdatePetsRequest = (mutationConfig?: SWRMutationConfig<UpdatePetsRequest, AxiosResponse<undefined>, IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useMutationRequest<UpdatePetsRequest, AxiosResponse<undefined>, IResponseError>({\n url: `/pets`,\n method: "patch",headers: { "Content-Type": "application/json"},\n mutationConfig,\n axiosConfig});',
'export const useUploadAttachmentUsingPostRequest = ({authorities,userId,userName}:{\n \'authorities\': string;\n\'userId\': string;\n\'userName\': string;\n }, mutationConfig?: SWRMutationConfig<UploadAttachmentUsingPostRequest, AxiosResponse<AttachmentBo>, IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useMutationRequest<UploadAttachmentUsingPostRequest, AxiosResponse<AttachmentBo>, IResponseError>({\n url: `/`,\n method: "post",headers: { "Authorities": authorities, "User-Id": userId, "User-Name": userName, "Content-Type": "multipart/form-data"},\n mutationConfig,\n axiosConfig});',
'export const useUploadDocumentUsingPostRequest = (mutationConfig?: SWRMutationConfig<UploadDocumentUsingPostRequest, AxiosResponse<undefined>, IResponseError>, axiosConfig?: AxiosRequestConfig) => \n useMutationRequest<UploadDocumentUsingPostRequest, AxiosResponse<undefined>, IResponseError>({\n url: `/documents`,\n method: "post",headers: { "Content-Type": "multipart/form-data"},\n mutationConfig,\n axiosConfig});',
"export interface UpdateBookJourneyUsingPostRequest {\n body: StatusFormData;\n \n }",
"export interface GetDocumentByIdUsingGetRequest {\n \n query: {\n 'from'?: FromFrom;\n }\n }",
"export interface GetScheduleDetailsByDateUsingGetRequest {\n \n query: {\n 'roleId'?: string;\n'scheduleDate': number;\n }\n }",
"export interface GetScheduleDetailsByDateUsingGetRequest {\n \n query: {\n 'fruit': Fruit;\n'roleId'?: string;\n'scheduleDate': number;\n }\n }",
"export interface UpdateBookByIdUsingPutRequest {\n body: UpdateBookRequest;\n \n }",
"export interface UpdatePetsRequest {\n body: Cat | Dog | null;\n \n }",
"export interface UploadAttachmentUsingPostRequest {\n body: FormData;\n \n }",
Expand Down
117 changes: 89 additions & 28 deletions src/resolvers/__tests__/mock-data/openAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,44 @@
"post": {
"operationId": "UpdateBookJourneyUsingPOST",
"parameters": [
{ "name": "journeyId", "required": true, "in": "path", "schema": { "type": "string" } },
{ "name": "journeyType", "required": true, "in": "path", "schema": { "type": "string" } }
{
"name": "journeyId",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
},
{
"name": "journeyType",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/StatusFormData" } } }
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StatusFormData"
}
}
}
},
"responses": {
"201": { "description": "", "content": { "application/json": { "schema": { "type": "object" } } } }
"201": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
Expand Down Expand Up @@ -351,6 +380,16 @@
"schema": {
"type": "string"
}
},
{
"name": "fruit",
"in": "query",
"description": "fruit",
"required": true,
"allowEmptyValue": false,
"schema": {
"$ref": "#/components/schemas/Fruit"
}
}
],
"responses": {
Expand Down Expand Up @@ -428,16 +467,6 @@
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/DocumentVO"
}
}
}
},
"401": {
"description": "Unauthorized"
},
Expand All @@ -446,6 +475,16 @@
},
"404": {
"description": "Not Found"
},
"default": {
"description": "default",
"content": {
"application/json; charset=UTF-8": {
"schema": {
"$ref": "#/components/schemas/DocumentVO"
}
}
}
}
},
"deprecated": false
Expand All @@ -459,12 +498,23 @@
"application/json": {
"schema": {
"nullable": true,
"oneOf": [{ "$ref": "#/components/schemas/Cat" }, { "$ref": "#/components/schemas/Dog" }]
"oneOf": [
{
"$ref": "#/components/schemas/Cat"
},
{
"$ref": "#/components/schemas/Dog"
}
]
}
}
}
},
"responses": { "200": { "description": "Updated" } }
"responses": {
"200": {
"description": "Updated"
}
}
}
}
},
Expand All @@ -478,15 +528,24 @@
"Dog": {
"type": "object",
"properties": {
"bark": { "type": "boolean" },
"breed": { "type": "string", "enum": ["Dingo", "Husky", "Retriever", "Shepherd"] }
"bark": {
"type": "boolean"
},
"breed": {
"type": "string",
"enum": ["Dingo", "Husky", "Retriever", "Shepherd"]
}
}
},
"Cat": {
"type": "object",
"properties": {
"hunts": { "type": "boolean" },
"age": { "type": "integer" }
"hunts": {
"type": "boolean"
},
"age": {
"type": "integer"
}
}
},
"BookDetailVo": {
Expand All @@ -513,7 +572,10 @@
"type": "string",
"example": ".png"
},
"type": { "type": "string", "enum": ["INTERVENTION_RUN", "CASE_CREATION_DATE"] },
"type": {
"type": "string",
"enum": ["INTERVENTION_RUN", "CASE_CREATION_DATE"]
},
"path": {
"type": "string",
"example": "/home"
Expand Down Expand Up @@ -904,14 +966,13 @@
},
"title": "ErrorInfo"
},
"StatusFormData": { "type": "object", "properties": {} },
"StatusFormData": {
"type": "object",
"properties": {}
},
"Fruit": {
"type": "string",
"enum": [
"Apple",
"Orange",
"Pear"
]
"type": "string,",
"enum": ["Apple", "Orange", "Pear"]
}
}
}
Expand Down

0 comments on commit 0627d63

Please sign in to comment.