Skip to content

Commit 5e90829

Browse files
author
bnasslahsen
committed
added groovy module
1 parent db730c1 commit 5e90829

File tree

72 files changed

+782
-335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+782
-335
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<module>springdoc-openapi-kotlin</module>
5959
<module>springdoc-openapi-data-rest</module>
6060
<module>springdoc-openapi-security</module>
61+
<module>springdoc-openapi-groovy</module>
6162
</modules>
6263

6364
<properties>

springdoc-openapi-common/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,5 @@
4141
<groupId>org.apache.commons</groupId>
4242
<artifactId>commons-lang3</artifactId>
4343
</dependency>
44-
<dependency>
45-
<groupId>org.codehaus.groovy</groupId>
46-
<artifactId>groovy</artifactId>
47-
<optional>true</optional>
48-
</dependency>
4944
</dependencies>
5045
</project>

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.stream.Collectors;
2626

2727
import com.fasterxml.jackson.databind.node.ObjectNode;
28-
import groovy.lang.MetaClass;
2928
import io.swagger.v3.core.converter.ModelConverter;
3029
import io.swagger.v3.oas.models.Components;
3130
import io.swagger.v3.oas.models.OpenAPI;
@@ -34,15 +33,13 @@
3433
import org.springdoc.core.converters.AdditionalModelsConverter;
3534
import org.springdoc.core.converters.ModelConverterRegistrar;
3635
import org.springdoc.core.converters.PropertyCustomizingConverter;
37-
import org.springdoc.core.converters.RequestTypeToIgnoreConverter;
3836
import org.springdoc.core.converters.ResponseSupportConverter;
3937
import org.springdoc.core.customizers.OpenApiBuilderCustomiser;
4038
import org.springdoc.core.customizers.OpenApiCustomiser;
4139
import org.springdoc.core.customizers.PropertyCustomizer;
4240

4341
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
4442
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
45-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
4643
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4744
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4845
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
@@ -91,20 +88,6 @@ ResponseSupportConverter responseSupportConverter() {
9188
return new ResponseSupportConverter();
9289
}
9390

