forked from loafle/openapi-generator-original
Merge pull request #2052 from swagger-api/issue-2001
added x-swagger-router-controller, operationId for node.js versions
This commit is contained in:
commit
c80df9ee4d
@ -8,11 +8,11 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
|
|||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
import io.swagger.codegen.*;
|
import io.swagger.codegen.*;
|
||||||
import io.swagger.models.Swagger;
|
import io.swagger.models.*;
|
||||||
import io.swagger.models.Info;
|
|
||||||
import io.swagger.util.Yaml;
|
import io.swagger.util.Yaml;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -20,9 +20,6 @@ import java.math.BigDecimal;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
||||||
@ -191,6 +188,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||||
for (CodegenOperation operation : operations) {
|
for (CodegenOperation operation : operations) {
|
||||||
operation.httpMethod = operation.httpMethod.toLowerCase();
|
operation.httpMethod = operation.httpMethod.toLowerCase();
|
||||||
|
|
||||||
List<CodegenParameter> params = operation.allParams;
|
List<CodegenParameter> params = operation.allParams;
|
||||||
if (params != null && params.size() == 0) {
|
if (params != null && params.size() == 0) {
|
||||||
operation.allParams = null;
|
operation.allParams = null;
|
||||||
@ -253,7 +251,6 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preprocessSwagger(Swagger swagger) {
|
public void preprocessSwagger(Swagger swagger) {
|
||||||
|
|
||||||
String host = swagger.getHost();
|
String host = swagger.getHost();
|
||||||
String port = "8080";
|
String port = "8080";
|
||||||
if (host != null) {
|
if (host != null) {
|
||||||
@ -273,6 +270,28 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
this.additionalProperties.put("projectName", projectName);
|
this.additionalProperties.put("projectName", projectName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// need vendor extensions for x-swagger-router-controller
|
||||||
|
Map<String, Path> paths = swagger.getPaths();
|
||||||
|
if(paths != null) {
|
||||||
|
for(String pathname : paths.keySet()) {
|
||||||
|
Path path = paths.get(pathname);
|
||||||
|
Map<HttpMethod, Operation> operationMap = path.getOperationMap();
|
||||||
|
if(operationMap != null) {
|
||||||
|
for(HttpMethod method : operationMap.keySet()) {
|
||||||
|
Operation operation = operationMap.get(method);
|
||||||
|
String tag = "default";
|
||||||
|
if(operation.getTags() != null && operation.getTags().size() > 0) {
|
||||||
|
tag = toApiName(operation.getTags().get(0));
|
||||||
|
}
|
||||||
|
if(operation.getOperationId() == null) {
|
||||||
|
operation.setOperationId(getOrGenerateOperationId(operation, pathname, method.toString()));
|
||||||
|
}
|
||||||
|
operation.getVendorExtensions().put("x-swagger-router-controller", toApiName(tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,15 +5,14 @@
|
|||||||
exports.{{nickname}} = function(args, res, next) {
|
exports.{{nickname}} = function(args, res, next) {
|
||||||
/**
|
/**
|
||||||
* parameters expected in the args:
|
* parameters expected in the args:
|
||||||
{{#allParams}}* {{paramName}} ({{dataType}})
|
{{#allParams}}* {{paramName}} ({{dataType}})
|
||||||
{{/allParams}}**/
|
{{/allParams}}**/
|
||||||
|
{{^returnType}}// no response value expected for this operation
|
||||||
var examples = {};
|
{{/returnType}}
|
||||||
{{#examples}}
|
|
||||||
examples['{{contentType}}'] = {{{example}}};
|
|
||||||
{{/examples}}
|
|
||||||
|
|
||||||
{{#returnType}}
|
{{#returnType}}
|
||||||
|
var examples = {};
|
||||||
|
{{#examples}}examples['{{contentType}}'] = {{{example}}};
|
||||||
|
{{/examples}}
|
||||||
if(Object.keys(examples).length > 0) {
|
if(Object.keys(examples).length > 0) {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
|
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
|
||||||
@ -24,5 +23,6 @@ var examples = {};
|
|||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
{{^returnType}}res.end();{{/returnType}}
|
{{^returnType}}res.end();{{/returnType}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user