Skip to content

Commit e5adbe9

Browse files
committedMar 11, 2024·
Optimize dict
1 parent 713c48c commit e5adbe9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

‎lib/services/mimetype-content-wrapper.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { ContentObject } from '../interfaces/open-api-spec.interface';
22

3+
function removeUndefinedKeys(obj: { [x: string]: any }) {
4+
Object.entries(obj).forEach(([key, value]) => {
5+
if (value === undefined) {
6+
delete obj[key];
7+
}
8+
});
9+
return obj;
10+
}
11+
312
export class MimetypeContentWrapper {
413
wrap(
514
mimetype: string[],
615
obj: Record<string, any>
716
): Record<'content', ContentObject> {
817
const content = mimetype.reduce(
9-
(acc, item) => ({ ...acc, [item]: obj }),
18+
(acc, item) => ({ ...acc, [item]: removeUndefinedKeys(obj) }),
1019
{}
1120
);
1221
return { content };

‎lib/services/response-object-mapper.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ResponseObjectMapper {
2020
$ref: getSchemaPath(name)
2121
}
2222
},
23-
...(response.example ? { example: response.example } : {})
23+
example: response.example
2424
})
2525
};
2626
}
@@ -32,7 +32,7 @@ export class ResponseObjectMapper {
3232
schema: {
3333
$ref: getSchemaPath(name)
3434
},
35-
...(response.example ? { example: response.example } : {})
35+
example: response.example
3636
})
3737
};
3838
}
@@ -45,8 +45,8 @@ export class ResponseObjectMapper {
4545
return response;
4646
}
4747
const content = this.mimetypeContentWrapper.wrap(produces, {
48-
...(response.schema ? { schema: response.schema } : {}),
49-
...(response.example ? { example: response.example } : {})
48+
schema: response.schema,
49+
example: response.example
5050
});
5151
return {
5252
...omit(response, ['schema', 'example']),

0 commit comments

Comments
 (0)
Please sign in to comment.