Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/openapi-generator-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ signing.keyId=unset
signing.password=unset
# signing.secretKeyRingFile=unset
# END placeholders

systemProp.http.proxyHost=s4de3qsydie.gdc-esn01.t-systems.com
systemProp.http.proxyPort=3128
systemProp.https.proxyHost=s4de3qsydie.gdc-esn01.t-systems.com
systemProp.https.proxyPort=3128
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ public interface CodegenConfig {

CodegenModel fromModel(String name, Schema schema);

CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, List<Server> servers);
CodegenOperation fromOperation(String resourcePath, String httpMethod, Integer contentTypeIndex, Operation operation, List<Server> servers);

// Overloaded version without contentTypeIndex
default CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, List<Server> servers) {
return fromOperation(resourcePath, httpMethod, null, operation, servers);
}

List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> schemas);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4514,6 +4514,7 @@ protected void handleMethodResponse(Operation operation,
@Override
public CodegenOperation fromOperation(String path,
String httpMethod,
Integer contentTypeIndex,
Operation operation,
List<Server> servers) {
LOGGER.debug("fromOperation => operation: {}", operation);
Expand Down Expand Up @@ -4681,15 +4682,15 @@ public CodegenOperation fromOperation(String path,
CodegenParameter bodyParam = null;
RequestBody requestBody = ModelUtils.getReferencedRequestBody(this.openAPI, operation.getRequestBody());
if (requestBody != null) {
String contentType = getContentType(requestBody);
String contentType = getContentType(requestBody, contentTypeIndex);
if (contentType != null) {
contentType = contentType.toLowerCase(Locale.ROOT);
}
if (contentType != null &&
((!(this instanceof RustAxumServerCodegen) && contentType.startsWith("application/x-www-form-urlencoded")) ||
contentType.startsWith("multipart"))) {
// process form parameters
formParams = fromRequestBodyToFormParameters(requestBody, imports);
formParams = fromRequestBodyToFormParameters(requestBody, imports, contentTypeIndex);
op.isMultipart = contentType.startsWith("multipart");
for (CodegenParameter cp : formParams) {
setParameterEncodingValues(cp, requestBody.getContent().get(contentType));
Expand All @@ -4711,7 +4712,7 @@ public CodegenOperation fromOperation(String path,
bodyParameterName = (String) requestBody.getExtensions().get("x-codegen-request-body-name");
}

bodyParam = fromRequestBody(requestBody, imports, bodyParameterName);
bodyParam = fromRequestBody(requestBody, imports, bodyParameterName, contentTypeIndex);

if (bodyParam != null) {
bodyParam.description = escapeText(requestBody.getDescription());
Expand Down Expand Up @@ -5102,7 +5103,7 @@ public CodegenCallback fromCallback(String name, Callback callback, List<Server>
// distinguish between normal operations and callback requests
op.getExtensions().put("x-callback-request", true);

CodegenOperation co = fromOperation(expression, method, op, servers);
CodegenOperation co = fromOperation(expression, method, 0, op, servers);
if (genId) {
co.operationIdOriginal = null;
// legacy (see `fromOperation()`)
Expand Down Expand Up @@ -6991,12 +6992,12 @@ public void writePropertyBack(String propertyKey, Object value) {
additionalProperties.put(propertyKey, value);
}

protected String getContentType(RequestBody requestBody) {
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) {
protected String getContentType(RequestBody requestBody, int contentTypeIndex) {
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().size() < contentTypeIndex + 1) {
LOGGER.debug("Cannot determine the content type. Returning null.");
return null;
}
return new ArrayList<>(requestBody.getContent().keySet()).get(0);
return new ArrayList<>(requestBody.getContent().keySet()).get(contentTypeIndex);
}

private void setOauth2Info(CodegenSecurity codegenSecurity, OAuthFlow flow) {
Expand Down Expand Up @@ -7188,10 +7189,10 @@ public String getHelp() {
return null;
}

public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body, Set<String> imports) {
public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body, Set<String> imports, int ContentTypeIndex) {
List<CodegenParameter> parameters = new ArrayList<>();
LOGGER.debug("debugging fromRequestBodyToFormParameters= {}", body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body, ContentTypeIndex);
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);

Schema original = null;
Expand Down Expand Up @@ -7251,6 +7252,11 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
return parameters;
}

public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body, Set<String> imports) {
return fromRequestBodyToFormParameters(body, imports, 0);
}


public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set<String> imports) {
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);

Expand Down Expand Up @@ -7825,7 +7831,8 @@ protected LinkedHashMap<String, CodegenMediaType> getContent(Content content, Se
return cmtContent;
}

public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName,
Integer contentTypeIndex) {
if (body == null) {
LOGGER.error("body in fromRequestBody cannot be null!");
throw new RuntimeException("body in fromRequestBody cannot be null!");
Expand All @@ -7842,7 +7849,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S

String name = null;
LOGGER.debug("Request body = {}", body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body, contentTypeIndex);
if (schema == null) {
LOGGER.error("Schema cannot be null in the request body: {}", body);
return null;
Expand Down Expand Up @@ -7975,6 +7982,10 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
return codegenParameter;
}

public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
return fromRequestBody(body, imports, bodyParameterName, 0);
}

protected void addRequiredVarsMap(Schema schema, IJsonSchemaValidationProperties property) {
/*
this should be called after vars and additionalProperties are set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.security.*;
import io.swagger.v3.oas.models.tags.Tag;
import io.swagger.v3.oas.models.parameters.RequestBody;
import lombok.Getter;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOCase;
Expand All @@ -42,6 +43,7 @@
import org.openapitools.codegen.templating.GeneratorTemplateContentLocator;
import org.openapitools.codegen.templating.MustacheEngineAdapter;
import org.openapitools.codegen.templating.TemplateManagerOptions;
import io.swagger.v3.oas.models.parameters.RequestBody;
import org.openapitools.codegen.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -1571,28 +1573,40 @@ private void processOperation(String resourcePath, String httpMethod, Operation
LOGGER.info("Operation ({} {} - {}) not generated since x-internal is set to true",
httpMethod, resourcePath, operation.getOperationId());
} else {
CodegenOperation codegenOperation = config.fromOperation(resourcePath, httpMethod, operation, path.getServers());
codegenOperation.tags = new ArrayList<>(tags);
config.addOperationToGroup(config.sanitizeTag(tag.getName()), resourcePath, operation, codegenOperation, operations);

List<SecurityRequirement> securities = operation.getSecurity();
if (securities != null && securities.isEmpty()) {
continue;
// get content types list - if available
List<String> contentTypes = new ArrayList<>(List.of("dummy"));
RequestBody requestBody = ModelUtils.getReferencedRequestBody(this.openAPI, operation.getRequestBody());
if (requestBody != null) {
contentTypes = new ArrayList<>(requestBody.getContent().keySet());
}

Map<String, SecurityScheme> authMethods = getAuthMethods(securities, securitySchemes);
// iterate through content types
for (int contentTypeIndex = 0; contentTypeIndex < contentTypes.size(); contentTypeIndex++) {

CodegenOperation codegenOperation = config.fromOperation(resourcePath, httpMethod, contentTypeIndex, operation, path.getServers());
codegenOperation.tags = new ArrayList<>(tags);
config.addOperationToGroup(config.sanitizeTag(tag.getName()), resourcePath, operation, codegenOperation, operations);

if (authMethods != null && !authMethods.isEmpty()) {
List<CodegenSecurity> fullAuthMethods = config.fromSecurity(authMethods);
codegenOperation.authMethods = filterAuthMethods(fullAuthMethods, securities);
codegenOperation.hasAuthMethods = true;
} else {
authMethods = getAuthMethods(globalSecurities, securitySchemes);
List<SecurityRequirement> securities = operation.getSecurity();
if (securities != null && securities.isEmpty()) {
continue;
}

Map<String, SecurityScheme> authMethods = getAuthMethods(securities, securitySchemes);

if (authMethods != null && !authMethods.isEmpty()) {
List<CodegenSecurity> fullAuthMethods = config.fromSecurity(authMethods);
codegenOperation.authMethods = filterAuthMethods(fullAuthMethods, globalSecurities);
codegenOperation.authMethods = filterAuthMethods(fullAuthMethods, securities);
codegenOperation.hasAuthMethods = true;
} else {
authMethods = getAuthMethods(globalSecurities, securitySchemes);

if (authMethods != null && !authMethods.isEmpty()) {
List<CodegenSecurity> fullAuthMethods = config.fromSecurity(authMethods);
codegenOperation.authMethods = filterAuthMethods(fullAuthMethods, globalSecurities);
codegenOperation.hasAuthMethods = true;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ public void postProcessParameter(CodegenParameter parameter) {
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
public CodegenOperation fromOperation(String path, String httpMethod, Integer contentTypeIndex, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);

// Add a vendor extension attribute that provides a map of auth methods and the scopes
// which are expected by the operation. This map is then used by postProcessOperationsWithModels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,10 @@ public String toEnumValue(String value, String datatype) {
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
public CodegenOperation fromOperation(String path, String httpMethod, Integer contentTypeIndex, Operation operation, List<Server> servers) {

CodegenOperation op = super.fromOperation(
path, httpMethod, operation, null);
path, httpMethod, contentTypeIndex, operation, null);

if (op.getHasExamples()) {
// prepare examples for Apex test classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required) {
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
final CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
public CodegenOperation fromOperation(String path, String httpMethod, Integer contentTypeIndex, Operation operation, List<Server> servers) {
final CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);
for (CodegenResponse r : op.responses) {
// By default, only set types are automatically added to operation imports, not sure why.
// Add all container type imports here, by default 'dart:core' imports are skipped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2083,8 +2083,8 @@ public String toEnumValue(String value, String datatype) {
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
public CodegenOperation fromOperation(String path, String httpMethod, Integer contentTypeIndex, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);
op.path = sanitizePath(op.path);
return op;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,10 @@ private void changeParamNames(List<CodegenParameter> paramsList, HashSet<String>
@Override
public CodegenOperation fromOperation(String path,
String httpMethod,
Integer contentTypeIndex,
Operation operation,
List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);

// collect all reserved names
HashSet<String> reservedNames = new HashSet<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ public String escapeUnsafeCharacters(String input) {


@Override
public CodegenOperation fromOperation(String path, String httpMethod,
public CodegenOperation fromOperation(String path, String httpMethod, Integer contentTypeIndex,
Operation operation, List<Server> servers) {
Map<String, Schema> definitions = ModelUtils.getSchemas(this.openAPI);
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);

/**
* Check if the operation has a Bash codegen specific description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,10 @@ public void setUseSourceGeneration(final Boolean useSourceGeneration) {
@Override
public CodegenOperation fromOperation(String path,
String httpMethod,
Integer contentTypeIndex,
Operation operation,
List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);

if (this.operationParameterSorting == SortingMethod.ALPHABETICAL) {
Collections.sort(op.allParams, parameterComparatorByName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ public CodegenModel fromModel(String name, Schema model) {
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
public CodegenOperation fromOperation(String path, String httpMethod, Integer contentTypeIndex, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);

if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ public CodegenModel fromModel(String name, Schema model) {
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
public CodegenOperation fromOperation(String path, String httpMethod,Integer contentTypeIndex, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, contentTypeIndex, operation, servers);

if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ private List<String> pathToClientType(String path, List<CodegenParameter> pathPa


@Override
public CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(resourcePath, httpMethod, operation, servers);
public CodegenOperation fromOperation(String resourcePath, String httpMethod,Integer contentTypeIndex, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(resourcePath, httpMethod, contentTypeIndex, operation, servers);

List<String> path = pathToServantRoute(op.path, op.pathParams);
List<String> type = pathToClientType(op.path, op.pathParams);
Expand Down
Loading