Skip to content

Commit 17cd6b2

Browse files
committed
code review
1 parent aee7cc2 commit 17cd6b2

File tree

3 files changed

+93
-13
lines changed

3 files changed

+93
-13
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.springdoc</groupId>
6+
<artifactId>springdoc-openapi-bom</artifactId>
7+
<version>2.8.7-SNAPSHOT</version>
8+
<packaging>pom</packaging>
9+
<description>Spring openapi documentation</description>
10+
<url>https://springdoc.org/springdoc-openapi-bom/</url>
11+
<licenses>
12+
<license>
13+
<name>The Apache License, Version 2.0</name>
14+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
15+
</license>
16+
</licenses>
17+
<developers>
18+
<developer>
19+
<name>Badr NASS LAHSEN</name>
20+
<email>[email protected]</email>
21+
<organization>springdoc</organization>
22+
<organizationUrl>https://springdoc.org/</organizationUrl>
23+
</developer>
24+
</developers>
25+
<scm>
26+
<connection>scm:git:[email protected]:springdoc/springdoc-openapi.git/springdoc-openapi-bom</connection>
27+
<developerConnection>scm:git:[email protected]:springdoc/springdoc-openapi.git/springdoc-openapi-bom</developerConnection>
28+
<url>[email protected]:springdoc/springdoc-openapi.git/springdoc-openapi-bom</url>
29+
</scm>
30+
<dependencyManagement>
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.springdoc</groupId>
34+
<artifactId>springdoc-openapi-starter-common</artifactId>
35+
<version>${project.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springdoc</groupId>
39+
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
40+
<version>${project.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springdoc</groupId>
44+
<artifactId>springdoc-openapi-starter-webflux-api</artifactId>
45+
<version>${project.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springdoc</groupId>
49+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
50+
<version>${project.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springdoc</groupId>
54+
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
55+
<version>${project.version}</version>
56+
</dependency>
57+
</dependencies>
58+
</dependencyManagement>
59+
</project>

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SchemaUtils.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
package org.springdoc.core.utils;
22

3+
import java.lang.annotation.Annotation;
4+
import java.lang.reflect.Field;
5+
import java.math.BigDecimal;
6+
import java.util.Arrays;
7+
import java.util.Collection;
8+
import java.util.HashSet;
9+
import java.util.List;
10+
import java.util.Optional;
11+
import java.util.OptionalDouble;
12+
import java.util.OptionalInt;
13+
import java.util.OptionalLong;
14+
import java.util.Set;
15+
import java.util.stream.Collectors;
16+
317
import io.swagger.v3.oas.annotations.Parameter;
18+
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
419
import io.swagger.v3.oas.models.media.Schema;
5-
import jakarta.validation.constraints.*;
20+
import jakarta.validation.constraints.DecimalMax;
21+
import jakarta.validation.constraints.DecimalMin;
22+
import jakarta.validation.constraints.Max;
23+
import jakarta.validation.constraints.Min;
24+
import jakarta.validation.constraints.NegativeOrZero;
25+
import jakarta.validation.constraints.Pattern;
26+
import jakarta.validation.constraints.PositiveOrZero;
27+
import jakarta.validation.constraints.Size;
628
import kotlin.reflect.KProperty;
729
import kotlin.reflect.jvm.ReflectJvmMapping;
30+
831
import org.springframework.core.KotlinDetector;
932
import org.springframework.lang.Nullable;
1033

11-
import java.lang.annotation.Annotation;
12-
import java.lang.reflect.Field;
13-
import java.math.BigDecimal;
14-
import java.util.*;
15-
import java.util.stream.Collectors;
16-
1734
import static org.springdoc.core.utils.Constants.OPENAPI_ARRAY_TYPE;
1835
import static org.springdoc.core.utils.Constants.OPENAPI_STRING_TYPE;
1936

@@ -77,7 +94,7 @@ public static boolean swaggerVisible(@Nullable io.swagger.v3.oas.annotations.med
7794
* @param schema the schema
7895
* @param parameter the parameter
7996
* @return the boolean or {@code null}
80-
* @see io.swagger.v3.oas.annotations.Parameter#required()
97+
* @see Parameter#required()
8198
* @see io.swagger.v3.oas.annotations.media.Schema#required()
8299
* @see io.swagger.v3.oas.annotations.media.Schema#requiredMode()
83100
*/
@@ -89,10 +106,10 @@ public static Boolean swaggerRequired(@Nullable io.swagger.v3.oas.annotations.me
89106
}
90107
if (schema != null) {
91108
if (schema.required()
92-
|| schema.requiredMode() == io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED) {
109+
|| schema.requiredMode() == RequiredMode.REQUIRED) {
93110
return true;
94111
}
95-
if (schema.requiredMode() == io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED) {
112+
if (schema.requiredMode() == RequiredMode.NOT_REQUIRED) {
96113
return false;
97114
}
98115
}
@@ -146,7 +163,7 @@ public static boolean fieldNullable(Field field) {
146163
* @param schema the schema
147164
* @param parameter the parameter
148165
* @return the boolean
149-
* @see io.swagger.v3.oas.annotations.Parameter#required()
166+
* @see Parameter#required()
150167
* @see io.swagger.v3.oas.annotations.media.Schema#required()
151168
* @see io.swagger.v3.oas.annotations.media.Schema#requiredMode()
152169
*/
@@ -203,11 +220,14 @@ public static void applyValidationsToSchema(Schema<?> schema, List<Annotation> a
203220
}
204221
}
205222
if (annotationName.equals(Size.class.getSimpleName())) {
206-
if (OPENAPI_ARRAY_TYPE.equals(schema.getType())) {
223+
String type = schema.getType();
224+
if (type == null && schema.getTypes() != null && schema.getTypes().size() == 1)
225+
type = schema.getTypes().iterator().next();
226+
if (OPENAPI_ARRAY_TYPE.equals(type)) {
207227
schema.setMinItems(((Size) anno).min());
208228
schema.setMaxItems(((Size) anno).max());
209229
}
210-
else if (OPENAPI_STRING_TYPE.equals(schema.getType())) {
230+
else if (OPENAPI_STRING_TYPE.equals(type)) {
211231
schema.setMinLength(((Size) anno).min());
212232
schema.setMaxLength(((Size) anno).max());
213233
}

springdoc-openapi-tests/springdoc-openapi-kotlin-webmvc-tests/src/test/kotlin/test/org/springdoc/api/v31/app17/SpringDocApp17Test.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import jakarta.validation.constraints.NotEmpty
44
import org.junit.jupiter.api.Assertions
55
import org.springdoc.core.customizers.DelegatingMethodParameterCustomizer
66
import org.springdoc.core.extractor.DelegatingMethodParameter
7+
import org.springdoc.core.utils.Constants
78
import org.springdoc.core.utils.Constants.SPRINGDOC_DEFAULT_FLAT_PARAM_OBJECT
89
import org.springframework.boot.autoconfigure.SpringBootApplication
910
import org.springframework.context.annotation.Bean

0 commit comments

Comments
 (0)