Skip to content

Commit b7c0d02

Browse files
committed
Group name cannot be null or empty - Fixes #2332
1 parent 498901a commit b7c0d02

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/models/GroupedOpenApi.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
import org.springdoc.core.customizers.RouterOperationCustomizer;
3737
import org.springdoc.core.filters.OpenApiMethodFilter;
3838

39+
import org.springframework.util.Assert;
3940
import org.springframework.util.CollectionUtils;
4041

41-
import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL;
42+
import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL_OR_EMPTY;
4243

4344
/**
4445
* The type Grouped open api.
@@ -117,7 +118,8 @@ public class GroupedOpenApi {
117118
* @param builder the builder
118119
*/
119120
private GroupedOpenApi(Builder builder) {
120-
this.group = Objects.requireNonNull(builder.group, GROUP_NAME_NOT_NULL);
121+
Assert.isTrue(StringUtils.isNotBlank(builder.group), GROUP_NAME_NOT_NULL_OR_EMPTY);
122+
this.group =builder.group;
121123
this.pathsToMatch = builder.pathsToMatch;
122124
this.packagesToScan = builder.packagesToScan;
123125
this.producesToMatch = builder.producesToMatch;

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/properties/AbstractSwaggerUiConfigProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.fasterxml.jackson.annotation.JsonProperty;
3333
import org.apache.commons.lang3.StringUtils;
3434

35-
import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL;
35+
import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL_OR_EMPTY;
3636

3737
/**
3838
* Please refer to the swagger
@@ -724,7 +724,7 @@ public SwaggerUrl() {
724724
* @param displayName the display name
725725
*/
726726
public SwaggerUrl(String group, String url, String displayName) {
727-
Objects.requireNonNull(group, GROUP_NAME_NOT_NULL);
727+
Objects.requireNonNull(group, GROUP_NAME_NOT_NULL_OR_EMPTY);
728728
this.url = url;
729729
this.name = group;
730730
this.displayName = StringUtils.defaultIfEmpty(displayName, this.name);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public final class Constants {
243243
/**
244244
* The constant GROUP_NAME_NOT_NULL.
245245
*/
246-
public static final String GROUP_NAME_NOT_NULL = "Group name can not be null";
246+
public static final String GROUP_NAME_NOT_NULL_OR_EMPTY = "Group name can not be null or empty";
247247

248248
/**
249249
* The constant GET_METHOD.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2023 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package test.org.springdoc.api.v30.app210;
26+
27+
import org.junit.jupiter.api.Test;
28+
import org.springdoc.core.models.GroupedOpenApi;
29+
import test.org.springdoc.api.AbstractCommonTest;
30+
31+
import org.springframework.boot.autoconfigure.SpringBootApplication;
32+
import org.springframework.boot.test.context.SpringBootTest;
33+
34+
import static org.junit.jupiter.api.Assertions.assertThrows;
35+
36+
@SpringBootTest
37+
public class SpringDocApp210Test extends AbstractCommonTest {
38+
39+
@Test
40+
public void testApp(){
41+
assertThrows(IllegalArgumentException.class, () -> GroupedOpenApi.builder().group("").build());
42+
}
43+
44+
@SpringBootApplication
45+
static class SpringDocTestApp {}
46+
47+
}

0 commit comments

Comments
 (0)