Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ methods:
type: boolean
isFormParameter:
type: boolean
responses:
type: object
description: Includes all defined response-codes and its JSONs schema
additionalProperties:
type: object
description: See the 'Response Object' section in the [Swagger 2.0 specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#response-object)
```

#### Custom Mustache Variables
Expand Down
6 changes: 5 additions & 1 deletion lib/codegen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

var fs = require('fs');
var Mustache = require('mustache');
var beautify = require('js-beautify').js_beautify;
Expand Down Expand Up @@ -131,6 +130,11 @@ var getViewForSwagger2 = function(opts, type){
parameter.cardinality = parameter.required ? '' : '?';
method.parameters.push(parameter);
});

method.responses = op.responses;
_.forEach(method.responses, (obj, key) => {
method.responses[key].tsType = ts.convertType(obj);
});
data.methods.push(method);
});
});
Expand Down
18 changes: 18 additions & 0 deletions lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ function convertType(swaggerType, swagger) {
typespec.properties.push(property);
});
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This _forEach should replace the above one, otherwise, it will result in duplicated typescript properties.

_.forEach(swaggerType.properties, function (propertyType, propertyName) {
var property = convertType(propertyType);
property.name = propertyName;
typespec.properties.push(property);
// see if property is required
if (Array.isArray(swaggerType.required)) {
if(swaggerType.required.indexOf(propertyName) > -1) {
property.isRequired = true;
}
else {
property.isRequired = false;
}
}
else {
property.isRequired = true;
}
});
} else {
// type unknown or unsupported... just map to 'any'...
typespec.tsType = 'any';
Expand Down
2 changes: 1 addition & 1 deletion templates/type.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%#isRef%><%target%><%/isRef%><%!
%><%#isAtomic%><%&tsType%><%/isAtomic%><%!
%><%#isObject%>{<%#properties%>
'<%name%>': <%>type%><%/properties%>
'<%name%>'<%^isRequired%>?<%/isRequired%>: <%>type%><%/properties%>
}<%/isObject%><%!
%><%#isArray%>Array<<%#elementType%><%>type%><%/elementType%>>|<%#elementType%><%>type%><%/elementType%><%/isArray%>
<%={{ }}=%>
Expand Down