forked from loafle/openapi-generator-original
Merge pull request #1614 from xhh/auto-generate-operation-id
Auto generate operationId for python-flask server codegen
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1081,31 +1081,7 @@ public class DefaultCodegen {
|
||||
Set<String> imports = new HashSet<String>();
|
||||
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
|
||||
*
|
||||
|
||||
@@ -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<HttpMethod, Operation> 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<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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}}
|
||||
|
||||
|
||||
@@ -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" );
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -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}}
|
||||
}
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
(:require [<baseNamespace>.core :refer [call-api check-required-params]])
|
||||
(:import (java.io File)))
|
||||
<#operations><#operation>
|
||||
(defn <nickname>
|
||||
(defn <operationId>
|
||||
"<&summary><#notes>
|
||||
<¬es></notes>"<#hasOptionalParams>
|
||||
([<#allParams><#required><#isFile>^File </isFile><paramName> </required></allParams>] (<nickname><#allParams><#required> <paramName></required></allParams> nil))</hasOptionalParams>
|
||||
([<#allParams><#required><#isFile>^File </isFile><paramName> </required></allParams>] (<operationId><#allParams><#required> <paramName></required></allParams> nil))</hasOptionalParams>
|
||||
<#hasOptionalParams>(</hasOptionalParams>[<#allParams><#required><#isFile>^File </isFile><paramName> </required></allParams><#hasOptionalParams>{:keys [<#allParams><^required><#isFile>^File </isFile><paramName> </required></allParams>]}</hasOptionalParams>]<#hasRequiredParams>
|
||||
<#hasOptionalParams> </hasOptionalParams>(check-required-params<#allParams><#required> <paramName></required></allParams>)</hasRequiredParams>
|
||||
<#hasOptionalParams> </hasOptionalParams>(call-api "<path>" :<httpMethod>
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}}))
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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!'
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user