From ceac5f9fb19c79359491724b3811d207d347b145 Mon Sep 17 00:00:00 2001 From: Dmitriy Kargapolov Date: Thu, 4 Jan 2018 20:16:33 -0500 Subject: [PATCH 1/3] Fix code to let Erlang server codegen work --- .../src/main/resources/erlang-server/api.mustache | 6 +++--- .../src/main/resources/erlang-server/app.src.mustache | 2 +- .../src/main/resources/erlang-server/handler.mustache | 4 ++-- .../src/main/resources/erlang-server/router.mustache | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache b/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache index 6e337c7773e..3c6003467b2 100644 --- a/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache +++ b/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache @@ -18,7 +18,7 @@ request_params('{{operationId}}') -> [{{#allParams}}{{^isBodyParam}} '{{baseName}}'{{/isBodyParam}}{{#isBodyParam}} - '{{dataType}}'{{/isBodyParam}}{{#hasMore}},{{/hasMore}}{{/allParams}} + '{{dataType}}'{{/isBodyParam}}{{^@last}},{{/@last}}{{/allParams}} ]; {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} request_params(_) -> @@ -53,7 +53,7 @@ request_params(_) -> {{#operations}}{{#operation}}{{#allParams}} request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyParam}}{{#isBodyParam}}'{{dataType}}'{{/isBodyParam}}) -> #{ - source => {{#isQueryParam}}qs_val{{/isQueryParam}} {{#isPathParam}}binding{{/isPathParam}} {{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}, + source => {{#vendorExtensions.x-is-query-param}}qs_val{{/vendorExtensions.x-is-query-param}} {{#isPathParam}}binding{{/isPathParam}} {{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}, rules => [{{#isString}} {type, 'binary'},{{/isString}}{{#isInteger}} {type, 'integer'},{{/isInteger}}{{#isLong}} @@ -65,7 +65,7 @@ request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyPar {type, 'boolean'},{{/isBoolean}}{{#isDate}} {type, 'date'},{{/isDate}}{{#isDateTime}} {type, 'datetime'},{{/isDateTime}}{{#isEnum}} - {enum, [{{#allowableValues}}{{#values}}'{{.}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] },{{/isEnum}}{{#maximum}} + {enum, [{{#allowableValues}}{{#values}}'{{.}}'{{^@last}}, {{/@last}}{{/values}}{{/allowableValues}}] },{{/isEnum}}{{#maximum}} {max, {{maximum}} }, {{/maximum}}{{#exclusiveMaximum}} {exclusive_max, {{exclusiveMaximum}} },{{/exclusiveMaximum}}{{#minimum}} {min, {{minimum}} },{{/minimum}}{{#exclusiveMinimum}} diff --git a/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache b/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache index 0bc22f45743..1180e74c6d8 100644 --- a/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache +++ b/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache @@ -1,5 +1,5 @@ {application, {{packageName}}, [ - {description, {{#appDescription}}"{{appDescription}}"{{/appDescription}}{{^appDescription}}"Swagger rest server library"{{/appDescription}}}, + {description, {{#appDescription}}"{{appDescription}}"{{/appDescription}}{{^appDescription}}"Swagger rest server library"{{/appDescription}} }, {vsn, "{{apiVersion}}"}, {registered, []}, {applications, [ diff --git a/modules/swagger-codegen/src/main/resources/erlang-server/handler.mustache b/modules/swagger-codegen/src/main/resources/erlang-server/handler.mustache index 4ed2e21a2ae..9122a63d794 100644 --- a/modules/swagger-codegen/src/main/resources/erlang-server/handler.mustache +++ b/modules/swagger-codegen/src/main/resources/erlang-server/handler.mustache @@ -90,7 +90,7 @@ is_authorized( ), case Result of {true, Context, Req} -> {true, Req, State#state{context = Context}}; - {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} + {false, AuthHeader, Req} -> { {false, AuthHeader}, Req, State} end; {{/isApiKey}} {{/authMethods}} @@ -101,7 +101,7 @@ is_authorized(Req, State) -> {{/authMethods}} {{#authMethods}} is_authorized(Req, State) -> - {{false, <<"">>}, Req, State}. + { {false, <<"">>}, Req, State}. {{/authMethods}} -spec content_types_accepted(Req :: cowboy_req:req(), State :: state()) -> diff --git a/modules/swagger-codegen/src/main/resources/erlang-server/router.mustache b/modules/swagger-codegen/src/main/resources/erlang-server/router.mustache index b5b7bd9f52e..ae22f385ebe 100644 --- a/modules/swagger-codegen/src/main/resources/erlang-server/router.mustache +++ b/modules/swagger-codegen/src/main/resources/erlang-server/router.mustache @@ -59,7 +59,7 @@ get_operations() -> path => "{{{basePathWithoutHost}}}{{{path}}}", method => <<"{{httpMethod}}">>, handler => '{{classname}}' - }{{#hasMore}},{{/hasMore}}{{/operation}}{{#hasMore}},{{/hasMore}}{{/operations}}{{/apis}}{{/apiInfo}} + }{{^@last}},{{/@last}}{{/operation}}{{^@last}},{{/@last}}{{/operations}}{{/apis}}{{/apiInfo}} }. prepare_validator() -> From ca1cd9cfae93c181df46c2ce4ccb14f5955b96e2 Mon Sep 17 00:00:00 2001 From: Dmitriy Kargapolov Date: Thu, 4 Jan 2018 23:07:54 -0500 Subject: [PATCH 2/3] Adjust fix to use handlebars is/has helpers --- .../src/main/resources/erlang-server/api.mustache | 8 ++++---- .../src/main/resources/erlang-server/app.src.mustache | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache b/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache index 3c6003467b2..96ced03790d 100644 --- a/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache +++ b/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache @@ -16,9 +16,9 @@ {{#apiInfo}}{{#apis}} {{#operations}}{{#operation}} request_params('{{operationId}}') -> - [{{#allParams}}{{^isBodyParam}} - '{{baseName}}'{{/isBodyParam}}{{#isBodyParam}} - '{{dataType}}'{{/isBodyParam}}{{^@last}},{{/@last}}{{/allParams}} + [{{#allParams}}{{#isNot this 'body-param'}} + '{{baseName}}'{{/isNot}}{{#is this 'body-param'}} + '{{dataType}}'{{/is}}{{#has this 'more'}},{{/has}}{{/allParams}} ]; {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} request_params(_) -> @@ -53,7 +53,7 @@ request_params(_) -> {{#operations}}{{#operation}}{{#allParams}} request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyParam}}{{#isBodyParam}}'{{dataType}}'{{/isBodyParam}}) -> #{ - source => {{#vendorExtensions.x-is-query-param}}qs_val{{/vendorExtensions.x-is-query-param}} {{#isPathParam}}binding{{/isPathParam}} {{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}, + source => {{#is this 'query-param'}}qs_val{{/is}} {{#isPathParam}}binding{{/isPathParam}} {{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}, rules => [{{#isString}} {type, 'binary'},{{/isString}}{{#isInteger}} {type, 'integer'},{{/isInteger}}{{#isLong}} diff --git a/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache b/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache index 1180e74c6d8..8e8bcd10c50 100644 --- a/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache +++ b/modules/swagger-codegen/src/main/resources/erlang-server/app.src.mustache @@ -1,5 +1,5 @@ {application, {{packageName}}, [ - {description, {{#appDescription}}"{{appDescription}}"{{/appDescription}}{{^appDescription}}"Swagger rest server library"{{/appDescription}} }, + {description, {{#appDescription}}"{{appDescription}}"{{/appDescription}}{{^appDescription}}"Swagger rest server library"{{/appDescription~}} }, {vsn, "{{apiVersion}}"}, {registered, []}, {applications, [ From 77a109a26aded4beeaf4da8688361703d9f87d3d Mon Sep 17 00:00:00 2001 From: Dmitry Klionsky Date: Mon, 15 Jan 2018 18:00:28 +0300 Subject: [PATCH 3/3] Fix schema path --- .../src/main/resources/erlang-server/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache b/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache index 96ced03790d..e2f91c98cfa 100644 --- a/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache +++ b/modules/swagger-codegen/src/main/resources/erlang-server/api.mustache @@ -261,7 +261,7 @@ validate(Rule = {pattern, Pattern}, Name, Value, _ValidatorState) -> end; validate(Rule = schema, Name, Value, ValidatorState) -> - Definition = list_to_binary("#/definitions/" ++ {{packageName}}_utils:to_list(Name)), + Definition = list_to_binary("#/components/schemas/" ++ {{packageName}}_utils:to_list(Name)), try _ = validate_with_schema(Value, Definition, ValidatorState), ok