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 @@ -456,4 +456,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String USE_DEFAULT_VALUES_FOR_REQUIRED_VARS = "useDefaultValuesForRequiredVars";

public static final String DEFAULT_TO_EMPTY_CONTAINER = "defaultToEmptyContainer";

public static final String X_INTERNAL = "x-internal";
public static final String X_PARENT = "x-parent";
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.openapitools.codegen.CodegenConstants.DEFAULT_TO_EMPTY_CONTAINER;
import static org.openapitools.codegen.CodegenConstants.UNSUPPORTED_V310_SPEC_MSG;
import static org.openapitools.codegen.CodegenConstants.*;
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.*;
Expand Down Expand Up @@ -5197,7 +5196,7 @@ public CodegenCallback fromCallback(String name, Callback callback, List<Server>
String method = p.getKey();
Operation op = p.getValue();

if (op.getExtensions() != null && Boolean.TRUE.equals(op.getExtensions().get("x-internal"))) {
if (op.getExtensions() != null && Boolean.TRUE.equals(op.getExtensions().get(X_INTERNAL))) {
// skip operation if x-internal sets to true
LOGGER.info("Operation ({} {} - {}) not generated since x-internal is set to true",
method, expression, op.getOperationId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.stream.Collectors;

import static org.apache.commons.lang3.StringUtils.removeStart;
import static org.openapitools.codegen.CodegenConstants.X_INTERNAL;
import static org.openapitools.codegen.utils.OnceLogger.once;

@SuppressWarnings("rawtypes")
Expand Down Expand Up @@ -486,7 +487,7 @@ void generateModels(List<File> files, List<ModelMap> allModels, List<String> unu

Schema schema = ModelUtils.getSchemas(this.openAPI).get(name);

if (schema.getExtensions() != null && Boolean.TRUE.equals(schema.getExtensions().get("x-internal"))) {
if (schema.getExtensions() != null && Boolean.TRUE.equals(schema.getExtensions().get(X_INTERNAL))) {
LOGGER.info("Model {} not generated since x-internal is set to true", name);
continue;
} else if (ModelUtils.isFreeFormObject(schema, openAPI)) { // check to see if it's a free-form object
Expand Down Expand Up @@ -1564,7 +1565,7 @@ private void processOperation(String resourcePath, String httpMethod, Operation
final List<SecurityRequirement> globalSecurities = openAPI.getSecurity();
for (Tag tag : tags) {
try {
if (operation.getExtensions() != null && Boolean.TRUE.equals(operation.getExtensions().get("x-internal"))) {
if (operation.getExtensions() != null && Boolean.TRUE.equals(operation.getExtensions().get(X_INTERNAL))) {
// skip operation if x-internal sets to true
LOGGER.info("Operation ({} {} - {}) not generated since x-internal is set to true",
httpMethod, resourcePath, operation.getOperationId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
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.utils.ModelUtils.simplifyOneOfAnyOfWithOnlyOneNonNullSubSchema;
import static org.openapitools.codegen.utils.StringUtils.getUniqueString;

Expand Down Expand Up @@ -127,7 +129,6 @@ public class OpenAPINormalizer {

// when set to true, remove x-internal: true from models, operations
final String REMOVE_X_INTERNAL = "REMOVE_X_INTERNAL";
final String X_INTERNAL = "x-internal";
boolean removeXInternal;

// when set (e.g. operationId:getPetById|addPet), filter out (or remove) everything else
Expand Down Expand Up @@ -431,17 +432,17 @@ protected void normalizePaths() {
for (Operation operation : operations) {
if (operationIdFilters.size() > 0) {
if (operationIdFilters.contains(operation.getOperationId())) {
operation.addExtension("x-internal", false);
operation.addExtension(X_INTERNAL, false);
} else {
LOGGER.info("operation `{}` marked as internal only (x-internal: true) by the operationId FILTER", operation.getOperationId());
operation.addExtension("x-internal", true);
operation.addExtension(X_INTERNAL, true);
}
} else if (!tagFilters.isEmpty()) {
if (operation.getTags().stream().anyMatch(tagFilters::contains)) {
operation.addExtension("x-internal", false);
operation.addExtension(X_INTERNAL, false);
} else {
LOGGER.info("operation `{}` marked as internal only (x-internal: true) by the tag FILTER", operation.getOperationId());
operation.addExtension("x-internal", true);
operation.addExtension(X_INTERNAL, true);
}
}

Expand Down Expand Up @@ -1083,10 +1084,10 @@ protected void processUseAllOfRefAsParent(Schema schema) {
refSchema.setExtensions(new HashMap<>());
}

if (refSchema.getExtensions().containsKey("x-parent")) {
if (refSchema.getExtensions().containsKey(X_PARENT)) {
// doing nothing as x-parent already exists
} else {
refSchema.getExtensions().put("x-parent", true);
refSchema.getExtensions().put(X_PARENT, true);
}

LOGGER.debug("processUseAllOfRefAsParent added `x-parent: true` to {}", refSchema);
Expand All @@ -1108,7 +1109,7 @@ protected void processRemoveXInternalFromOperation(Operation operation) {
return;
}

if (Boolean.parseBoolean(String.valueOf(operation.getExtensions().get("x-internal")))) {
if (Boolean.parseBoolean(String.valueOf(operation.getExtensions().get(X_INTERNAL)))) {
operation.getExtensions().remove(X_INTERNAL);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public enum VendorExtension {
X_OPERATION_EXTRA_ANNOTATION("x-operation-extra-annotation", ExtensionLevel.OPERATION, "List of custom annotations to be added to operation", null),
X_VERSION_PARAM("x-version-param", ExtensionLevel.OPERATION_PARAMETER, "Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false", null),
X_PATTERN_MESSAGE("x-pattern-message", Arrays.asList(ExtensionLevel.FIELD, ExtensionLevel.OPERATION_PARAMETER), "Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable", null),
X_ZERO_BASED_ENUM("x-zero-based-enum", ExtensionLevel.MODEL, "When used on an enum, the index will not be generated and the default numbering will be used, zero-based", "false"),
;
X_ZERO_BASED_ENUM("x-zero-based-enum", ExtensionLevel.MODEL, "When used on an enum, the index will not be generated and the default numbering will be used, zero-based", "false");

private final String name;
private final List<ExtensionLevel> levels;
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_PARENT;
import static org.openapitools.codegen.utils.OnceLogger.once;

public class ModelUtils {
Expand Down Expand Up @@ -1716,7 +1717,7 @@ public static boolean isExtensionParent(Schema schema) {
return false;
}

Object xParent = schema.getExtensions().get("x-parent");
Object xParent = schema.getExtensions().get(X_PARENT);
if (xParent == null) {
return false;
} else if (xParent instanceof Boolean) {
Expand Down
Loading
Loading