Skip to content

Commit

Permalink
Duplicate GroupConfigs in SpringDocConfigProperties. Fixes #2518.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Mar 2, 2024
1 parent 2da5a96 commit 8ece255
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
package org.springdoc.core.properties;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import io.swagger.v3.oas.models.SpecVersion;
import org.springdoc.core.configuration.SpringDocConfiguration;
Expand Down Expand Up @@ -112,7 +115,7 @@ public class SpringDocConfigProperties {
/**
* The Group configs.
*/
private List<GroupConfig> groupConfigs = new ArrayList<>();
private Set<GroupConfig> groupConfigs = new HashSet<>();

/**
* The Auto tag classes.
Expand Down Expand Up @@ -781,12 +784,13 @@ public boolean isCacheDisabled() {
return cache.isDisabled();
}


/**
* Gets group configs.
*
* @return the group configs
*/
public List<GroupConfig> getGroupConfigs() {
public Set<GroupConfig> getGroupConfigs() {
return groupConfigs;
}

Expand All @@ -795,7 +799,7 @@ public List<GroupConfig> getGroupConfigs() {
*
* @param groupConfigs the group configs
*/
public void setGroupConfigs(List<GroupConfig> groupConfigs) {
public void setGroupConfigs(Set<GroupConfig> groupConfigs) {
this.groupConfigs = groupConfigs;
}

Expand Down Expand Up @@ -1703,6 +1707,19 @@ public String getDisplayName() {
public void setDisplayName(String displayName) {
this.displayName = displayName;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GroupConfig that = (GroupConfig) o;
return Objects.equals(group, that.group);
}

@Override
public int hashCode() {
return Objects.hash(group);
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
*
* * 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.app214;

import org.junit.jupiter.api.Test;
import org.springdoc.core.customizers.SpecPropertiesCustomizer;
import org.springdoc.core.properties.SpringDocConfigProperties;
import org.springdoc.core.properties.SpringDocConfigProperties.GroupConfig;
import test.org.springdoc.api.AbstractCommonTest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;

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

/**
* <p>
* A test for {@link SpecPropertiesCustomizer}
*/
@SpringBootTest
@TestPropertySource(properties = { "springdoc.group-configs[0].group=Group0",
"springdoc.group-configs[0].packages-to-scan=com.my-package",
"springdoc.group-configs[1].group=Group1",
"springdoc.group-configs[1].packages-to-scan=com.my-package",
"springdoc.group-configs[2].group=Group2",
"springdoc.group-configs[2].packages-to-scan=com.my-package",
"springdoc.group-configs[3].group=Group3",
"springdoc.group-configs[3].packages-to-scan=com.my-package" })

public class SpringDocApp214Test extends AbstractCommonTest {

@Autowired
private SpringDocConfigProperties springDocConfigProperties;

@SpringBootApplication
static class SpringDocTestApp {}

@Test
public void testApp() throws Exception {
assertEquals(4, springDocConfigProperties.getGroupConfigs().stream().map(GroupConfig::getGroup).toList().size());
}

}

0 comments on commit 8ece255

Please sign in to comment.