Skip to content

Commit bd275fd

Browse files
committed
Undo changes in decompose Schema
1 parent 5f5f679 commit bd275fd

2 files changed

Lines changed: 10 additions & 124 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public Schema normalizeSchema(Schema schema, Set<Schema> visitedSchemas) {
747747
if (ModelUtils.isNullTypeSchema(openAPI, schema)) {
748748
return schema;
749749
}
750-
schema = decomposeSchema(schema);
750+
751751
markSchemaAsVisited(schema, visitedSchemas);
752752

753753
processNormalizeOtherThanObjectWithProperties(schema);
@@ -1083,15 +1083,15 @@ protected Schema normalizeOneOf(Schema schema, Set<Schema> visitedSchemas) {
10831083
// normalize it as it's no longer an oneOf
10841084
schema = normalizeSchema(schema, visitedSchemas);
10851085
}
1086-
schema = decomposeSchema(schema);
1086+
10871087
return schema;
10881088
}
10891089

10901090
protected Schema normalizeAnyOf(Schema schema, Set<Schema> visitedSchemas) {
10911091
//transform anyOf into enums if needed
10921092
schema = processSimplifyAnyOfEnum(schema);
10931093
if (schema.getAnyOf() == null) {
1094-
return decomposeSchema(schema);
1094+
return schema;
10951095
}
10961096

10971097
for (int i = 0; i < schema.getAnyOf().size(); i++) {
@@ -1634,19 +1634,6 @@ protected Schema processReplaceOneOfByMapping(Schema schema) {
16341634
return schema;
16351635
}
16361636

1637-
/**
1638-
* Replace a ComposeSchema into a Simple Schema if no OneOf/AnyOf/AllOf.
1639-
*
1640-
* This allows side effects with ModelUtils.isComposedSchema() that returns true for a ComposedSchema.
1641-
* For example the InlineModelResolver does not inline properties of a ComposedSchema (a bug to be fixed in another PR)
1642-
*/
1643-
private Schema decomposeSchema(Schema schema) {
1644-
if (schema instanceof ComposedSchema && schema.getOneOf() == null && schema.getAnyOf() == null && schema.getAllOf() == null) {
1645-
schema = ModelUtils.shallowCopy(schema, new Schema());
1646-
}
1647-
return schema;
1648-
}
1649-
16501637
private boolean isInlineSchema(Schema schema) {
16511638
if (openAPI.getComponents()!=null && openAPI.getComponents().getSchemas()!=null) {
16521639
int identity = System.identityHashCode(schema);

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 7 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717

1818
package org.openapitools.codegen.utils;
1919

20-
import com.fasterxml.jackson.core.JsonProcessingException;
2120
import com.fasterxml.jackson.databind.JsonNode;
2221
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import io.swagger.util.Yaml;
2422
import io.swagger.v3.core.util.AnnotationsUtils;
2523
import io.swagger.v3.oas.models.OpenAPI;
2624
import io.swagger.v3.oas.models.Operation;
2725
import io.swagger.v3.oas.models.PathItem;
28-
import io.swagger.v3.oas.models.SpecVersion;
2926
import io.swagger.v3.oas.models.callbacks.Callback;
3027
import io.swagger.v3.oas.models.headers.Header;
3128
import io.swagger.v3.oas.models.media.*;
@@ -565,7 +562,7 @@ public static boolean isMapSchema(Schema schema) {
565562

566563
// additionalProperties explicitly set to false
567564
if ((schema.getAdditionalProperties() instanceof Boolean && Boolean.FALSE.equals(schema.getAdditionalProperties())) ||
568-
(schema.getAdditionalProperties() instanceof Schema && Boolean.FALSE.equals(((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue()))
565+
(schema.getAdditionalProperties() instanceof Schema && Boolean.FALSE.equals(((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue()))
569566
) {
570567
return false;
571568
}
@@ -815,12 +812,12 @@ public static boolean isModelWithPropertiesOnly(Schema schema) {
815812
(null != schema.getProperties() && !schema.getProperties().isEmpty()) &&
816813
// no additionalProperties is set
817814
(schema.getAdditionalProperties() == null ||
818-
// additionalProperties is boolean and set to false
819-
(schema.getAdditionalProperties() instanceof Boolean && !(Boolean) schema.getAdditionalProperties()) ||
820-
// additionalProperties is a schema with its boolean value set to false
821-
(schema.getAdditionalProperties() instanceof Schema &&
822-
((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue() != null &&
823-
!((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue())
815+
// additionalProperties is boolean and set to false
816+
(schema.getAdditionalProperties() instanceof Boolean && !(Boolean) schema.getAdditionalProperties()) ||
817+
// additionalProperties is a schema with its boolean value set to false
818+
(schema.getAdditionalProperties() instanceof Schema &&
819+
((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue() != null &&
820+
!((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue())
824821
);
825822
}
826823

@@ -2271,88 +2268,6 @@ public static boolean isParent(Schema schema) {
22712268
return false;
22722269
}
22732270

2274-
/**
2275-
* copy all the fields from the origin schema to the destination schema.
2276-
* @param schema original schema
2277-
* @param dest the destination schema
2278-
* @return dest
2279-
*/
2280-
2281-
public static Schema shallowCopy(Schema schema, Schema dest) {
2282-
// cloneSchema does not work because it does conversions for some attributes (enums, default...)
2283-
// the intermediate JSON can convert between integer and BigInteger for example.
2284-
// so copy all the fields individually
2285-
dest.setDefault(schema.getDefault());
2286-
dest.setName(schema.getName());
2287-
dest.setTitle(schema.getTitle());
2288-
dest.setMultipleOf(schema.getMultipleOf());
2289-
dest.setMaximum(schema.getMaximum());
2290-
dest.setExclusiveMaximum(schema.getExclusiveMaximum());
2291-
dest.setMinimum(schema.getMinimum());
2292-
dest.setExclusiveMinimum(schema.getExclusiveMinimum());
2293-
dest.setMaxLength(schema.getMaxLength());
2294-
dest.setPattern(schema.getPattern());
2295-
dest.setMaxItems(schema.getMaxItems());
2296-
dest.setMinItems(schema.getMinItems());
2297-
dest.setUnevaluatedItems(schema.getUnevaluatedItems());
2298-
dest.setMaxProperties(schema.getMaxProperties());
2299-
dest.setMinProperties(schema.getMinProperties());
2300-
dest.setRequired(schema.getRequired());
2301-
dest.setType(schema.getType());
2302-
dest.setNot(schema.getNot());
2303-
dest.setProperties(schema.getProperties());
2304-
dest.setDescription(schema.getDescription());
2305-
dest.setFormat(schema.getFormat());
2306-
dest.set$ref(schema.get$ref());
2307-
dest.setNullable(schema.getNullable());
2308-
dest.setReadOnly(schema.getReadOnly());
2309-
dest.setWriteOnly(schema.getWriteOnly());
2310-
dest.setExample(schema.getExample());
2311-
dest.setExternalDocs(schema.getExternalDocs());
2312-
dest.setDeprecated(schema.getDeprecated());
2313-
dest.setXml(schema.getXml());
2314-
dest.setExtensions(schema.getExtensions());
2315-
dest.setEnum(schema.getEnum());
2316-
dest.setDiscriminator(schema.getDiscriminator());
2317-
dest.setExampleSetFlag(schema.getExampleSetFlag());
2318-
dest.setPrefixItems(schema.getPrefixItems());
2319-
dest.setAllOf(schema.getAllOf());
2320-
dest.setAnyOf(schema.getAnyOf());
2321-
dest.setOneOf(schema.getOneOf());
2322-
dest.setItems(schema.getItems());
2323-
dest.setConst(schema.getConst());
2324-
dest.setSpecVersion(schema.getSpecVersion());
2325-
dest.setPatternProperties(schema.getPatternProperties());
2326-
dest.setExclusiveMaximumValue(schema.getExclusiveMaximumValue());
2327-
dest.setExclusiveMinimumValue(schema.getExclusiveMinimumValue());
2328-
dest.setContains(schema.getContains());
2329-
dest.set$id(schema.get$id());
2330-
dest.set$schema(schema.get$schema());
2331-
dest.set$anchor(schema.get$anchor());
2332-
dest.set$vocabulary(schema.get$vocabulary());
2333-
dest.set$dynamicAnchor(schema.get$dynamicAnchor());
2334-
dest.set$dynamicRef(schema.get$dynamicRef());
2335-
dest.setContentEncoding(schema.getContentEncoding());
2336-
dest.setContentMediaType(schema.getContentMediaType());
2337-
dest.setPropertyNames(schema.getPropertyNames());
2338-
dest.setUnevaluatedProperties(schema.getUnevaluatedProperties());
2339-
dest.setMaxContains(schema.getMaxContains());
2340-
dest.setMinContains(schema.getMinContains());
2341-
dest.setAdditionalItems(schema.getAdditionalItems());
2342-
dest.setUnevaluatedItems(schema.getUnevaluatedItems());
2343-
dest.setIf(schema.getIf());
2344-
dest.setElse(schema.getElse());
2345-
dest.setThen(schema.getThen());
2346-
dest.setDependentSchemas(schema.getDependentSchemas());
2347-
dest.setDependentRequired(schema.getDependentRequired());
2348-
dest.set$comment(schema.get$comment());
2349-
dest.setExamples(schema.getExamples());
2350-
dest.setBooleanSchemaValue(schema.getBooleanSchemaValue());
2351-
dest.setJsonSchema(schema.getJsonSchema());
2352-
dest.setJsonSchemaImpl(schema.getJsonSchemaImpl());
2353-
return dest;
2354-
}
2355-
23562271
public static Schema cloneSchema(Schema schema, boolean openapi31) {
23572272
if (openapi31) {
23582273
return AnnotationsUtils.clone(schema, openapi31);
@@ -2730,20 +2645,4 @@ public LinkedHashSet<String> build() {
27302645
}
27312646
}
27322647
}
2733-
2734-
2735-
/*
2736-
* Simplest dump of an openApi contract on the console.
2737-
*
2738-
* Only use for debugging.
2739-
*/
2740-
public static void dumpAsYaml(OpenAPI openAPI) {
2741-
ObjectMapper mapper = Yaml.mapper();
2742-
try {
2743-
String yaml = mapper.writeValueAsString(openAPI);
2744-
System.out.println(yaml);
2745-
} catch (JsonProcessingException e) {
2746-
throw new RuntimeException(e);
2747-
}
2748-
}
27492648
}

0 commit comments

Comments
 (0)