Skip to content

Commit 4c434e9

Browse files
authored
Merge pull request wcandillon#204 from Pita/optional
Allow optional object properties for typescript
2 parents 81a509e + a6ce69c commit 4c434e9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/typescript.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ function convertType(swaggerType, swagger) {
6161
_.forEach(swaggerType.properties, function (propertyType, propertyName) {
6262
var property = convertType(propertyType);
6363
property.name = propertyName;
64+
65+
property.optional = true;
66+
if (swaggerType.required && swaggerType.required.indexOf(propertyName) !== -1) {
67+
property.optional = false;
68+
}
69+
6470
typespec.properties.push(property);
6571
});
6672
}
@@ -79,4 +85,3 @@ function convertType(swaggerType, swagger) {
7985
}
8086

8187
module.exports.convertType = convertType;
82-

templates/type.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<%#isRef%><%target%><%/isRef%><%!
55
%><%#isAtomic%><%&tsType%><%/isAtomic%><%!
66
%><%#isObject%>{<%#properties%>
7-
'<%name%>': <%>type%><%/properties%>
7+
'<%name%>'<%#optional%>?<%/optional%>: <%>type%><%/properties%>
88
}<%/isObject%><%!
99
%><%#isArray%>Array<<%#elementType%><%>type%><%/elementType%>>|<%#elementType%><%>type%><%/elementType%><%/isArray%>
1010
<%={{ }}=%>
11-
{{/tsType}}
11+
{{/tsType}}

0 commit comments

Comments
 (0)