Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.regex.Matcher;

import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -866,13 +868,13 @@ public ModelsMap postProcessModels(ModelsMap objs) {
}

// if oneOf contains "null" type
if (model.oneOf != null && !model.oneOf.isEmpty() && model.oneOf.contains("nil")) {
if (hasOneOf(model) && model.oneOf.contains("nil")) {
model.isNullable = true;
model.oneOf.remove("nil");
}

// if anyOf contains "null" type
if (model.anyOf != null && !model.anyOf.isEmpty() && model.anyOf.contains("nil")) {
if (hasAnyOf(model) && model.anyOf.contains("nil")) {
model.isNullable = true;
model.anyOf.remove("nil");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import static org.openapitools.codegen.CodegenConstants.*;
import static org.openapitools.codegen.utils.EnumUtils.getEnumVars;
import static org.openapitools.codegen.utils.ModelUtils.*;
import static org.openapitools.codegen.utils.StringUtils.*;


Expand Down Expand Up @@ -1059,15 +1060,15 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
}

List<CodegenProperty> codegenProperties = null;
if (!model.oneOf.isEmpty()) { // oneOfValidationError
if (hasOneOf(model)) {
codegenProperties = model.getComposedSchemas().getOneOf();
moduleImports.add("typing", "Any");
moduleImports.add("typing", "List");
moduleImports.add(PYDANTIC, "Field");
moduleImports.add(PYDANTIC, "StrictStr");
moduleImports.add(PYDANTIC, "ValidationError");
moduleImports.add(PYDANTIC, "field_validator");
} else if (!model.anyOf.isEmpty()) { // anyOF
} else if (hasAnyOf(model)) {
codegenProperties = model.getComposedSchemas().getAnyOf();
moduleImports.add(PYDANTIC, "Field");
moduleImports.add(PYDANTIC, "StrictStr");
Expand All @@ -1083,7 +1084,7 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
}
}

if (!model.allOf.isEmpty()) { // allOf
if (hasAllOf(model)) {
for (CodegenProperty cp : model.allVars) {
if (!cp.isPrimitiveType || cp.isModel) {
if (cp.isArray || cp.isMap) { // if array or map
Expand Down Expand Up @@ -1121,9 +1122,9 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
cp.vendorExtensions.put(X_PY_TYPING, typing);

// setup x-py-name for each oneOf/anyOf schema
if (!model.oneOf.isEmpty()) { // oneOf
if (hasOneOf(model)) {
cp.vendorExtensions.put(X_PY_NAME, String.format(Locale.ROOT, "oneof_schema_%d_validator", property_count++));
} else if (!model.anyOf.isEmpty()) { // anyOf
} else if (hasAnyOf(model)) {
cp.vendorExtensions.put(X_PY_NAME, String.format(Locale.ROOT, "anyof_schema_%d_validator", property_count++));
}
}
Expand Down Expand Up @@ -1301,9 +1302,9 @@ void createImportMapOfSet(String modelName, Map<String, CodegenModel> codegenMod
}

List<CodegenProperty> codegenProperties = null;
if (cm.oneOf != null && !cm.oneOf.isEmpty()) { // oneOf
if (hasOneOf(cm)) {
codegenProperties = cm.getComposedSchemas().getOneOf();
} else if (cm.anyOf != null && !cm.anyOf.isEmpty()) { // anyOF
} else if (hasAnyOf(cm)) {
codegenProperties = cm.getComposedSchemas().getAnyOf();
} else { // typical model
codegenProperties = cm.vars;
Expand Down Expand Up @@ -1352,9 +1353,9 @@ public void updateImportsFromCodegenModel(String modelName, CodegenModel cm, Set
}

List<CodegenProperty> codegenProperties = null;
if (cm.oneOf != null && !cm.oneOf.isEmpty()) { // oneOfValidationError
if (hasOneOf(cm)) {
codegenProperties = cm.getComposedSchemas().getOneOf();
} else if (cm.anyOf != null && !cm.anyOf.isEmpty()) { // anyOF
} else if (hasAnyOf(cm)) {
codegenProperties = cm.getComposedSchemas().getAnyOf();
} else { // typical model
codegenProperties = cm.vars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.stream.Collectors;

import static org.openapitools.codegen.CodegenConstants.*;
import static org.openapitools.codegen.utils.ModelUtils.*;
import static org.openapitools.codegen.utils.StringUtils.*;

public abstract class AbstractPythonPydanticV1Codegen extends DefaultCodegen implements CodegenConfig {
Expand Down Expand Up @@ -850,15 +851,15 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
}

List<CodegenProperty> codegenProperties = null;
if (!model.oneOf.isEmpty()) { // oneOfValidationError
if (hasOneOf(model)) {
codegenProperties = model.getComposedSchemas().getOneOf();
typingImports.add("Any");
typingImports.add("List");
pydanticImports.add("Field");
pydanticImports.add("StrictStr");
pydanticImports.add("ValidationError");
pydanticImports.add("validator");
} else if (!model.anyOf.isEmpty()) { // anyOF
} else if (hasAnyOf(model)) {
codegenProperties = model.getComposedSchemas().getAnyOf();
pydanticImports.add("Field");
pydanticImports.add("StrictStr");
Expand All @@ -873,7 +874,7 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
}
}

if (!model.allOf.isEmpty()) { // allOf
if (hasAllOf(model)) {
for (CodegenProperty cp : model.allVars) {
if (!cp.isPrimitiveType || cp.isModel) {
if (cp.isArray || cp.isMap) { // if array or map
Expand Down Expand Up @@ -961,9 +962,9 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
cp.vendorExtensions.put(X_PY_TYPING, typing + " = " + fieldCustomization);

// setup x-py-name for each oneOf/anyOf schema
if (!model.oneOf.isEmpty()) { // oneOf
if (hasOneOf(model)) {
cp.vendorExtensions.put(X_PY_NAME, String.format(Locale.ROOT, "oneof_schema_%d_validator", property_count++));
} else if (!model.anyOf.isEmpty()) { // anyOf
} else if (hasAnyOf(model)) {
cp.vendorExtensions.put(X_PY_NAME, String.format(Locale.ROOT, "anyof_schema_%d_validator", property_count++));
}
}
Expand Down Expand Up @@ -1663,9 +1664,9 @@ void createImportMapOfSet(String modelName, Map<String, CodegenModel> codegenMod
}

List<CodegenProperty> codegenProperties = null;
if (cm.oneOf != null && !cm.oneOf.isEmpty()) { // oneOf
if (hasOneOf(cm)) {
codegenProperties = cm.getComposedSchemas().getOneOf();
} else if (cm.anyOf != null && !cm.anyOf.isEmpty()) { // anyOF
} else if (hasAnyOf(cm)) {
codegenProperties = cm.getComposedSchemas().getAnyOf();
} else { // typical model
codegenProperties = cm.vars;
Expand Down Expand Up @@ -1714,9 +1715,9 @@ public void updateImportsFromCodegenModel(String modelName, CodegenModel cm, Set
}

List<CodegenProperty> codegenProperties = null;
if (cm.oneOf != null && !cm.oneOf.isEmpty()) { // oneOfValidationError
if (hasOneOf(cm)) {
codegenProperties = cm.getComposedSchemas().getOneOf();
} else if (cm.anyOf != null && !cm.anyOf.isEmpty()) { // anyOF
} else if (hasAnyOf(cm)) {
codegenProperties = cm.getComposedSchemas().getAnyOf();
} else { // typical model
codegenProperties = cm.vars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.*;
import java.util.function.Function;

import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;
import static org.openapitools.codegen.utils.StringUtils.*;

public abstract class AbstractRustCodegen extends DefaultCodegen implements CodegenConfig {
Expand Down Expand Up @@ -292,7 +294,7 @@ public CodegenModel fromModel(String name, Schema model) {
} else {
mdl.arrayModelType = toModelName(mdl.arrayModelType);
}
} else if ((!mdl.anyOf.isEmpty()) || (!mdl.oneOf.isEmpty())) {
} else if ((hasAnyOf(mdl)) || (hasOneOf(mdl))) {
mdl.dataType = getSchemaType(model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.openapitools.codegen.CodegenConstants.X_CSHARP_VALUE_TYPE;
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -1688,12 +1690,12 @@ public ModelsMap postProcessModels(ModelsMap objs) {
for (ModelMap mo : objs.getModels()) {
CodegenModel cm = mo.getModel();

if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.remove("Null")) {
if (hasOneOf(cm) && cm.oneOf.remove("Null")) {
// if oneOf contains "null" type
cm.isNullable = true;
}

if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.remove("Null")) {
if (hasAnyOf(cm) && cm.anyOf.remove("Null")) {
// if anyOf contains "null" type
cm.isNullable = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.openapitools.codegen.CodegenConstants.X_CSHARP_VALUE_TYPE;
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -1081,13 +1083,13 @@ public ModelsMap postProcessModels(ModelsMap objs) {
for (ModelMap mo : objs.getModels()) {
CodegenModel cm = mo.getModel();

if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {
if (hasOneOf(cm) && cm.oneOf.contains("ModelNull")) {
// if oneOf contains "null" type
cm.isNullable = true;
cm.oneOf.remove("ModelNull");
}

if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.contains("ModelNull")) {
if (hasAnyOf(cm) && cm.anyOf.contains("ModelNull")) {
// if anyOf contains "null" type
cm.isNullable = true;
cm.anyOf.remove("ModelNull");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.EnumUtils.getEnumValues;
import static org.openapitools.codegen.utils.EnumUtils.getEnumVars;
import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;
import static org.openapitools.codegen.utils.StringUtils.camelize;

/**
Expand Down Expand Up @@ -543,7 +545,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
boolean addedFmtImport = false;

// oneOf
if (model.oneOf != null && !model.oneOf.isEmpty()) {
if (hasOneOf(model)) {
imports.add(createMapping("import", "fmt"));
addedFmtImport = true;

Expand All @@ -554,7 +556,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
}

// anyOf
if (model.anyOf != null && !model.anyOf.isEmpty()) {
if (hasAnyOf(model)) {
imports.add(createMapping("import", "fmt"));
addedFmtImport = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import static java.util.Collections.sort;
import static org.openapitools.codegen.CodegenConstants.*;
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;
import static org.openapitools.codegen.utils.StringUtils.camelize;

/**
Expand Down Expand Up @@ -1269,13 +1271,13 @@ public ModelsMap postProcessModels(ModelsMap objs) {

cm.getVendorExtensions().putIfAbsent(X_IMPLEMENTS, new ArrayList<String>());
if (isLibrary(JERSEY2) || isLibrary(JERSEY3) || isLibrary(NATIVE) || isLibrary(OKHTTP_GSON)) {
if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {
if (hasOneOf(cm) && cm.oneOf.contains("ModelNull")) {
// if oneOf contains "null" type
cm.isNullable = true;
cm.oneOf.remove("ModelNull");
}

if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.contains("ModelNull")) {
if (hasAnyOf(cm) && cm.anyOf.contains("ModelNull")) {
// if anyOf contains "null" type
cm.isNullable = true;
cm.anyOf.remove("ModelNull");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.USE_TAGS;
import static org.openapitools.codegen.utils.EnumUtils.getEnumValues;
import static org.openapitools.codegen.utils.EnumUtils.hasEnumValues;
import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;

/**
* <p>Mustache templates are located in
Expand Down Expand Up @@ -522,8 +524,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
// For allOf pattern: if parent has properties, mark child's inherited properties
// Skip this for oneOf/anyOf patterns where parent properties are merged from children
boolean parentIsOneOfOrAnyOf = parentModel != null
&& ((parentModel.oneOf != null && !parentModel.oneOf.isEmpty())
|| (parentModel.anyOf != null && !parentModel.anyOf.isEmpty()));
&& (hasOneOf(parentModel) || (hasAnyOf(parentModel)));

if (parentModel != null && parentModel.getHasVars() && !parentIsOneOfOrAnyOf) {
Set<String> parentPropNames = new HashSet<>();
Expand Down Expand Up @@ -572,8 +573,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
CodegenModel owner = allModelsMap.get(ownerName);
if (owner != null && owner.getDiscriminator() != null) {
String discriminatorPropBaseName = owner.getDiscriminator().getPropertyBaseName();
boolean isOneOfOrAnyOfPattern = (owner.oneOf != null && !owner.oneOf.isEmpty())
|| (owner.anyOf != null && !owner.anyOf.isEmpty());
boolean isOneOfOrAnyOfPattern = hasOneOf(owner) || hasAnyOf(owner);

// hasParentProperties controls whether the sealed class has properties in its constructor
// This should be false for oneOf/anyOf patterns (parent is a type union, no direct properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import static org.apache.commons.lang3.StringUtils.capitalize;
import static org.openapitools.codegen.CodegenConstants.ENUM_NAME;
import static org.openapitools.codegen.CodegenConstants.ENUM_VALUES;
import static org.openapitools.codegen.utils.ModelUtils.hasAnyOf;
import static org.openapitools.codegen.utils.ModelUtils.hasOneOf;
import static org.openapitools.codegen.utils.StringUtils.escape;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -221,11 +223,11 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> supero
enrichPropertiesWithEnumDefaultValues(cm.getParentVars());
}

if (!cm.oneOf.isEmpty()) {
if (hasOneOf(cm)) {
// Add a boolean if it is a `oneOf`, because Mustache does not let us check if a list is non-empty
cm.getVendorExtensions().put("x-ocaml-isOneOf", true);
}
if (!cm.anyOf.isEmpty()) {
if (hasAnyOf(cm)) {
// Add a boolean if it is a `anyOf`, because Mustache does not let us check if a list is non-empty
cm.getVendorExtensions().put("x-ocaml-isAnyOf", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

import static org.openapitools.codegen.utils.ModelUtils.hasAllOf;

/**
* <p>Mustache templates are located in {@code src/main/resources/plantuml/}.
*/
Expand Down Expand Up @@ -79,7 +82,7 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
.collect(Collectors.toList());

List<CodegenModel> subtypeCodegenModelList = codegenModelList.stream()
.filter(codegenModel -> !codegenModel.allOf.isEmpty())
.filter(ModelUtils::hasAllOf)
.collect(Collectors.toList());


Expand Down
Loading
Loading