94-
@ConditionalOnClass(value = { MetaClass.class })
95-
class GroovyProvider {
96-
@Bean
97-
Object ignoreGroovyMetaClass() {
98-
SpringDocUtils.getConfig().addRequestWrapperToIgnore(MetaClass.class);
99-
return null;
100-
}
101-
102-
@Bean
103-
RequestTypeToIgnoreConverter requestTypeToIgnoreConverter() {
104-
return new RequestTypeToIgnoreConverter();
105-
}
106-
}
107-
10891
@Bean
10992
@ConditionalOnMissingBean
11093
OpenAPIBuilder openAPIBuilder(Optional<OpenAPI> openAPI, ApplicationContext context,

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/SpringDocDataRestConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
import io.swagger.v3.oas.models.media.MapSchema;
3131
import io.swagger.v3.oas.models.media.ObjectSchema;
3232
import io.swagger.v3.oas.models.media.StringSchema;
33+
import org.springdoc.core.customizers.OpenApiCustomiser;
34+
import org.springdoc.data.rest.converters.Pageable;
3335
import org.springdoc.data.rest.converters.RepresentationModelLinksOASMixin;
3436
import org.springdoc.data.rest.customisers.QuerydslPredicateOperationCustomizer;
35-
import org.springdoc.data.rest.converters.Pageable;
36-
import org.springdoc.core.customizers.OpenApiCustomiser;
3737

3838
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3939
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

springdoc-openapi-groovy/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>springdoc-openapi</artifactId>
7+
<groupId>org.springdoc</groupId>
8+
<version>1.3.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>springdoc-openapi-groovy</artifactId>
13+
14+
15+
<dependencies>
16+
<!-- springdoc-common -->
17+
<dependency>
18+
<groupId>org.springdoc</groupId>
19+
<artifactId>springdoc-openapi-common</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.codehaus.groovy</groupId>
24+
<artifactId>groovy</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springdoc</groupId>
28+
<artifactId>springdoc-openapi-webmvc-core</artifactId>
29+
<version>${project.version}</version>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>jakarta.servlet</groupId>
34+
<artifactId>jakarta.servlet-api</artifactId>
35+
<scope>provided</scope>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-maven-plugin</artifactId>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.codehaus.gmavenplus</groupId>
47+
<artifactId>gmavenplus-plugin</artifactId>
48+
<version>1.8.1</version>
49+
<executions>
50+
<execution>
51+
<goals>
52+
<goal>addSources</goal>
53+
<goal>addTestSources</goal>
54+
<goal>generateStubs</goal>
55+
<goal>compile</goal>
56+
<goal>generateTestStubs</goal>
57+
<goal>compileTests</goal>
58+
<goal>removeStubs</goal>
59+
<goal>removeTestStubs</goal>
60+
</goals>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package org.springdoc.groovy;
20+
21+
import groovy.lang.MetaClass;
22+
import org.springdoc.core.SpringDocUtils;
23+
import org.springdoc.core.converters.RequestTypeToIgnoreConverter;
24+
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.Configuration;
28+
29+
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
30+
31+
@Configuration
32+
@ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true)
33+
public class SpringDocGroovyConfiguration {
34+
35+
@Bean
36+
Object ignoreGroovyMetaClass() {
37+
SpringDocUtils.getConfig().addRequestWrapperToIgnore(MetaClass.class);
38+
return null;
39+
}
40+
41+
@Bean
42+
RequestTypeToIgnoreConverter requestTypeToIgnoreConverter() {
43+
return new RequestTypeToIgnoreConverter();
44+
}
45+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2+
org.springdoc.groovy.SpringDocGroovyConfiguration
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api;
20+
21+
import java.nio.charset.StandardCharsets;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.nio.file.Paths;
25+
26+
import nonapi.io.github.classgraph.utils.FileUtils;
27+
import org.junit.jupiter.api.Test;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
import org.springdoc.core.Constants;
31+
32+
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
34+
import org.springframework.boot.test.context.SpringBootTest;
35+
import org.springframework.test.context.ActiveProfiles;
36+
import org.springframework.test.web.servlet.MockMvc;
37+
import org.springframework.test.web.servlet.MvcResult;
38+
39+
import static org.hamcrest.Matchers.is;
40+
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
41+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
42+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
43+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
44+
45+
@ActiveProfiles("test")
46+
@SpringBootTest
47+
@AutoConfigureMockMvc
48+
public abstract class AbstractSpringDocTest {
49+
50+
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractSpringDocTest.class);
51+
52+
public static String className;
53+
54+
@Autowired
55+
protected MockMvc mockMvc;
56+
57+
public static String getContent(String fileName) throws Exception {
58+
try {
59+
Path path = Paths.get(FileUtils.class.getClassLoader().getResource(fileName).toURI());
60+
byte[] fileBytes = Files.readAllBytes(path);
61+
return new String(fileBytes, StandardCharsets.UTF_8);
62+
}
63+
catch (Exception e) {
64+
throw new RuntimeException("Failed to read file: " + fileName, e);
65+
}
66+
}
67+
68+
@Test
69+
public void testApp() throws Exception {
70+
className = getClass().getSimpleName();
71+
String testNumber = className.replaceAll("[^0-9]", "");
72+
MvcResult mockMvcResult = mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL)).andExpect(status().isOk())
73+
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
74+
String result = mockMvcResult.getResponse().getContentAsString();
75+
String expected = getContent("results/app" + testNumber + ".json");
76+
assertEquals(expected, result, true);
77+
}
78+
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app103/Car.groovy renamed to springdoc-openapi-groovy/src/test/groovy/test/org/springdoc/api/app1/Car.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package test.org.springdoc.api.app103
1+
package test.org.springdoc.api.app1
22

33
class Car {
44
Long id

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app103/CarController.groovy renamed to springdoc-openapi-groovy/src/test/groovy/test/org/springdoc/api/app1/CarController.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package test.org.springdoc.api.app103
1+
package test.org.springdoc.api.app1
22

33

44
import org.springframework.web.bind.annotation.GetMapping

0 commit comments

Comments
 (0)