Skip to content

Commit

Permalink
Group name cannot be null or empty - Fixes #2332
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Aug 5, 2023
1 parent 498901a commit b7c0d02
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
import org.springdoc.core.customizers.RouterOperationCustomizer;
import org.springdoc.core.filters.OpenApiMethodFilter;

import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL;
import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL_OR_EMPTY;

/**
* The type Grouped open api.
Expand Down Expand Up @@ -117,7 +118,8 @@ public class GroupedOpenApi {
* @param builder the builder
*/
private GroupedOpenApi(Builder builder) {
this.group = Objects.requireNonNull(builder.group, GROUP_NAME_NOT_NULL);
Assert.isTrue(StringUtils.isNotBlank(builder.group), GROUP_NAME_NOT_NULL_OR_EMPTY);
this.group =builder.group;
this.pathsToMatch = builder.pathsToMatch;
this.packagesToScan = builder.packagesToScan;
this.producesToMatch = builder.producesToMatch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;

import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL;
import static org.springdoc.core.utils.Constants.GROUP_NAME_NOT_NULL_OR_EMPTY;

/**
* Please refer to the swagger
Expand Down Expand Up @@ -724,7 +724,7 @@ public SwaggerUrl() {
* @param displayName the display name
*/
public SwaggerUrl(String group, String url, String displayName) {
Objects.requireNonNull(group, GROUP_NAME_NOT_NULL);
Objects.requireNonNull(group, GROUP_NAME_NOT_NULL_OR_EMPTY);
this.url = url;
this.name = group;
this.displayName = StringUtils.defaultIfEmpty(displayName, this.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public final class Constants {
/**
* The constant GROUP_NAME_NOT_NULL.
*/
public static final String GROUP_NAME_NOT_NULL = "Group name can not be null";
public static final String GROUP_NAME_NOT_NULL_OR_EMPTY = "Group name can not be null or empty";

/**
* The constant GET_METHOD.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* *
* * *
* * * *
* * * * * Copyright 2019-2023 the original author or authors.
* * * * *
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * * you may not use this file except in compliance with the License.
* * * * * You may obtain a copy of the License at
* * * * *
* * * * * https://www.apache.org/licenses/LICENSE-2.0
* * * * *
* * * * * Unless required by applicable law or agreed to in writing, software
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * * See the License for the specific language governing permissions and
* * * * * limitations under the License.
* * * *
* * *
* *
*
*/

package test.org.springdoc.api.v30.app210;

import org.junit.jupiter.api.Test;
import org.springdoc.core.models.GroupedOpenApi;
import test.org.springdoc.api.AbstractCommonTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;

import static org.junit.jupiter.api.Assertions.assertThrows;

@SpringBootTest
public class SpringDocApp210Test extends AbstractCommonTest {

@Test
public void testApp(){
assertThrows(IllegalArgumentException.class, () -> GroupedOpenApi.builder().group("").build());
}

@SpringBootApplication
static class SpringDocTestApp {}

}

0 comments on commit b7c0d02

Please sign in to comment.