Skip to content

Commit 33fd1e2

Browse files
Add mediaType and allMediaTypes to operationResponse. Add new handlebars helper function to help with debugging
1 parent 3c22a1d commit 33fd1e2

10 files changed

+20
-4
lines changed

src/client/interfaces/OperationParameter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +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[] | null;
7+
allMediaTypes: string[];
88
}

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const getOperationParameter = (openApi: OpenApi, parameter: OpenApiParame
4343
enums: [],
4444
properties: [],
4545
mediaType: null,
46-
allMediaTypes: null,
46+
allMediaTypes: [],
4747
};
4848

4949
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/getOperationParameter.ts

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

3636
if (parameter.$ref) {

src/openApi/v3/parser/getOperationRequestBody.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getOperationRequestBody = (openApi: OpenApi, body: OpenApiRequestBo
2727
enums: [],
2828
properties: [],
2929
mediaType: null,
30-
allMediaTypes: null,
30+
allMediaTypes: [],
3131
};
3232

3333
if (body.content) {

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

src/utils/registerHandlebarHelpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,8 @@ export const registerHandlebarHelpers = (root: {
107107
Handlebars.registerHelper('camelCase', function (value: string): string {
108108
return camelCase(value);
109109
});
110+
111+
Handlebars.registerHelper('toJSON', function (object): any {
112+
return new Handlebars.SafeString(JSON.stringify(object));
113+
});
110114
};

0 commit comments

Comments
 (0)