Skip to content
Open
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ methods:
type: boolean
isFormParameter:
type: boolean
definitions:
type: array
description: Array with all Types defined in defintions
items:
type: object
properties:
tsType:
type: string
isRef:
type: boolean
isObject:
type: boolean
isArray:
type: boolean
isAtomic:
type: boolean
name:
type: string
```

####Custom Mustache Variables
Expand Down
12 changes: 11 additions & 1 deletion lib/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ var getViewForSwagger2 = function(opts, type){
className: opts.className,
imports: opts.imports,
domain: (swagger.schemes && swagger.schemes.length > 0 && swagger.host && swagger.basePath) ? swagger.schemes[0] + '://' + swagger.host + swagger.basePath.replace(/\/+$/g,'') : '',
methods: []
methods: [],
definitions: []
};

_.forEach(swagger.paths, function(api, path){
Expand Down Expand Up @@ -157,6 +158,15 @@ var getViewForSwagger2 = function(opts, type){
data.methods.push(method);
});
});

_.forEach(swagger.definitions, function(typeInfo, typeName) {
typeInfo.type = typeInfo.type || 'object';

var tsType = ts.convertType(typeInfo);
tsType.name = typeName;
data.definitions.push(tsType);
});

return data;
};

Expand Down
3 changes: 3 additions & 0 deletions lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function convertType(swaggerType) {

var typespec = {};

// sanitize input
swaggerType = swaggerType || {};

if (swaggerType.hasOwnProperty('schema')) {
return convertType(swaggerType.schema);
} else if (_.isString(swaggerType.$ref)) {
Expand Down
3 changes: 3 additions & 0 deletions templates/typescript-definitions-only.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#definitions}}
interface {{name}} {{>type}}
{{/definitions}}