mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 12:09:15 +00:00
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) {
|
||||
|
||||
Reference in New Issue
Block a user