Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse definitions from Swagger #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
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
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
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
@@ -0,0 +1,3 @@
{{#definitions}}
interface {{name}} {{>type}}
{{/definitions}}