From d6417005ef21ac2861a68c16e980866dd48b7185 Mon Sep 17 00:00:00 2001 From: Individumm Date: Wed, 18 May 2016 17:44:58 +0200 Subject: [PATCH 1/5] Add responses-object to endpoints for use in "getCustomCode" --- lib/codegen.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/codegen.js b/lib/codegen.js index 1226f870..48aaaeb1 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -149,6 +149,11 @@ var getViewForSwagger2 = function(opts, type){ parameter.cardinality = parameter.required ? '' : '?'; method.parameters.push(parameter); }); + + if(_.isPlainObject(op.responses)) { + method.responses = op.responses; + } + data.methods.push(method); }); }); From 0e8604f98a267aa9b774b207118feb13764361c2 Mon Sep 17 00:00:00 2001 From: Individumm Date: Wed, 18 May 2016 18:00:59 +0200 Subject: [PATCH 2/5] Removed unnecessary condition and extended schema in "README.md" --- README.md | 6 ++++++ lib/codegen.js | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dffa0360..25ec3347 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/codegen.js b/lib/codegen.js index 48aaaeb1..d604ce55 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -150,9 +150,7 @@ var getViewForSwagger2 = function(opts, type){ method.parameters.push(parameter); }); - if(_.isPlainObject(op.responses)) { - method.responses = op.responses; - } + method.responses = op.responses; data.methods.push(method); }); From 64dce885977277e07e45bc2ab5499c7b8098cd0e Mon Sep 17 00:00:00 2001 From: Individumm Date: Thu, 19 May 2016 21:07:12 +0200 Subject: [PATCH 3/5] Tabs to spaces --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 25ec3347..e0dc49ac 100644 --- a/README.md +++ b/README.md @@ -170,11 +170,11 @@ methods: 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) + 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 From b26efb018f34f85f5324c39f356915bac39bca4f Mon Sep 17 00:00:00 2001 From: Bradley Leatherwood Date: Fri, 13 Jan 2017 17:59:49 -0800 Subject: [PATCH 4/5] added response type infromation to the response --- lib/codegen.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/codegen.js b/lib/codegen.js index 05f40a85..28356921 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -1,5 +1,4 @@ 'use strict'; - var fs = require('fs'); var Mustache = require('mustache'); var beautify = require('js-beautify').js_beautify; @@ -133,9 +132,11 @@ var getViewForSwagger2 = function(opts, type){ parameter.cardinality = parameter.required ? '' : '?'; method.parameters.push(parameter); }); - - method.responses = op.responses; - + + method.responses = op.responses; + _.forEach(method.responses, (obj, key) => { + method.responses[key].tsType = ts.convertType(obj); + }); data.methods.push(method); }); }); From 9d4f73a773013f3a2a10cdb628f80ae32211fa52 Mon Sep 17 00:00:00 2001 From: Bradley Leatherwood Date: Tue, 17 Jan 2017 12:19:34 -0800 Subject: [PATCH 5/5] added optional paramaters to TypeScript type definitions --- lib/typescript.js | 12 ++++++++++++ templates/type.mustache | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/typescript.js b/lib/typescript.js index b33070c4..b105c77c 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -40,6 +40,18 @@ function convertType(swaggerType) { 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'... diff --git a/templates/type.mustache b/templates/type.mustache index d8f2518d..d0f258cc 100644 --- a/templates/type.mustache +++ b/templates/type.mustache @@ -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%> <%={{ }}=%>