Skip to content

Commit 066a840

Browse files
authored
Revert "fix ref to allOf wrapper, add tests (#19986)" (#20446)
This reverts commit 48e8375.
1 parent 121c82f commit 066a840

File tree

6 files changed

+2
-117
lines changed

6 files changed

+2
-117
lines changed

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,29 +3875,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
38753875
}
38763876

38773877
Schema original = null;
3878-
// process the dereference schema if it's a ref to allOf with a single item
3879-
// and certain field(s) (e.g. description, readyOnly, etc) is set
3880-
if (p.get$ref() != null) {
3881-
Schema derefSchema = ModelUtils.getReferencedSchema(openAPI, p);
3882-
if (ModelUtils.isAllOfWithSingleItem(derefSchema) && (
3883-
derefSchema.getReadOnly() != null ||
3884-
derefSchema.getWriteOnly() != null ||
3885-
derefSchema.getDeprecated() != null ||
3886-
derefSchema.getDescription() != null ||
3887-
derefSchema.getMaxLength() != null ||
3888-
derefSchema.getMinLength() != null ||
3889-
derefSchema.getMinimum() != null ||
3890-
derefSchema.getMaximum() != null ||
3891-
derefSchema.getMaximum() != null ||
3892-
derefSchema.getMinItems() != null ||
3893-
derefSchema.getTitle() != null
3894-
)) {
3895-
p = ModelUtils.getReferencedSchema(openAPI, p);
3896-
}
3897-
}
3898-
38993878
// check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level
3900-
if (ModelUtils.isAllOfWithSingleItem(p)) {
3879+
if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1) {
39013880
if (p.getAllOf().get(0) instanceof Schema) {
39023881
original = p;
39033882
p = (Schema) p.getAllOf().get(0);

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,18 +2031,6 @@ public static boolean isAllOf(Schema schema) {
20312031
return false;
20322032
}
20332033

2034-
2035-
/**
2036-
* Returns true if the schema contains allOf with a single item but
2037-
* no properties/oneOf/anyOf defined
2038-
*
2039-
* @param schema the schema
2040-
* @return true if the schema contains allOf but no properties/oneOf/anyOf defined.
2041-
*/
2042-
public static boolean isAllOfWithSingleItem(Schema schema) {
2043-
return (isAllOf(schema) && schema.getAllOf().size() == 1);
2044-
}
2045-
20462034
/**
20472035
* Returns true if the schema contains allOf and may or may not have
20482036
* properties/oneOf/anyOf defined.

modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,10 +2617,6 @@ components:
26172617
minItems: 1
26182618
items:
26192619
$ref: '#/components/schemas/Scalar'
2620-
AllOfRefToString:
2621-
allOf:
2622-
- $ref: '#/components/schemas/OuterString'
2623-
description: testing allOf with a ref to string
26242620
NewPet:
26252621
type: object
26262622
required:
@@ -2631,12 +2627,6 @@ components:
26312627
type: integer
26322628
format: int64
26332629
x-is-unique: true
2634-
category_ref_to_inline_allof_string:
2635-
$ref: '#/components/schemas/AllOfRefToString'
2636-
category_inline_allof_string:
2637-
allOf:
2638-
- $ref: '#/components/schemas/OuterString'
2639-
description: testing allOf with a ref to string
26402630
category_inline_allof:
26412631
allOf:
26422632
- type: object

samples/client/petstore/java/okhttp-gson/api/openapi.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,22 +2697,12 @@ components:
26972697
$ref: '#/components/schemas/Scalar'
26982698
minItems: 1
26992699
type: array
2700-
AllOfRefToString:
2701-
allOf:
2702-
- $ref: '#/components/schemas/OuterString'
2703-
description: testing allOf with a ref to string
27042700
NewPet:
27052701
properties:
27062702
id:
27072703
format: int64
27082704
type: integer
27092705
x-is-unique: true
2710-
category_ref_to_inline_allof_string:
2711-
$ref: '#/components/schemas/AllOfRefToString'
2712-
category_inline_allof_string:
2713-
allOf:
2714-
- $ref: '#/components/schemas/OuterString'
2715-
description: testing allOf with a ref to string
27162706
category_inline_allof:
27172707
$ref: '#/components/schemas/NewPet_category_inline_allof'
27182708
category_allOf_ref:

samples/client/petstore/java/okhttp-gson/docs/NewPet.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
| Name | Type | Description | Notes |
99
|------------ | ------------- | ------------- | -------------|
1010
|**id** | **Long** | | [optional] |
11-
|**categoryRefToInlineAllofString** | **String** | testing allOf with a ref to string | [optional] |
12-
|**categoryInlineAllofString** | **String** | testing allOf with a ref to string | [optional] |
1311
|**categoryInlineAllof** | [**NewPetCategoryInlineAllof**](NewPetCategoryInlineAllof.md) | | [optional] |
1412
|**categoryAllOfRef** | [**Category**](Category.md) | | [optional] |
1513
|**categoryAllOfRefDescription** | [**Category**](Category.md) | Adding description to property using allOf | [optional] |

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NewPet.java

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ public class NewPet {
6060
@javax.annotation.Nullable
6161
private Long id;
6262

63-
public static final String SERIALIZED_NAME_CATEGORY_REF_TO_INLINE_ALLOF_STRING = "category_ref_to_inline_allof_string";
64-
@SerializedName(SERIALIZED_NAME_CATEGORY_REF_TO_INLINE_ALLOF_STRING)
65-
@javax.annotation.Nullable
66-
private String categoryRefToInlineAllofString;
67-
68-
public static final String SERIALIZED_NAME_CATEGORY_INLINE_ALLOF_STRING = "category_inline_allof_string";
69-
@SerializedName(SERIALIZED_NAME_CATEGORY_INLINE_ALLOF_STRING)
70-
@javax.annotation.Nullable
71-
private String categoryInlineAllofString;
72-
7363
public static final String SERIALIZED_NAME_CATEGORY_INLINE_ALLOF = "category_inline_allof";
7464
@SerializedName(SERIALIZED_NAME_CATEGORY_INLINE_ALLOF)
7565
@javax.annotation.Nullable
@@ -193,44 +183,6 @@ public void setId(@javax.annotation.Nullable Long id) {
193183
}
194184

195185

196-
public NewPet categoryRefToInlineAllofString(@javax.annotation.Nullable String categoryRefToInlineAllofString) {
197-
this.categoryRefToInlineAllofString = categoryRefToInlineAllofString;
198-
return this;
199-
}
200-
201-
/**
202-
* testing allOf with a ref to string
203-
* @return categoryRefToInlineAllofString
204-
*/
205-
@javax.annotation.Nullable
206-
public String getCategoryRefToInlineAllofString() {
207-
return categoryRefToInlineAllofString;
208-
}
209-
210-
public void setCategoryRefToInlineAllofString(@javax.annotation.Nullable String categoryRefToInlineAllofString) {
211-
this.categoryRefToInlineAllofString = categoryRefToInlineAllofString;
212-
}
213-
214-
215-
public NewPet categoryInlineAllofString(@javax.annotation.Nullable String categoryInlineAllofString) {
216-
this.categoryInlineAllofString = categoryInlineAllofString;
217-
return this;
218-
}
219-
220-
/**
221-
* testing allOf with a ref to string
222-
* @return categoryInlineAllofString
223-
*/
224-
@javax.annotation.Nullable
225-
public String getCategoryInlineAllofString() {
226-
return categoryInlineAllofString;
227-
}
228-
229-
public void setCategoryInlineAllofString(@javax.annotation.Nullable String categoryInlineAllofString) {
230-
this.categoryInlineAllofString = categoryInlineAllofString;
231-
}
232-
233-
234186
public NewPet categoryInlineAllof(@javax.annotation.Nullable NewPetCategoryInlineAllof categoryInlineAllof) {
235187
this.categoryInlineAllof = categoryInlineAllof;
236188
return this;
@@ -446,8 +398,6 @@ public boolean equals(Object o) {
446398
}
447399
NewPet newPet = (NewPet) o;
448400
return Objects.equals(this.id, newPet.id) &&
449-
Objects.equals(this.categoryRefToInlineAllofString, newPet.categoryRefToInlineAllofString) &&
450-
Objects.equals(this.categoryInlineAllofString, newPet.categoryInlineAllofString) &&
451401
Objects.equals(this.categoryInlineAllof, newPet.categoryInlineAllof) &&
452402
Objects.equals(this.categoryAllOfRef, newPet.categoryAllOfRef) &&
453403
Objects.equals(this.categoryAllOfRefDescription, newPet.categoryAllOfRefDescription) &&
@@ -461,16 +411,14 @@ public boolean equals(Object o) {
461411

462412
@Override
463413
public int hashCode() {
464-
return Objects.hash(id, categoryRefToInlineAllofString, categoryInlineAllofString, categoryInlineAllof, categoryAllOfRef, categoryAllOfRefDescription, categoryAllOfRefDescriptionReadonly, name, photoUrls, tags, status, additionalProperties);
414+
return Objects.hash(id, categoryInlineAllof, categoryAllOfRef, categoryAllOfRefDescription, categoryAllOfRefDescriptionReadonly, name, photoUrls, tags, status, additionalProperties);
465415
}
466416

467417
@Override
468418
public String toString() {
469419
StringBuilder sb = new StringBuilder();
470420
sb.append("class NewPet {\n");
471421
sb.append(" id: ").append(toIndentedString(id)).append("\n");
472-
sb.append(" categoryRefToInlineAllofString: ").append(toIndentedString(categoryRefToInlineAllofString)).append("\n");
473-
sb.append(" categoryInlineAllofString: ").append(toIndentedString(categoryInlineAllofString)).append("\n");
474422
sb.append(" categoryInlineAllof: ").append(toIndentedString(categoryInlineAllof)).append("\n");
475423
sb.append(" categoryAllOfRef: ").append(toIndentedString(categoryAllOfRef)).append("\n");
476424
sb.append(" categoryAllOfRefDescription: ").append(toIndentedString(categoryAllOfRefDescription)).append("\n");
@@ -503,8 +451,6 @@ private String toIndentedString(Object o) {
503451
// a set of all properties/fields (JSON key names)
504452
openapiFields = new HashSet<String>();
505453
openapiFields.add("id");
506-
openapiFields.add("category_ref_to_inline_allof_string");
507-
openapiFields.add("category_inline_allof_string");
508454
openapiFields.add("category_inline_allof");
509455
openapiFields.add("category_allOf_ref");
510456
openapiFields.add("category_allOf_ref_description");
@@ -540,12 +486,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
540486
}
541487
}
542488
JsonObject jsonObj = jsonElement.getAsJsonObject();
543-
if ((jsonObj.get("category_ref_to_inline_allof_string") != null && !jsonObj.get("category_ref_to_inline_allof_string").isJsonNull()) && !jsonObj.get("category_ref_to_inline_allof_string").isJsonPrimitive()) {
544-
throw new IllegalArgumentException(String.format("Expected the field `category_ref_to_inline_allof_string` to be a primitive type in the JSON string but got `%s`", jsonObj.get("category_ref_to_inline_allof_string").toString()));
545-
}
546-
if ((jsonObj.get("category_inline_allof_string") != null && !jsonObj.get("category_inline_allof_string").isJsonNull()) && !jsonObj.get("category_inline_allof_string").isJsonPrimitive()) {
547-
throw new IllegalArgumentException(String.format("Expected the field `category_inline_allof_string` to be a primitive type in the JSON string but got `%s`", jsonObj.get("category_inline_allof_string").toString()));
548-
}
549489
// validate the optional field `category_inline_allof`
550490
if (jsonObj.get("category_inline_allof") != null && !jsonObj.get("category_inline_allof").isJsonNull()) {
551491
NewPetCategoryInlineAllof.validateJsonElement(jsonObj.get("category_inline_allof"));

0 commit comments

Comments
 (0)