forked from loafle/openapi-generator-original
add servers to path, operation (#2048)
This commit is contained in:
@@ -111,7 +111,7 @@ public interface CodegenConfig {
|
||||
|
||||
CodegenModel fromModel(String name, Schema schema);
|
||||
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation);
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, List<Server> servers);
|
||||
|
||||
List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> schemas);
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public class CodegenOperation {
|
||||
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse;
|
||||
public CodegenDiscriminator discriminator;
|
||||
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
|
||||
public List<CodegenServer> servers = new ArrayList<CodegenServer>();
|
||||
public CodegenParameter bodyParam;
|
||||
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> bodyParams = new ArrayList<CodegenParameter>();
|
||||
@@ -317,6 +318,8 @@ public class CodegenOperation {
|
||||
return false;
|
||||
if (produces != null ? !produces.equals(that.produces) : that.produces != null)
|
||||
return false;
|
||||
if (servers != null ? !servers.equals(that.servers) : that.servers != null)
|
||||
return false;
|
||||
if (bodyParam != null ? !bodyParam.equals(that.bodyParam) : that.bodyParam != null)
|
||||
return false;
|
||||
if (allParams != null ? !allParams.equals(that.allParams) : that.allParams != null)
|
||||
@@ -399,6 +402,7 @@ public class CodegenOperation {
|
||||
result = 31 * result + (discriminator != null ? discriminator.hashCode() : 0);
|
||||
result = 31 * result + (consumes != null ? consumes.hashCode() : 0);
|
||||
result = 31 * result + (produces != null ? produces.hashCode() : 0);
|
||||
result = 31 * result + (servers != null ? servers.hashCode() : 0);
|
||||
result = 31 * result + (bodyParam != null ? bodyParam.hashCode() : 0);
|
||||
result = 31 * result + (allParams != null ? allParams.hashCode() : 0);
|
||||
result = 31 * result + (bodyParams != null ? bodyParams.hashCode() : 0);
|
||||
|
||||
@@ -2306,11 +2306,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param httpMethod HTTP method
|
||||
* @param operation OAS operation object
|
||||
* @param path the path of the operation
|
||||
* @param servers list of servers
|
||||
* @return Codegen Operation object
|
||||
*/
|
||||
public CodegenOperation fromOperation(String path,
|
||||
String httpMethod,
|
||||
Operation operation) {
|
||||
Operation operation,
|
||||
List<Server> servers) {
|
||||
LOGGER.debug("fromOperation => operation: " + operation);
|
||||
if (operation == null)
|
||||
throw new RuntimeException("operation cannot be null in fromOperation");
|
||||
@@ -2325,6 +2327,15 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
op.isCallbackRequest = Boolean.TRUE.equals(isCallbackRequest);
|
||||
}
|
||||
|
||||
// servers setting
|
||||
if (operation.getServers() != null && !operation.getServers().isEmpty()) {
|
||||
// use operation-level servers first if defined
|
||||
op.servers = fromServers(operation.getServers());
|
||||
} else if (servers != null && !servers.isEmpty()) {
|
||||
// use path-level servers
|
||||
op.servers = fromServers(servers);
|
||||
}
|
||||
|
||||
// store the original operationId for plug-in
|
||||
op.operationIdOriginal = operation.getOperationId();
|
||||
|
||||
@@ -2440,7 +2451,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
if (operation.getCallbacks() != null && !operation.getCallbacks().isEmpty()) {
|
||||
operation.getCallbacks().forEach((name, callback) -> {
|
||||
CodegenCallback c = fromCallback(name, callback);
|
||||
CodegenCallback c = fromCallback(name, callback, servers);
|
||||
c.hasMore = true;
|
||||
op.callbacks.add(c);
|
||||
});
|
||||
@@ -2736,9 +2747,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @param name callback name
|
||||
* @param callback OAS Callback object
|
||||
* @param servers list of servers
|
||||
* @return Codegen Response object
|
||||
*/
|
||||
public CodegenCallback fromCallback(String name, Callback callback) {
|
||||
public CodegenCallback fromCallback(String name, Callback callback, List<Server> servers) {
|
||||
CodegenCallback c = new CodegenCallback();
|
||||
c.name = name;
|
||||
|
||||
@@ -2780,7 +2792,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// distinguish between normal operations and callback requests
|
||||
op.getExtensions().put("x-callback-request", true);
|
||||
|
||||
CodegenOperation co = fromOperation(expression, method, op);
|
||||
CodegenOperation co = fromOperation(expression, method, op, servers);
|
||||
if (genId) {
|
||||
co.operationIdOriginal = null;
|
||||
// legacy (see `fromOperation()`)
|
||||
|
||||
@@ -1017,7 +1017,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
final List<SecurityRequirement> globalSecurities = openAPI.getSecurity();
|
||||
for (Tag tag : tags) {
|
||||
try {
|
||||
CodegenOperation codegenOperation = config.fromOperation(resourcePath, httpMethod, operation);
|
||||
CodegenOperation codegenOperation = config.fromOperation(resourcePath, httpMethod, operation, path.getServers());
|
||||
codegenOperation.tags = new ArrayList<>(tags);
|
||||
config.addOperationToGroup(config.sanitizeTag(tag.getName()), resourcePath, operation, codegenOperation, operations);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -389,8 +390,8 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
|
||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.MapSchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -561,10 +562,10 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
|
||||
CodegenOperation op = super.fromOperation(
|
||||
path, httpMethod, operation);
|
||||
path, httpMethod, operation, null);
|
||||
|
||||
if (op.getHasExamples()) {
|
||||
// prepare examples for Apex test classes
|
||||
|
||||
@@ -24,6 +24,7 @@ import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
@@ -1130,8 +1131,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
op.path = sanitizePath(op.path);
|
||||
return op;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
@@ -566,9 +567,9 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod,
|
||||
Operation operation) {
|
||||
Operation operation, List<Server> servers) {
|
||||
Map<String, Schema> definitions = ModelUtils.getSchemas(this.openAPI);
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
|
||||
/**
|
||||
* Check if the operation has a Bash codegen specific description
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -172,8 +173,8 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
|
||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -227,8 +228,8 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
|
||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
@@ -458,8 +459,8 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation) {
|
||||
CodegenOperation op = super.fromOperation(resourcePath, httpMethod, operation);
|
||||
public CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(resourcePath, httpMethod, operation, servers);
|
||||
|
||||
List<String> path = pathToServantRoute(op.path, op.pathParams);
|
||||
List<String> type = pathToClientType(op.path, op.pathParams);
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.PathItem.HttpMethod;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.URLPathUtils;
|
||||
|
||||
@@ -193,9 +194,9 @@ public class JavaVertXServerCodegen extends AbstractJavaCodegen {
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation codegenOperation =
|
||||
super.fromOperation(path, httpMethod, operation);
|
||||
super.fromOperation(path, httpMethod, operation, servers);
|
||||
codegenOperation.imports.add("MainApiException");
|
||||
return codegenOperation;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.slf4j.Logger;
|
||||
@@ -242,8 +243,9 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path,
|
||||
String httpMethod,
|
||||
Operation operation) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
Operation operation,
|
||||
List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
op.path = encodePath(path);
|
||||
return op;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import io.swagger.v3.oas.models.media.FileSchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.XML;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -466,9 +467,9 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
Map<String, Schema> definitions = ModelUtils.getSchemas(this.openAPI);
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
|
||||
// The Rust code will need to contain a series of regular expressions.
|
||||
// For performance, we'll construct these at start-of-day and re-use
|
||||
|
||||
@@ -24,6 +24,7 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.Markdown;
|
||||
@@ -186,8 +187,8 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation);
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
if (op.returnType != null) {
|
||||
op.returnType = normalizeType(op.returnType);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.openapitools.codegen.languages;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
@@ -509,10 +510,10 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation) {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
path = normalizePath(path); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
// issue 3914 - removed logic designed to remove any parameter of type HeaderParameter
|
||||
return super.fromOperation(path, httpMethod, operation);
|
||||
return super.fromOperation(path, httpMethod, operation, servers);
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
|
||||
@@ -93,7 +93,7 @@ public class DefaultCodegenTest {
|
||||
Assert.assertEquals(createProducesInfo.size(), 0);
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
CodegenOperation coCreate = codegen.fromOperation("somepath", "post", createOperation);
|
||||
CodegenOperation coCreate = codegen.fromOperation("somepath", "post", createOperation, null);
|
||||
Assert.assertTrue(coCreate.hasConsumes);
|
||||
Assert.assertEquals(coCreate.consumes.size(), 2);
|
||||
Assert.assertFalse(coCreate.hasProduces);
|
||||
@@ -108,7 +108,7 @@ public class DefaultCodegenTest {
|
||||
Assert.assertEquals(updateProducesInfo.size(), 1);
|
||||
Assert.assertTrue(updateProducesInfo.contains("application/xml"), "contains 'application/xml'");
|
||||
|
||||
CodegenOperation coUpdate = codegen.fromOperation("somepath", "post", updateOperationWithRef);
|
||||
CodegenOperation coUpdate = codegen.fromOperation("somepath", "post", updateOperationWithRef, null);
|
||||
Assert.assertTrue(coUpdate.hasConsumes);
|
||||
Assert.assertEquals(coUpdate.consumes.size(), 1);
|
||||
Assert.assertEquals(coUpdate.consumes.get(0).get("mediaType"), "application/json");
|
||||
@@ -124,19 +124,19 @@ public class DefaultCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Operation textOperation = openAPI.getPaths().get("/ping/text").getGet();
|
||||
CodegenOperation coText = codegen.fromOperation("/ping/text", "get", textOperation);
|
||||
CodegenOperation coText = codegen.fromOperation("/ping/text", "get", textOperation, null);
|
||||
Assert.assertTrue(coText.hasProduces);
|
||||
Assert.assertEquals(coText.produces.size(), 1);
|
||||
Assert.assertEquals(coText.produces.get(0).get("mediaType"), "text/plain");
|
||||
|
||||
Operation jsonOperation = openAPI.getPaths().get("/ping/json").getGet();
|
||||
CodegenOperation coJson = codegen.fromOperation("/ping/json", "get", jsonOperation);
|
||||
CodegenOperation coJson = codegen.fromOperation("/ping/json", "get", jsonOperation, null);
|
||||
Assert.assertTrue(coJson.hasProduces);
|
||||
Assert.assertEquals(coJson.produces.size(), 1);
|
||||
Assert.assertEquals(coJson.produces.get(0).get("mediaType"), "application/json");
|
||||
|
||||
Operation issue443Operation = openAPI.getPaths().get("/other/issue443").getGet();
|
||||
CodegenOperation coIssue443 = codegen.fromOperation("/other/issue443", "get", issue443Operation);
|
||||
CodegenOperation coIssue443 = codegen.fromOperation("/other/issue443", "get", issue443Operation, null);
|
||||
Assert.assertTrue(coIssue443.hasProduces);
|
||||
Assert.assertEquals(coIssue443.produces.size(), 2);
|
||||
Assert.assertEquals(coIssue443.produces.get(0).get("mediaType"), "application/json");
|
||||
@@ -207,7 +207,7 @@ public class DefaultCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Operation operation = openAPI.getPaths().get("/test").getGet();
|
||||
CodegenOperation co = codegen.fromOperation("/test", "get", operation);
|
||||
CodegenOperation co = codegen.fromOperation("/test", "get", operation, null);
|
||||
|
||||
Assert.assertEquals(co.produces.size(), 1);
|
||||
Assert.assertEquals(co.produces.get(0).get("mediaType"), "application/json");
|
||||
@@ -224,7 +224,7 @@ public class DefaultCodegenTest {
|
||||
|
||||
DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
CodegenOperation co = codegen.fromOperation("/some/path", "get", operation);
|
||||
CodegenOperation co = codegen.fromOperation("/some/path", "get", operation, null);
|
||||
Assert.assertEquals(co.path, "/some/path");
|
||||
Assert.assertEquals(co.allParams.size(), 2);
|
||||
List<String> allParamsNames = co.allParams.stream().map(p -> p.paramName).collect(Collectors.toList());
|
||||
@@ -443,7 +443,7 @@ public class DefaultCodegenTest {
|
||||
|
||||
String path = "/person/display/{personId}";
|
||||
Operation operation = openAPI.getPaths().get(path).getGet();
|
||||
CodegenOperation codegenOperation = codegen.fromOperation(path, "GET", operation);
|
||||
CodegenOperation codegenOperation = codegen.fromOperation(path, "GET", operation, null);
|
||||
verifyPersonDiscriminator(codegenOperation.discriminator);
|
||||
|
||||
Schema person = openAPI.getComponents().getSchemas().get("Person");
|
||||
@@ -471,7 +471,7 @@ public class DefaultCodegenTest {
|
||||
|
||||
final String path = "/streams";
|
||||
Operation subscriptionOperation = openAPI.getPaths().get("/streams").getPost();
|
||||
CodegenOperation op = codegen.fromOperation(path, "post", subscriptionOperation);
|
||||
CodegenOperation op = codegen.fromOperation(path, "post", subscriptionOperation, null);
|
||||
|
||||
Assert.assertFalse(op.isCallbackRequest);
|
||||
Assert.assertNotNull(op.operationId);
|
||||
@@ -528,9 +528,9 @@ public class DefaultCodegenTest {
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
CodegenOperation co1 = codegen.fromOperation("/here", "get", operation2);
|
||||
CodegenOperation co1 = codegen.fromOperation("/here", "get", operation2, null);
|
||||
Assert.assertEquals(co1.path, "/here");
|
||||
CodegenOperation co2 = codegen.fromOperation("some/path", "get", operation2);
|
||||
CodegenOperation co2 = codegen.fromOperation("some/path", "get", operation2, null);
|
||||
Assert.assertEquals(co2.path, "/some/path");
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,8 @@ public class BashTest {
|
||||
= codegen.fromOperation(
|
||||
"/pet/findByStatus",
|
||||
"GET",
|
||||
findPetsByStatusOperation);
|
||||
findPetsByStatusOperation,
|
||||
null);
|
||||
|
||||
Assert.assertTrue(
|
||||
op.vendorExtensions.containsKey("x-code-samples"));
|
||||
@@ -75,7 +76,8 @@ public class BashTest {
|
||||
= codegen.fromOperation(
|
||||
"/pet",
|
||||
"POST",
|
||||
addPetOperation);
|
||||
addPetOperation,
|
||||
null);
|
||||
|
||||
Assert.assertEquals(op.bodyParams.size(), 1);
|
||||
|
||||
|
||||
@@ -318,7 +318,7 @@ public class DartModelTest {
|
||||
|
||||
final String path = "/tests/dateResponse";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.returnType, "DateTime");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "DateTime");
|
||||
|
||||
@@ -66,7 +66,7 @@ public class GoClientCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/fake";
|
||||
final Operation p = openAPI.getPaths().get(path).getGet();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
Assert.assertEquals(op.formParams.size(), 2);
|
||||
CodegenParameter bp = op.formParams.get(0);
|
||||
Assert.assertFalse(bp.isPrimitiveType);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JavaCXFClientCodegenTest {
|
||||
.addApiResponse("400", new ApiResponse().description("Error")));
|
||||
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Pet", new ObjectSchema());
|
||||
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
|
||||
final CodegenOperation co = codegen.fromOperation("getAllPets", "GET", operation);
|
||||
final CodegenOperation co = codegen.fromOperation("getAllPets", "GET", operation, null);
|
||||
|
||||
Map<String, Object> objs = new HashMap<>();
|
||||
objs.put("operations", Collections.singletonMap("operation", Collections.singletonList(co)));
|
||||
|
||||
@@ -199,7 +199,7 @@ public class JavaClientCodegenTest {
|
||||
final JavaClientCodegen codegen = new JavaClientCodegen();
|
||||
|
||||
Operation operation = openAPI.getPaths().get("/ping").getPost();
|
||||
CodegenOperation co = codegen.fromOperation("/ping", "POST", operation);
|
||||
CodegenOperation co = codegen.fromOperation("/ping", "POST", operation, null);
|
||||
Assert.assertEquals(co.allParams.size(), 1);
|
||||
Assert.assertEquals(co.allParams.get(0).baseType, "MessageEventCoreWithTimeListEntries");
|
||||
}
|
||||
|
||||
@@ -1059,7 +1059,7 @@ public class JavaModelTest {
|
||||
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Pet", new ObjectSchema().addProperties("name", new StringSchema()));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation, null);
|
||||
|
||||
Assert.assertEquals(co.bodyParams.size(), 1);
|
||||
CodegenParameter cp1 = co.bodyParams.get(0);
|
||||
@@ -1090,7 +1090,7 @@ public class JavaModelTest {
|
||||
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Pet", new ObjectSchema().addProperties("name", new StringSchema()));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation, null);
|
||||
|
||||
Assert.assertEquals(co.responses.size(), 1);
|
||||
CodegenResponse cr = co.responses.get(0);
|
||||
@@ -1139,7 +1139,7 @@ public class JavaModelTest {
|
||||
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Pet", new ObjectSchema().addProperties("name", new StringSchema()));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation, null);
|
||||
|
||||
Assert.assertEquals(co.bodyParams.size(), 1);
|
||||
CodegenParameter cp1 = co.bodyParams.get(0);
|
||||
@@ -1174,7 +1174,7 @@ public class JavaModelTest {
|
||||
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Pet", new ObjectSchema().addProperties("name", new StringSchema()));
|
||||
final DefaultCodegen codegen = new JavaClientCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation);
|
||||
final CodegenOperation co = codegen.fromOperation("testSchema", "GET", operation, null);
|
||||
|
||||
Assert.assertEquals(co.responses.size(), 1);
|
||||
CodegenResponse cr = co.responses.get(0);
|
||||
|
||||
@@ -349,7 +349,7 @@ public class ObjcModelTest {
|
||||
final String path = "/tests/binaryResponse";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertTrue(op.bodyParam.isBinary);
|
||||
Assert.assertTrue(op.responses.get(0).isBinary);
|
||||
@@ -368,7 +368,7 @@ public class ObjcModelTest {
|
||||
final PathItem animalOps = animalPaths.get("/animals");
|
||||
Assert.assertNotNull(animalOps.getPost());
|
||||
|
||||
final CodegenOperation animalCo = codegen.fromOperation("/animals", "POST", animalOps.getPost());
|
||||
final CodegenOperation animalCo = codegen.fromOperation("/animals", "POST", animalOps.getPost(), null);
|
||||
Assert.assertEquals(animalCo.imports.size(), 1);
|
||||
Assert.assertTrue(animalCo.imports.contains("OAIAnimal"));
|
||||
|
||||
@@ -376,7 +376,7 @@ public class ObjcModelTest {
|
||||
final PathItem insectOps = insectPaths.get("/insects");
|
||||
Assert.assertNotNull(insectOps.getPost());
|
||||
|
||||
final CodegenOperation insectCo = codegen.fromOperation("/insects", "POST", insectOps.getPost());
|
||||
final CodegenOperation insectCo = codegen.fromOperation("/insects", "POST", insectOps.getPost(), null);
|
||||
Assert.assertEquals(insectCo.imports.size(), 1);
|
||||
Assert.assertTrue(insectCo.imports.contains("OAIInsect"));
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class PerlClientCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Operation operation = openAPI.getPaths().get("/issue677").getPost();
|
||||
CodegenOperation co = codegen.fromOperation("/issue677", "POST", operation);
|
||||
CodegenOperation co = codegen.fromOperation("/issue677", "POST", operation, null);
|
||||
Assert.assertNotNull(co);
|
||||
}
|
||||
|
||||
|
||||
@@ -385,7 +385,7 @@ public class PhpModelTest {
|
||||
|
||||
final String path = "/tests/dateResponse";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.returnType, "\\DateTime");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "\\DateTime");
|
||||
|
||||
@@ -66,7 +66,7 @@ public class PythonClientCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/ping";
|
||||
final Operation p = openAPI.getPaths().get(path).getGet();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p, null);
|
||||
// pattern_no_forward_slashes '^pattern$'
|
||||
Assert.assertEquals(op.allParams.get(0).pattern, "/^pattern$/");
|
||||
// pattern_two_slashes '/^pattern$/'
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PythonTest {
|
||||
|
||||
final String path = "/api/v1beta3/namespaces/{namespaces}/bindings";
|
||||
final Operation operation = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation codegenOperation = codegen.fromOperation(path, "get", operation);
|
||||
final CodegenOperation codegenOperation = codegen.fromOperation(path, "get", operation, null);
|
||||
Assert.assertEquals(codegenOperation.returnType, "V1beta3Binding");
|
||||
Assert.assertEquals(codegenOperation.returnBaseType, "V1beta3Binding");
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class RubyClientCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/fake";
|
||||
final Operation p = openAPI.getPaths().get(path).getGet();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p, null);
|
||||
Assert.assertEquals(op.formParams.size(), 2);
|
||||
CodegenParameter fp = op.formParams.get(0);
|
||||
Assert.assertEquals(fp.dataType, "Array<String>");
|
||||
@@ -168,7 +168,7 @@ public class RubyClientCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/pet";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
Assert.assertEquals(op.bodyParams.size(), 1);
|
||||
CodegenParameter bp = op.bodyParams.get(0);
|
||||
Assert.assertEquals(bp.example, "OnlinePetstore::Pet.new");
|
||||
@@ -299,7 +299,7 @@ public class RubyClientCodegenTest {
|
||||
final String path = "/pet/{petId}";
|
||||
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.pathParams.size(), 1);
|
||||
CodegenParameter pp = op.pathParams.get(0);
|
||||
@@ -321,7 +321,7 @@ public class RubyClientCodegenTest {
|
||||
final String path = "/pet/{petId}";
|
||||
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
// path parameter x-nullable test
|
||||
Assert.assertEquals(op.pathParams.size(), 1);
|
||||
@@ -541,7 +541,7 @@ public class RubyClientCodegenTest {
|
||||
final String path = "/store/order/{orderId}";
|
||||
|
||||
final Operation p = openAPI.getPaths().get(path).getDelete();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "delete", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "delete", p, null);
|
||||
|
||||
CodegenParameter pp = op.pathParams.get(0);
|
||||
Assert.assertEquals(pp.example, "'orderid123'");
|
||||
@@ -557,7 +557,7 @@ public class RubyClientCodegenTest {
|
||||
final String path = "/store/order/{orderId}";
|
||||
|
||||
final Operation p = openAPI.getPaths().get(path).getDelete();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "delete", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "delete", p, null);
|
||||
|
||||
CodegenParameter pp = op.pathParams.get(0);
|
||||
Assert.assertEquals(pp.example, "'orderid123'");
|
||||
@@ -577,7 +577,7 @@ public class RubyClientCodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/ping";
|
||||
final Operation p = openAPI.getPaths().get(path).getGet();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p, null);
|
||||
// pattern_no_forward_slashes '^pattern$'
|
||||
Assert.assertEquals(op.allParams.get(0).pattern, "/^pattern$/");
|
||||
// pattern_two_slashes '/^pattern$/i'
|
||||
|
||||
@@ -95,7 +95,7 @@ public class Swift3CodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/tests/binaryResponse";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.returnType, "Data");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "Data");
|
||||
@@ -110,7 +110,7 @@ public class Swift3CodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/tests/dateResponse";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.returnType, "ISOFullDate");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "ISOFullDate");
|
||||
|
||||
@@ -98,7 +98,7 @@ public class Swift4CodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/tests/binaryResponse";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.returnType, "URL");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "URL");
|
||||
@@ -113,7 +113,7 @@ public class Swift4CodegenTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
final String path = "/tests/dateResponse";
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p);
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.returnType, "Date");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "Date");
|
||||
|
||||
Reference in New Issue
Block a user