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 @@ -483,4 +483,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String X_MODIFIERS = "x-modifiers";
public static final String X_MODIFIER_PREFIX = "x-modifier-";
public static final String X_MODEL_IS_MUTABLE = "x-model-is-mutable";
public static final String X_IMPLEMENTS = "x-implements";
public static final String X_IS_ONE_OF_INTERFACE = "x-is-one-of-interface";
public static final String X_DISCRIMINATOR_VALUE = "x-discriminator-value";
public static final String X_ONE_OF_NAME = "x-one-of-name";
public static final String X_NULLABLE = "x-nullable";
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
for (ModelMap mo : modelsAttrs.getModels()) {
CodegenModel cm = mo.getModel();
if (cm.oneOf.size() > 0) {
cm.vendorExtensions.put("x-is-one-of-interface", true);
cm.vendorExtensions.put(X_IS_ONE_OF_INTERFACE, true);
for (String one : cm.oneOf) {
if (!additionalDataMap.containsKey(one)) {
additionalDataMap.put(one, new OneOfImplementorAdditionalData(one));
Expand Down Expand Up @@ -2348,8 +2348,8 @@ public String toAnyOfName(List<String> names, Schema composedSchema) {
@SuppressWarnings("static-method")
public String toOneOfName(List<String> names, Schema composedSchema) {
Map<String, Object> exts = composedSchema.getExtensions();
if (exts != null && exts.containsKey("x-one-of-name")) {
return (String) exts.get("x-one-of-name");
if (exts != null && exts.containsKey(X_ONE_OF_NAME)) {
return (String) exts.get(X_ONE_OF_NAME);
}
return "oneOf<" + String.join(",", names) + ">";
}
Expand Down Expand Up @@ -3548,8 +3548,8 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
once(LOGGER).error("Failed to lookup the schema '{}' when processing oneOf/anyOf. Please check to ensure it's defined properly.", modelName);
} else {
Map<String, Object> vendorExtensions = cs.getExtensions();
if (vendorExtensions != null && !vendorExtensions.isEmpty() && vendorExtensions.containsKey("x-discriminator-value")) {
String xDiscriminatorValue = (String) vendorExtensions.get("x-discriminator-value");
if (vendorExtensions != null && !vendorExtensions.isEmpty() && vendorExtensions.containsKey(X_DISCRIMINATOR_VALUE)) {
String xDiscriminatorValue = (String) vendorExtensions.get(X_DISCRIMINATOR_VALUE);
mm = new MappedModel(xDiscriminatorValue, toModelName(modelName), true);
descendentSchemas.add(mm);
}
Expand Down Expand Up @@ -3605,7 +3605,7 @@ protected List<MappedModel> getAllOfDescendants(String thisSchemaName) {
Map<String, Object> vendorExtensions = cs.getExtensions();
String mappingName =
Optional.ofNullable(vendorExtensions)
.map(ve -> ve.get("x-discriminator-value"))
.map(ve -> ve.get(X_DISCRIMINATOR_VALUE))
.map(discriminatorValue -> (String) discriminatorValue)
.orElse(currentSchemaName);
MappedModel mm = new MappedModel(mappingName, toModelName(currentSchemaName), !mappingName.equals(currentSchemaName));
Expand Down Expand Up @@ -4098,8 +4098,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
if (referencedSchema.getNullable() != null) {
property.isNullable = referencedSchema.getNullable();
} else if (referencedSchema.getExtensions() != null &&
referencedSchema.getExtensions().containsKey("x-nullable")) {
property.isNullable = (Boolean) referencedSchema.getExtensions().get("x-nullable");
referencedSchema.getExtensions().containsKey(X_NULLABLE)) {
property.isNullable = (Boolean) referencedSchema.getExtensions().get(X_NULLABLE);
}

final XML referencedSchemaXml = referencedSchema.getXml();
Expand Down Expand Up @@ -4201,8 +4201,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
// evaluate common attributes if defined in the top level
if (p.getNullable() != null) {
property.isNullable = p.getNullable();
} else if (p.getExtensions() != null && p.getExtensions().containsKey("x-nullable")) {
property.isNullable = (Boolean) p.getExtensions().get("x-nullable");
} else if (p.getExtensions() != null && p.getExtensions().containsKey(X_NULLABLE)) {
property.isNullable = (Boolean) p.getExtensions().get(X_NULLABLE);
}

if (p.getReadOnly() != null) {
Expand Down Expand Up @@ -8047,8 +8047,8 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
// evaluate common attributes such as description if defined in the top level
if (original.getNullable() != null) {
codegenParameter.isNullable = original.getNullable();
} else if (original.getExtensions() != null && original.getExtensions().containsKey("x-nullable")) {
codegenParameter.isNullable = (Boolean) original.getExtensions().get("x-nullable");
} else if (original.getExtensions() != null && original.getExtensions().containsKey(X_NULLABLE)) {
codegenParameter.isNullable = (Boolean) original.getExtensions().get(X_NULLABLE);
}

if (original.getExtensions() != null) {
Expand Down Expand Up @@ -8464,7 +8464,7 @@ public void setRemoveEnumValuePrefix(final boolean removeEnumValuePrefix) {
*/
public void addOneOfNameExtension(Schema schema, String name) {
if (schema.getOneOf() != null && schema.getOneOf().size() > 0) {
schema.addExtension("x-one-of-name", name);
schema.addExtension(X_ONE_OF_NAME, name);
}
}

Expand Down Expand Up @@ -8498,7 +8498,7 @@ public void addOneOfInterfaceModel(Schema cs, String type) {
}
cm.name = type;
cm.classname = type;
cm.vendorExtensions.put("x-is-one-of-interface", true);
cm.vendorExtensions.put(X_IS_ONE_OF_INTERFACE, true);
cm.interfaceModels = new ArrayList<>();

addOneOfInterfaces.add(cm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.openapitools.codegen.CodegenConstants.X_INTERNAL;
import static org.openapitools.codegen.CodegenConstants.X_PARENT;
import static org.openapitools.codegen.CodegenConstants.*;
import static org.openapitools.codegen.utils.ModelUtils.simplifyOneOfAnyOfWithOnlyOneNonNullSubSchema;
import static org.openapitools.codegen.utils.StringUtils.getUniqueString;

Expand Down Expand Up @@ -1570,7 +1569,7 @@ protected Schema processSetPrimitiveTypesToNullable(Schema schema) {
}

protected Schema setNullable(Schema schema) {
if (schema.getNullable() != null || (schema.getExtensions() != null && schema.getExtensions().containsKey("x-nullable"))) {
if (schema.getNullable() != null || (schema.getExtensions() != null && schema.getExtensions().containsKey(X_NULLABLE))) {
// already set, don't overwrite
return schema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;
import static org.openapitools.codegen.utils.CamelizeOption.*;
import static org.openapitools.codegen.utils.ModelUtils.getSchemaItems;
import static org.openapitools.codegen.utils.OnceLogger.once;
Expand Down Expand Up @@ -1997,8 +1998,8 @@ public ModelsMap postProcessModels(ModelsMap objs) {
for (ModelMap mo : objs.getModels()) {
CodegenModel cm = mo.getModel();
if (this.serializableModel) {
cm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Serializable");
cm.getVendorExtensions().putIfAbsent(X_IMPLEMENTS, new ArrayList<String>());
((ArrayList<String>) cm.getVendorExtensions().get(X_IMPLEMENTS)).add("Serializable");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static java.util.Collections.sort;
import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.StringUtils.camelize;

Expand Down Expand Up @@ -1173,7 +1174,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
for (ModelMap mo : models) {
CodegenModel cm = mo.getModel();

cm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
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 oneOf contains "null" type
Expand All @@ -1188,7 +1189,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
}
}
if (this.parcelableModel && !cm.isEnum) {
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Parcelable");
((ArrayList<String>) cm.getVendorExtensions().get(X_IMPLEMENTS)).add("Parcelable");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.openapitools.codegen.CodegenConstants.X_ONE_OF_NAME;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -1406,8 +1407,8 @@ public String toOneOfName(List<String> names, Schema composedSchema) {
if (composedSchema != null) {
exts = composedSchema.getExtensions();
}
if (exts != null && exts.containsKey("x-one-of-name")) {
return (String) exts.get("x-one-of-name");
if (exts != null && exts.containsKey(X_ONE_OF_NAME)) {
return (String) exts.get(X_ONE_OF_NAME);
}

List<Schema> schemas = ModelUtils.getInterfaces(composedSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.openapitools.codegen.CodegenConstants.X_ONE_OF_NAME;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -1386,8 +1387,8 @@ public String toOneOfName(List<String> names, Schema composedSchema) {
if (composedSchema != null) {
exts = composedSchema.getExtensions();
}
if (exts != null && exts.containsKey("x-one-of-name")) {
return (String) exts.get("x-one-of-name");
if (exts != null && exts.containsKey(X_ONE_OF_NAME)) {
return (String) exts.get(X_ONE_OF_NAME);
}

List<Schema> schemas = ModelUtils.getInterfaces(composedSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;

public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenConfig {
private final Logger LOGGER = LoggerFactory.getLogger(ScalaHttp4sServerCodegen.class);
protected String artifactId = "http4s-server";
Expand Down Expand Up @@ -374,7 +376,7 @@ else if (cModel.isEnum) {
}
//
try {
List<String> exts = (List<String>) cModel.getVendorExtensions().get("x-implements");
List<String> exts = (List<String>) cModel.getVendorExtensions().get(X_IMPLEMENTS);
if (exts != null) {
cModel.getVendorExtensions().put("x-extends", exts.subList(0, 1));
cModel.getVendorExtensions().put("x-extendsWith", exts.subList(1, exts.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.Map.Entry;
import java.util.stream.Collectors;

import static org.openapitools.codegen.CodegenConstants.X_NULLABLE;
import static org.openapitools.codegen.CodegenConstants.X_PARENT;
import static org.openapitools.codegen.utils.OnceLogger.once;

Expand Down Expand Up @@ -1757,8 +1758,8 @@ public static boolean isNullable(Schema schema) {
return true;
}

if (schema.getExtensions() != null && schema.getExtensions().get("x-nullable") != null) {
return Boolean.parseBoolean(schema.getExtensions().get("x-nullable").toString());
if (schema.getExtensions() != null && schema.getExtensions().get(X_NULLABLE) != null) {
return Boolean.parseBoolean(schema.getExtensions().get(X_NULLABLE).toString());
}
// In OAS 3.1, the recommended way to define a nullable property or object is to use oneOf.
if (isComposedSchema(schema)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import java.util.*;

import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;

/**
* This class holds data to add to `oneOf` members. Let's consider this example:
* <p>
Expand Down Expand Up @@ -101,11 +103,11 @@ public void addFromInterfaceModel(CodegenModel cm, List<Map<String, String>> mod
*/
@SuppressWarnings("unchecked")
public void addToImplementor(CodegenConfig cc, CodegenModel implcm, List<Map<String, String>> implImports, boolean addInterfaceImports) {
implcm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
implcm.getVendorExtensions().putIfAbsent(X_IMPLEMENTS, new ArrayList<String>());

// Add implemented interfaces
for (String intf : additionalInterfaces) {
List<String> impl = (List<String>) implcm.getVendorExtensions().get("x-implements");
List<String> impl = (List<String>) implcm.getVendorExtensions().get(X_IMPLEMENTS);
impl.add(intf);
if (addInterfaceImports) {
// Add imports for interfaces
Expand Down
Loading