Skip to content

Commit 3933cb7

Browse files
authored
Merge pull request #1 from jessewang-arvatosystems/generate-custom-rebase
Add new property to list allMediaTypes.
2 parents 716d22a + 33fd1e2 commit 3933cb7

11 files changed

+28
-1
lines changed

src/client/interfaces/OperationParameter.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface OperationParameter extends Model {
44
in: 'path' | 'query' | 'header' | 'formData' | 'body' | 'cookie';
55
prop: string;
66
mediaType: string | null;
7+
allMediaTypes: string[];
78
}

src/client/interfaces/OperationResponse.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ import type { Model } from './Model';
33
export interface OperationResponse extends Model {
44
in: 'response' | 'header';
55
code: number;
6+
mediaType: string | null;
7+
allMediaTypes: string[];
68
}

src/openApi/v2/parser/getOperationParameter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const getOperationParameter = (openApi: OpenApi, parameter: OpenApiParame
4343
enums: [],
4444
properties: [],
4545
mediaType: null,
46+
allMediaTypes: [],
4647
};
4748

4849
if (parameter.$ref) {

src/openApi/v2/parser/getOperationResponse.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const getOperationResponse = (
3030
enum: [],
3131
enums: [],
3232
properties: [],
33+
mediaType: null,
34+
allMediaTypes: [],
3335
};
3436

3537
// If this response has a schema, then we need to check two things:

src/openApi/v2/parser/getOperationResults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const getOperationResults = (operationResponses: OperationResponse[]): Op
3939
enum: [],
4040
enums: [],
4141
properties: [],
42+
mediaType: null,
43+
allMediaTypes: [],
4244
});
4345
}
4446

src/openApi/v3/parser/getContent.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
66

77
export interface Content {
88
mediaType: string;
9+
allMediaTypes: string[];
910
schema: OpenApiSchema;
1011
}
1112

1213
const BASIC_MEDIA_TYPES = [
1314
'application/json-patch+json',
1415
'application/json',
15-
'application/x-www-form-urlencoded',
1616
'text/json',
1717
'text/plain',
18+
'application/xml',
19+
'application/javascript',
20+
'application/octet-stream',
21+
'application/x-www-form-urlencoded',
1822
'multipart/form-data',
1923
'multipart/mixed',
2024
'multipart/related',
@@ -31,6 +35,7 @@ export const getContent = (openApi: OpenApi, content: Dictionary<OpenApiMediaTyp
3135
if (basicMediaTypeWithSchema) {
3236
return {
3337
mediaType: basicMediaTypeWithSchema,
38+
allMediaTypes: Object.keys(content),
3439
schema: content[basicMediaTypeWithSchema].schema as OpenApiSchema,
3540
};
3641
}
@@ -39,6 +44,7 @@ export const getContent = (openApi: OpenApi, content: Dictionary<OpenApiMediaTyp
3944
if (firstMediaTypeWithSchema) {
4045
return {
4146
mediaType: firstMediaTypeWithSchema,
47+
allMediaTypes: Object.keys(content),
4248
schema: content[firstMediaTypeWithSchema].schema as OpenApiSchema,
4349
};
4450
}

src/openApi/v3/parser/getOperationParameter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const getOperationParameter = (openApi: OpenApi, parameter: OpenApiParame
3030
enums: [],
3131
properties: [],
3232
mediaType: null,
33+
allMediaTypes: [],
3334
};
3435

3536
if (parameter.$ref) {

src/openApi/v3/parser/getOperationRequestBody.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ export const getOperationRequestBody = (openApi: OpenApi, body: OpenApiRequestBo
2727
enums: [],
2828
properties: [],
2929
mediaType: null,
30+
allMediaTypes: [],
3031
};
3132

3233
if (body.content) {
3334
const content = getContent(openApi, body.content);
3435
if (content) {
3536
requestBody.mediaType = content.mediaType;
37+
requestBody.allMediaTypes = content.allMediaTypes;
3638
switch (requestBody.mediaType) {
3739
case 'application/x-www-form-urlencoded':
3840
case 'multipart/form-data':

src/openApi/v3/parser/getOperationResponse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ export const getOperationResponse = (
3131
enum: [],
3232
enums: [],
3333
properties: [],
34+
mediaType: null,
35+
allMediaTypes: [],
3436
};
3537

3638
if (response.content) {
3739
const content = getContent(openApi, response.content);
3840
if (content) {
41+
operationResponse.mediaType = content.mediaType;
42+
operationResponse.allMediaTypes = content.allMediaTypes;
3943
if (content.schema.$ref?.startsWith('#/components/responses/')) {
4044
content.schema = getRef<OpenApiSchema>(openApi, content.schema);
4145
}

src/openApi/v3/parser/getOperationResults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const getOperationResults = (operationResponses: OperationResponse[]): Op
3939
enum: [],
4040
enums: [],
4141
properties: [],
42+
mediaType: null,
43+
allMediaTypes: [],
4244
});
4345
}
4446

0 commit comments

Comments
 (0)