Skip to content

Commit d541c09

Browse files
committed
Simplified the configuration and updated the documentation
1 parent 330291b commit d541c09

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

README.adoc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ dependencies {
9393

9494
NOTE: The current snapshot version that is available is `1.0.0-SNAPSHOT`
9595

96+
== Demo application
97+
98+
The demo application is available in https://github.com/springfox/springfox-grails-demo[this repository]. You can
99+
see a live demo running or https://immense-escarpment-17128.herokuapp.com/swagger-ui.html[heroku here].
100+
96101
===== Configure the springfox grails integration
97102

98103
In your Application (GrailsAutoConfiguration) startup entry-point follow the steps below
@@ -113,16 +118,12 @@ class Application extends GrailsAutoConfiguration {
113118
// 3. **Optionally** define a custom docket or omit this step to use the default
114119
// For grails it is preferrable to use use the following settings.
115120
@Bean
116-
Docket api(List<AlternateTypeRuleConvention> conventions) { //<1>
117-
def typeRules = conventions.collectMany {
118-
it.rules()
119-
}
121+
Docket api() {
120122
new Docket(DocumentationType.SWAGGER_2)
121123
.ignoredParameterTypes(MetaClass)
122124
.select()
123125
.paths(not(ant("/error")))
124126
.build()
125-
.alternateTypeRules(typeRules.toArray(new AlternateTypeRule[typeRules.size()]))
126127
}
127128
128129
// 4. **Optionally** in the absense of asset pipeline configure the swagger-ui webjar to serve the scaffolded
@@ -147,7 +148,6 @@ class Application extends GrailsAutoConfiguration {
147148
}
148149
}
149150
----
150-
<1> Conventions are way to describe conventions specific to grails
151151

152152
==== Swagger UI integration
153153

@@ -186,6 +186,16 @@ dependencies {
186186

187187
NOTE: The current snapshot in development is `2.7.0-SNAPSHOT`
188188

189+
==== Extensibility
190+
191+
TODO: Add more docs
192+
- Conventions - for adding custom conventions for replacing grails types
193+
- GrailsPropertySelector - for overriding the selection of grails properties by the default convention
194+
- GrailsPropertyTransformer - for overriding the transformer of the grails property
195+
- GeneratedClassNamingStrategy - for naming the generated class mixins
196+
197+
==== Trouble shooting
198+
189199
If you get an exception when you try to run your app, this might be because of the chosen profile for your application. If you use the `rest-api` profile, everything should be fine, but if you've chosen the `web` profile, it is likely that you have to add something like
190200

191201
grails.serverURL: http://localhost:8080

springfox-grails-contract-tests/grails-app/init/grails/springfox/sample/Application.groovy

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@ package grails.springfox.sample
22

33
import grails.boot.GrailsApp
44
import grails.boot.config.GrailsAutoConfiguration
5-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
65
import org.springframework.context.annotation.Bean
76
import org.springframework.context.annotation.Import
87
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
98
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
10-
import springfox.documentation.grails.DefaultGrailsPropertySelector
11-
import springfox.documentation.grails.DefaultGrailsPropertyTransformer
12-
import springfox.documentation.grails.DefaultGeneratedClassNamingStrategy
13-
import springfox.documentation.grails.GrailsPropertySelector
14-
import springfox.documentation.grails.GrailsPropertyTransformer
15-
import springfox.documentation.grails.GeneratedClassNamingStrategy
169
import springfox.documentation.grails.SpringfoxGrailsIntegrationConfiguration
17-
import springfox.documentation.schema.AlternateTypeRule
18-
import springfox.documentation.schema.AlternateTypeRuleConvention
1910
import springfox.documentation.spi.DocumentationType
2011
import springfox.documentation.spring.web.plugins.Docket
2112
import springfox.documentation.swagger2.annotations.EnableSwagger2
@@ -31,34 +22,12 @@ class Application extends GrailsAutoConfiguration {
3122
}
3223

3324
@Bean
34-
@ConditionalOnMissingBean(GrailsPropertySelector)
35-
GrailsPropertySelector propertySelector() {
36-
new DefaultGrailsPropertySelector()
37-
}
38-
39-
@Bean
40-
@ConditionalOnMissingBean(GrailsPropertyTransformer)
41-
GrailsPropertyTransformer propertyTransformer() {
42-
new DefaultGrailsPropertyTransformer()
43-
}
44-
45-
@Bean
46-
@ConditionalOnMissingBean(GeneratedClassNamingStrategy)
47-
GeneratedClassNamingStrategy namingStrategy() {
48-
new DefaultGeneratedClassNamingStrategy()
49-
}
50-
51-
@Bean
52-
Docket api(List<AlternateTypeRuleConvention> conventions) {
53-
def typeRules = conventions.collectMany {
54-
it.rules()
55-
}
25+
Docket api() {
5626
new Docket(DocumentationType.SWAGGER_2)
5727
.ignoredParameterTypes(MetaClass)
5828
.select()
5929
.paths(not(ant("/error")))
6030
.build()
61-
.alternateTypeRules(typeRules.toArray(new AlternateTypeRule[typeRules.size()]))
6231
}
6332

6433
@Bean

springfox-grails/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies {
5757
provided "org.springframework:spring-web:$spring"
5858
provided "org.springframework:spring-webmvc:$spring"
5959
provided "org.springframework:spring-context:$spring"
60+
provided "org.springframework.boot:spring-boot-autoconfigure:$springBoot"
6061
provided "org.grails:grails-core:$grails"
6162
provided "org.grails:grails-web-url-mappings:$grails"
6263
provided "org.grails:grails-web-url-mappings:$grails"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
package springfox.documentation.grails;
22

3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4+
import org.springframework.context.annotation.Bean;
35
import org.springframework.context.annotation.ComponentScan;
46
import org.springframework.context.annotation.Configuration;
57

68
@Configuration
79
@ComponentScan(basePackages = "springfox.documentation.grails")
810
public class SpringfoxGrailsIntegrationConfiguration {
11+
12+
@Bean
13+
@ConditionalOnMissingBean(GrailsPropertySelector.class)
14+
public GrailsPropertySelector propertySelector() {
15+
return new DefaultGrailsPropertySelector();
16+
}
17+
18+
@Bean
19+
@ConditionalOnMissingBean(GrailsPropertyTransformer.class)
20+
public GrailsPropertyTransformer propertyTransformer() {
21+
return new DefaultGrailsPropertyTransformer();
22+
}
23+
24+
@Bean
25+
@ConditionalOnMissingBean(GeneratedClassNamingStrategy.class)
26+
GeneratedClassNamingStrategy namingStrategy() {
27+
return new DefaultGeneratedClassNamingStrategy();
28+
}
929
}

0 commit comments

Comments
 (0)