diff --git a/bin/flaskConnexion.sh b/bin/flaskConnexion.sh index f300d3124b16..1745d2a3ba2a 100755 --- a/bin/flaskConnexion.sh +++ b/bin/flaskConnexion.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l flaskConnexion -o samples/server/petstore/flaskConnexion " +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l python-flask -o samples/server/petstore/flaskConnexion " java $JAVA_OPTS -Dservice -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 219c5a5efb30..75c6e2ff8169 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1081,31 +1081,7 @@ public class DefaultCodegen { Set imports = new HashSet(); op.vendorExtensions = operation.getVendorExtensions(); - String operationId = operation.getOperationId(); - if (operationId == null) { - String tmpPath = path; - tmpPath = tmpPath.replaceAll("\\{", ""); - tmpPath = tmpPath.replaceAll("\\}", ""); - String[] parts = (tmpPath + "/" + httpMethod).split("/"); - StringBuilder builder = new StringBuilder(); - if ("/".equals(tmpPath)) { - // must be root tmpPath - builder.append("root"); - } - for (int i = 0; i < parts.length; i++) { - String part = parts[i]; - if (part.length() > 0) { - if (builder.toString().length() == 0) { - part = Character.toLowerCase(part.charAt(0)) + part.substring(1); - } else { - part = initialCaps(part); - } - builder.append(part); - } - } - operationId = builder.toString(); - LOGGER.info("generated operationId " + operationId + "\tfor Path: " + httpMethod + " " + path); - } + String operationId = getOrGenerateOperationId(operation, path, httpMethod); operationId = removeNonNameElementToCamelCase(operationId); op.path = path; op.operationId = toOperationId(operationId); @@ -1635,6 +1611,43 @@ public class DefaultCodegen { return secs; } + /** + * Get operationId from the operation object, and if it's blank, generate a new one from the given parameters. + * + * @param operation the operation object + * @param path the path of the operation + * @param httpMethod the HTTP method of the operation + * @return the (generated) operationId + */ + protected String getOrGenerateOperationId(Operation operation, String path, String httpMethod) { + String operationId = operation.getOperationId(); + if (StringUtils.isBlank(operationId)) { + String tmpPath = path; + tmpPath = tmpPath.replaceAll("\\{", ""); + tmpPath = tmpPath.replaceAll("\\}", ""); + String[] parts = (tmpPath + "/" + httpMethod).split("/"); + StringBuilder builder = new StringBuilder(); + if ("/".equals(tmpPath)) { + // must be root tmpPath + builder.append("root"); + } + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + if (part.length() > 0) { + if (builder.toString().length() == 0) { + part = Character.toLowerCase(part.charAt(0)) + part.substring(1); + } else { + part = initialCaps(part); + } + builder.append(part); + } + } + operationId = builder.toString(); + LOGGER.info("generated operationId " + operationId + "\tfor Path: " + httpMethod + " " + path); + } + return operationId; + } + /** * Check the type to see if it needs import the library/module/package * diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java index b3de913501a0..7a06ee8b845f 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java @@ -5,6 +5,7 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import io.swagger.codegen.*; +import io.swagger.models.HttpMethod; import io.swagger.models.Operation; import io.swagger.models.Path; import io.swagger.models.Swagger; @@ -205,13 +206,17 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf for(String pathname : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathname); if(path.getOperations() != null) { - for(Operation operation : path.getOperations()) { - String operationId = operation.getOperationId(); - if(operationId != null && operationId.indexOf(".") == -1) { - operation.setVendorExtension("x-operationId", underscore(sanitizeName(operationId))); - operationId = controllerPackage + "." + defaultController + "." + underscore(sanitizeName(operationId)); - operation.setOperationId(operationId); + for(Map.Entry entry : path.getOperationMap().entrySet()) { + // Normalize `operationId` and add package/class path in front, e.g. + // controllers.default_controller.add_pet + String httpMethod = entry.getKey().name().toLowerCase(); + Operation operation = entry.getValue(); + String operationId = getOrGenerateOperationId(operation, pathname, httpMethod); + if(!operationId.contains(".")) { + operationId = underscore(sanitizeName(operationId)); + operationId = controllerPackage + "." + defaultController + "." + operationId; } + operation.setOperationId(operationId); if(operation.getTags() != null) { List> tags = new ArrayList>(); for(String tag : operation.getTags()) { @@ -292,4 +297,15 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf } return super.postProcessSupportingFileData(objs); } + + @Override + public String toOperationId(String operationId) { + operationId = super.toOperationId(operationId); + // Use the part after the last dot, e.g. + // controllers.defaultController.addPet => addPet + operationId = operationId.replaceAll(".*\\.", ""); + // Need to underscore it since it has been processed via removeNonNameElementToCamelCase, e.g. + // addPet => add_pet + return underscore(operationId); + } } \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index 3ac280b2d706..5f617a253f14 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -41,13 +41,13 @@ public class {{classname}} { {{#allParams}} * @param {{paramName}} {{description}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ - public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{^isBinary}}{{paramName}}{{/isBinary}}{{#isBinary}}null{{/isBinary}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; byte[] {{localVariablePrefix}}postBinaryBody = {{#bodyParam}}{{#isBinary}}{{paramName}}{{/isBinary}}{{^isBinary}}null{{/isBinary}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set if ({{paramName}} == null) { - throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}"); + throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}"); } {{/required}}{{/allParams}} // create path and map variables diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache index 10f2fa2f7446..0d5c3bcf7f0b 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache @@ -41,12 +41,12 @@ public class {{classname}} { {{#allParams}} * @param {{paramName}} {{description}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ - public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set if ({{paramName}} == null) { - throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}"); + throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}"); } {{/required}}{{/allParams}} // create path and map variables diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache index c5ddb428e59f..a1a4c9f8fb4f 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache @@ -45,13 +45,13 @@ public class {{classname}} { } {{#operation}} - /* Build call for {{nickname}} */ - private Call {{nickname}}Call({{#allParams}}{{{dataType}}} {{paramName}},{{/allParams}} final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + /* Build call for {{operationId}} */ + private Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set if ({{paramName}} == null) { - throw new ApiException("Missing the required parameter '{{paramName}}' when calling {{nickname}}(Async)"); + throw new ApiException("Missing the required parameter '{{paramName}}' when calling {{operationId}}(Async)"); } {{/required}}{{/allParams}} @@ -105,8 +105,8 @@ public class {{classname}} { * @param {{paramName}} {{description}}{{/allParams}}{{#returnType}} * @return {{{returnType}}}{{/returnType}} */ - public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { - Call {{localVariablePrefix}}call = {{nickname}}Call({{#allParams}}{{paramName}},{{/allParams}} null, null); + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { + Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}null, null); {{#returnType}}Type {{localVariablePrefix}}returnType = new TypeToken<{{{returnType}}}>(){}.getType(); return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}returnType);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}} } @@ -118,12 +118,12 @@ public class {{classname}} { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call {{nickname}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException { + public Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -139,7 +139,7 @@ public class {{classname}} { }; } - Call {{localVariablePrefix}}call = {{nickname}}Call({{#allParams}}{{paramName}},{{/allParams}} progressListener, progressRequestListener); + Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener); {{#returnType}}Type {{localVariablePrefix}}returnType = new TypeToken<{{{returnType}}}>(){}.getType(); {{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}returnType, {{localVariablePrefix}}callback);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}callback);{{/returnType}} return {{localVariablePrefix}}call; diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache index 84c799d62520..9d758bddd212 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache @@ -26,7 +26,7 @@ public interface {{classname}} { {{#formParams}}{{#-first}} {{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}} @{{httpMethod}}("{{path}}") - {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}} {{nickname}}({{^allParams}});{{/allParams}} + {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}} {{operationId}}({{^allParams}});{{/allParams}} {{#allParams}}{{>libraries/retrofit/queryParams}}{{>libraries/retrofit/pathParams}}{{>libraries/retrofit/headerParams}}{{>libraries/retrofit/bodyParams}}{{>libraries/retrofit/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}} );{{/hasMore}}{{/allParams}} @@ -40,7 +40,7 @@ public interface {{classname}} { {{#formParams}}{{#-first}} {{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}} @{{httpMethod}}("{{path}}") - void {{nickname}}( + void {{operationId}}( {{#allParams}}{{>libraries/retrofit/queryParams}}{{>libraries/retrofit/pathParams}}{{>libraries/retrofit/headerParams}}{{>libraries/retrofit/bodyParams}}{{>libraries/retrofit/formParams}}, {{/allParams}}Callback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> cb ); {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache index d0205c3d0b1e..a066a625cffa 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache @@ -25,7 +25,7 @@ public interface {{classname}} { {{#formParams}}{{#-first}} {{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}} @{{httpMethod}}("{{path}}") - Call<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> {{nickname}}({{^allParams}});{{/allParams}} + Call<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> {{operationId}}({{^allParams}});{{/allParams}} {{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}} );{{/hasMore}}{{/allParams}} diff --git a/modules/swagger-codegen/src/main/resources/JavaInflector/api.mustache b/modules/swagger-codegen/src/main/resources/JavaInflector/api.mustache index 74e688ee23e0..0a5e225306ce 100644 --- a/modules/swagger-codegen/src/main/resources/JavaInflector/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaInflector/api.mustache @@ -24,7 +24,7 @@ public class {{classname}} { {{#operation}} /* - public ResponseContext {{nickname}}(RequestContext request {{#allParams}}, {{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{/allParams}}) { + public ResponseContext {{operationId}}(RequestContext request {{#allParams}}, {{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{/allParams}}) { return new ResponseContext().status(Status.INTERNAL_SERVER_ERROR).entity( "Not implemented" ); } */ diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache index ea9f2518b019..da3eba49461a 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache @@ -47,10 +47,10 @@ public class {{classname}} { @io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}){{#hasMore}}, {{/hasMore}}{{/responses}} }) - public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, + public Response {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws NotFoundException { - return delegate.{{nickname}}({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}}); + return delegate.{{operationId}}({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}}); } {{/operation}} } diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/api.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/api.mustache index 6eb6358a7026..a882c0069754 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/api.mustache @@ -50,7 +50,7 @@ public class {{classname}} { {{#hasProduces}}produces = { {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}} {{#hasConsumes}}consumes = { {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}} method = RequestMethod.{{httpMethod}}) - public ResponseEntity<{{>returnTypes}}> {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, + public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws NotFoundException { // do some magic! diff --git a/modules/swagger-codegen/src/main/resources/clojure/api.mustache b/modules/swagger-codegen/src/main/resources/clojure/api.mustache index 1acdf94d764a..94e95dffaf76 100644 --- a/modules/swagger-codegen/src/main/resources/clojure/api.mustache +++ b/modules/swagger-codegen/src/main/resources/clojure/api.mustache @@ -2,10 +2,10 @@ (:require [.core :refer [call-api check-required-params]]) (:import (java.io File))) <#operations><#operation> -(defn +(defn "<&summary><#notes> <¬es>"<#hasOptionalParams> - ([<#allParams><#required><#isFile>^File ] (<#allParams><#required> nil)) + ([<#allParams><#required><#isFile>^File ] (<#allParams><#required> nil)) <#hasOptionalParams>([<#allParams><#required><#isFile>^File <#hasOptionalParams>{:keys [<#allParams><^required><#isFile>^File ]}]<#hasRequiredParams> <#hasOptionalParams> (check-required-params<#allParams><#required> ) <#hasOptionalParams> (call-api "" : diff --git a/modules/swagger-codegen/src/main/resources/codegen/api.template b/modules/swagger-codegen/src/main/resources/codegen/api.template index 9dbc8dd4ba13..62802f7f1e78 100644 --- a/modules/swagger-codegen/src/main/resources/codegen/api.template +++ b/modules/swagger-codegen/src/main/resources/codegen/api.template @@ -14,8 +14,8 @@ classname: {{classname}} # loop over each operation in the API: {{#operation}} -# each operation has a `nickname`: -nickname: {{nickname}} +# each operation has an `operationId`: +operationId: {{operationId}} # and parameters: {{#allParams}} diff --git a/modules/swagger-codegen/src/main/resources/flaskConnexion/controller.mustache b/modules/swagger-codegen/src/main/resources/flaskConnexion/controller.mustache index cb8544aa1b43..06b3c63fdb06 100644 --- a/modules/swagger-codegen/src/main/resources/flaskConnexion/controller.mustache +++ b/modules/swagger-codegen/src/main/resources/flaskConnexion/controller.mustache @@ -3,7 +3,7 @@ {{#operations}} {{#operation}} -def {{vendorExtensions.x-operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> str: +def {{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> str: return 'do some magic!' {{/operation}} {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index a43260c06079..b8e2e0da4c88 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -16,13 +16,13 @@ module {{moduleName}} {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} {{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}] - def {{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) + def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) if Configuration.debugging - Configuration.logger.debug "Calling API: {{classname}}#{{nickname}} ..." + Configuration.logger.debug "Calling API: {{classname}}#{{operationId}} ..." end {{#allParams}}{{#required}} # verify the required parameter '{{paramName}}' is set - fail "Missing the required parameter '{{paramName}}' when calling {{nickname}}" if {{{paramName}}}.nil?{{#isEnum}} + fail "Missing the required parameter '{{paramName}}' when calling {{operationId}}" if {{{paramName}}}.nil?{{#isEnum}} unless [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}}) fail "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}" end{{/isEnum}} @@ -71,7 +71,7 @@ module {{moduleName}} :auth_names => auth_names, :return_type => '{{{returnType}}}') if Configuration.debugging - Configuration.logger.debug "API called: {{classname}}#{{nickname}}. Result: #{result.inspect}" + Configuration.logger.debug "API called: {{classname}}#{{operationId}}. Result: #{result.inspect}" end return result{{/returnType}}{{^returnType}}@api_client.call_api(:{{httpMethod}}, path, :header_params => header_params, @@ -80,7 +80,7 @@ module {{moduleName}} :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: {{classname}}#{{nickname}}" + Configuration.logger.debug "API called: {{classname}}#{{operationId}}" end return nil{{/returnType}} end diff --git a/modules/swagger-codegen/src/main/resources/scala/api.mustache b/modules/swagger-codegen/src/main/resources/scala/api.mustache index 87b04b5900f7..3b74dca81626 100644 --- a/modules/swagger-codegen/src/main/resources/scala/api.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/api.mustache @@ -30,7 +30,7 @@ class {{classname}}(val defBasePath: String = "{{basePath}}", {{#allParams}} * @param {{paramName}} {{description}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ - def {{nickname}} ({{#allParams}}{{paramName}}: {{dataType}}{{#defaultValue}} /* = {{{defaultValue}}} */{{/defaultValue}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#returnType}}: Option[{{returnType}}]{{/returnType}} = { + def {{operationId}} ({{#allParams}}{{paramName}}: {{dataType}}{{#defaultValue}} /* = {{{defaultValue}}} */{{/defaultValue}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#returnType}}: Option[{{returnType}}]{{/returnType}} = { // create path and map variables val path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{baseName}}" + "\\}",apiInvoker.escape({{paramName}})) diff --git a/samples/server/petstore/flaskConnexion/README.md b/samples/server/petstore/flaskConnexion/README.md index d85f471ba406..2b8c96e6170e 100644 --- a/samples/server/petstore/flaskConnexion/README.md +++ b/samples/server/petstore/flaskConnexion/README.md @@ -3,7 +3,7 @@ ## Overview This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This -is an example of building a swagger-enabled JAX-RS server. +is an example of building a swagger-enabled flask server. This example uses the [connexion](https://github.com/zalando/connexion) library on top of Flask. diff --git a/samples/server/petstore/flaskConnexion/controllers/default_controller.py b/samples/server/petstore/flaskConnexion/controllers/default_controller.py index 8d771afed91c..d42c48575d1e 100644 --- a/samples/server/petstore/flaskConnexion/controllers/default_controller.py +++ b/samples/server/petstore/flaskConnexion/controllers/default_controller.py @@ -23,6 +23,18 @@ def update_user(username, body) -> str: def delete_user(username) -> str: return 'do some magic!' +def get_inventory() -> str: + return 'do some magic!' + +def place_order(body) -> str: + return 'do some magic!' + +def get_order_by_id(orderId) -> str: + return 'do some magic!' + +def delete_order(orderId) -> str: + return 'do some magic!' + def update_pet(body) -> str: return 'do some magic!' @@ -46,15 +58,3 @@ def delete_pet(petId, apiKey) -> str: def upload_file(petId, additionalMetadata, file) -> str: return 'do some magic!' - -def get_inventory() -> str: - return 'do some magic!' - -def place_order(body) -> str: - return 'do some magic!' - -def get_order_by_id(orderId) -> str: - return 'do some magic!' - -def delete_order(orderId) -> str: - return 'do some magic!' diff --git a/samples/server/petstore/flaskConnexion/swagger/swagger.yaml b/samples/server/petstore/flaskConnexion/swagger/swagger.yaml index 047d1652a87e..1a4ff85e60ab 100644 --- a/samples/server/petstore/flaskConnexion/swagger/swagger.yaml +++ b/samples/server/petstore/flaskConnexion/swagger/swagger.yaml @@ -45,7 +45,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "add_pet" x-tags: - tag: "pet" put: @@ -78,7 +77,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "update_pet" x-tags: - tag: "pet" /pet/findByStatus: @@ -114,7 +112,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "find_pets_by_status" x-tags: - tag: "pet" /pet/findByTags: @@ -150,7 +147,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "find_pets_by_tags" x-tags: - tag: "pet" /pet/{petId}: @@ -185,7 +181,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "get_pet_by_id" x-tags: - tag: "pet" post: @@ -222,7 +217,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "update_pet_with_form" x-tags: - tag: "pet" delete: @@ -253,7 +247,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "delete_pet" x-tags: - tag: "pet" /pet/{petId}/uploadImage: @@ -292,7 +285,6 @@ paths: - petstore_auth: - "write:pets" - "read:pets" - x-operationId: "upload_file" x-tags: - tag: "pet" /store/inventory: @@ -316,7 +308,6 @@ paths: format: "int32" security: - api_key: [] - x-operationId: "get_inventory" x-tags: - tag: "store" /store/order: @@ -343,7 +334,6 @@ paths: $ref: "#/definitions/Order" 400: description: "Invalid Order" - x-operationId: "place_order" x-tags: - tag: "store" /store/order/{orderId}: @@ -372,7 +362,6 @@ paths: description: "Invalid ID supplied" 404: description: "Order not found" - x-operationId: "get_order_by_id" x-tags: - tag: "store" delete: @@ -396,7 +385,6 @@ paths: description: "Invalid ID supplied" 404: description: "Order not found" - x-operationId: "delete_order" x-tags: - tag: "store" /user: @@ -419,7 +407,6 @@ paths: responses: default: description: "successful operation" - x-operationId: "create_user" x-tags: - tag: "user" /user/createWithArray: @@ -444,7 +431,6 @@ paths: responses: default: description: "successful operation" - x-operationId: "create_users_with_array_input" x-tags: - tag: "user" /user/createWithList: @@ -469,7 +455,6 @@ paths: responses: default: description: "successful operation" - x-operationId: "create_users_with_list_input" x-tags: - tag: "user" /user/login: @@ -500,7 +485,6 @@ paths: type: "string" 400: description: "Invalid username/password supplied" - x-operationId: "login_user" x-tags: - tag: "user" /user/logout: @@ -517,7 +501,6 @@ paths: responses: default: description: "successful operation" - x-operationId: "logout_user" x-tags: - tag: "user" /user/{username}: @@ -555,7 +538,6 @@ paths: description: "Invalid username supplied" 404: description: "User not found" - x-operationId: "get_user_by_name" x-tags: - tag: "user" put: @@ -584,7 +566,6 @@ paths: description: "Invalid user supplied" 404: description: "User not found" - x-operationId: "update_user" x-tags: - tag: "user" delete: @@ -607,14 +588,9 @@ paths: description: "Invalid username supplied" 404: description: "User not found" - x-operationId: "delete_user" x-tags: - tag: "user" securityDefinitions: - api_key: - type: "apiKey" - name: "api_key" - in: "header" petstore_auth: type: "oauth2" authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" @@ -622,6 +598,10 @@ securityDefinitions: scopes: write:pets: "modify pets in your account" read:pets: "read your pets" + api_key: + type: "apiKey" + name: "api_key" + in: "header" definitions: User: properties: