Skip to content

Commit bba71b7

Browse files
committed
fix: Fix missing items on nested @ArraySchema items in OAS 3.1 Resolves #4944 #4836
1 parent 52c993a commit bba71b7

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.medi
548548

549549
if (arraySchema.schema() != null) {
550550
if (arraySchema.schema().implementation().equals(Void.class)) {
551-
getSchemaFromAnnotation(arraySchema.schema(), components, jsonViewAnnotation, openapi31).ifPresent(arraySchemaObject::setItems);
551+
getSchemaFromAnnotation(arraySchema.schema(), components, jsonViewAnnotation, openapi31, arraySchemaObject.getItems()).ifPresent(arraySchemaObject::setItems);
552552
} else if (processSchemaImplementation) {
553553
getSchema(arraySchema.schema(), arraySchema, false, arraySchema.schema().implementation(), components, jsonViewAnnotation, openapi31).ifPresent(arraySchemaObject::setItems);
554554
}

modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/v31/ModelResolverOAS31Test.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ public void testOAS31Fields() {
8585
" properties:\n" +
8686
" billingAddress:\n" +
8787
" type: string\n" +
88+
" acceptingCountries:\n" +
89+
" type: array\n" +
90+
" items:\n" +
91+
" type: string\n" +
92+
" description: accepting country\n" +
93+
" enum:\n" +
94+
" - UNITED_STATES_OF_AMERICA\n" +
95+
" - CANADA\n" +
96+
" uniqueItems: true\n" +
97+
" availableCurrencies:\n" +
98+
" type: array\n" +
99+
" items:\n" +
100+
" $ref: \"#/components/schemas/Currency\"\n" +
101+
" description: available currencies\n" +
102+
" uniqueItems: true\n" +
103+
"Currency:\n" +
104+
" type: object\n" +
105+
" properties:\n" +
106+
" currencyCode:\n" +
107+
" type: string\n" +
88108
"ModelWithOAS31Stuff:\n" +
89109
" type: object\n" +
90110
" $comment: Random comment at schema level\n" +

modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/v31/model/CreditCard.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package io.swagger.v3.core.resolving.v31.model;
22

3+
import io.swagger.v3.oas.annotations.media.ArraySchema;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
6+
import java.util.Set;
7+
38
public class CreditCard {
49

510
private String billingAddress;
11+
private Set<Address.CountryEnum> acceptingCountries;
12+
private Set<Currency> availableCurrencies;
613

714
public String getBillingAddress() {
815
return billingAddress;
@@ -11,4 +18,22 @@ public String getBillingAddress() {
1118
public void setBillingAddress(String billingAddress) {
1219
this.billingAddress = billingAddress;
1320
}
21+
22+
@ArraySchema(schema = @Schema(description = "accepting country"))
23+
public Set<Address.CountryEnum> getAcceptingCountries() {
24+
return acceptingCountries;
25+
}
26+
27+
public void setAcceptingCountries(Set<Address.CountryEnum> acceptingCountries) {
28+
this.acceptingCountries = acceptingCountries;
29+
}
30+
31+
@ArraySchema(schema = @Schema(description = "available currencies"))
32+
public Set<Currency> getAvailableCurrencies() {
33+
return availableCurrencies;
34+
}
35+
36+
public void setAvailableCurrencies(Set<Currency> availableCurrencies) {
37+
this.availableCurrencies = availableCurrencies;
38+
}
1439
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.swagger.v3.core.resolving.v31.model;
2+
3+
public class Currency {
4+
5+
private String currencyCode;
6+
7+
public String getCurrencyCode() {
8+
return currencyCode;
9+
}
10+
11+
public void setCurrencyCode(String currencyCode) {
12+
this.currencyCode = currencyCode;
13+
}
14+
}

0 commit comments

Comments
 (0)