Skip to content

Commit 1062799

Browse files
committed
Fixed the documentation to reflect the right maven coordinates
Also miscellaneous documentation edits for clarity. Added a point about the swagger-ui dependency. Removed maven related references. Grails 3 only supports gradle. fixes #7 fixes #8
1 parent cccc691 commit 1062799

File tree

2 files changed

+81
-72
lines changed

2 files changed

+81
-72
lines changed

README.adoc

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ repositories {
7171
}
7272
7373
dependencies {
74-
compile "io.springfox:springfox-grails:{releaseVersion}"
74+
compile "io.springfox.grails:springfox-grails:{releaseVersion}" //<1>
7575
}
7676
----
7777

78+
NOTE: This project has not been released yet.
79+
7880
===== Snapshot
7981

8082
[source,groovy]
@@ -85,51 +87,11 @@ repositories {
8587
}
8688
8789
dependencies {
88-
compile "io.springfox:springfox-grails:{snapshotVersion}"
90+
compile "io.springfox:springfox-grails:{snapshotVersion}" //<1>
8991
}
9092
----
9193

92-
93-
==== Maven
94-
===== Release
95-
96-
[source,xml]
97-
[subs="verbatim,attributes"]
98-
----
99-
<repositories>
100-
<repository>
101-
<id>jcenter-snapshots</id>
102-
<name>jcenter</name>
103-
<url>https://jcenter.bintray.com/</url>
104-
</repository>
105-
</repositories>
106-
107-
<dependency>
108-
<groupId>io.springfox</groupId>
109-
<artifactId>springfox-grails</artifactId>
110-
<version>{releaseVersion}</version>
111-
</dependency>
112-
----
113-
114-
===== Snapshot
115-
116-
[source,xml]
117-
[subs="verbatim,attributes"]
118-
----
119-
<repositories>
120-
<repository>
121-
<id>jcenter-snapshots</id>
122-
<name>jcenter</name>
123-
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
124-
</repository>
125-
</repositories>
126-
127-
<dependency>
128-
<groupId>io.springfox</groupId>
129-
<artifactId>springfox-grails</artifactId>
130-
<version>{snapshotVersion}</version>
131-
</dependency>
132-
----
94+
NOTE: The current snapshot version that is available is `1.0.0-SNAPSHOT`
13395

13496
===== Configure the springfox grails integration
13597

@@ -144,41 +106,86 @@ In your Application (GrailsAutoConfiguration) startup entry-point follow the ste
144106
// 2. Import the springfox grails integration configuration
145107
@Import([springfox.documentation.grails.SpringfoxGrailsIntegrationConfiguration])
146108
class Application extends GrailsAutoConfiguration {
147-
static void main(String[] args) {
148-
GrailsApp.run(Application, args)
109+
static void main(String[] args) {
110+
GrailsApp.run(Application, args)
111+
}
112+
113+
// 3. **Optionally** define a custom docket or omit this step to use the default
114+
// For grails it is preferrable to use use the following settings.
115+
@Bean
116+
Docket api(List<AlternateTypeRuleConvention> conventions) { //<1>
117+
def typeRules = conventions.collectMany {
118+
it.rules()
119+
}
120+
new Docket(DocumentationType.SWAGGER_2)
121+
.ignoredParameterTypes(MetaClass)
122+
.select()
123+
.paths(not(ant("/error")))
124+
.build()
125+
.alternateTypeRules(typeRules.toArray(new AlternateTypeRule[typeRules.size()]))
126+
}
127+
128+
// 4. **Optionally** in the absense of asset pipeline configure the swagger-ui webjar to serve the scaffolded
129+
swagger UI
130+
@Bean
131+
static WebMvcConfigurerAdapter webConfigurer() {
132+
new WebMvcConfigurerAdapter() {
133+
@Override
134+
void addResourceHandlers(ResourceHandlerRegistry registry) {
135+
if (!registry.hasMappingForPattern("/webjars/**")) {
136+
registry
137+
.addResourceHandler("/webjars/**")
138+
.addResourceLocations("classpath:/META-INF/resources/webjars/")
139+
}
140+
if (!registry.hasMappingForPattern("/swagger-ui.html")) {
141+
registry
142+
.addResourceHandler("/swagger-ui.html")
143+
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html")
144+
}
145+
}
146+
}
149147
}
148+
}
149+
----
150+
<1> Conventions are way to describe conventions specific to grails
150151

152+
==== Swagger UI integration
151153

152-
// 3. **Optionally** define a custom docket or omit this step to use the default
153-
@Bean
154-
Docket api() {
155-
new Docket(DocumentationType.SWAGGER_2)
156-
.ignoredParameterTypes(MetaClass)
157-
}
154+
IMPORTANT: In order to use the bundled swagger UI as explained in ___step 4___ above. The following library needs to be
155+
included in the `build.gradle`
158156

159-
// 4. **Optionally** configure the swagger-ui webjar to serve the scaffolded swagger UI
160-
@Bean
161-
static WebMvcConfigurerAdapter webConfigurer() {
162-
new WebMvcConfigurerAdapter() {
163-
@Override
164-
void addResourceHandlers(ResourceHandlerRegistry registry) {
165-
if (!registry.hasMappingForPattern("/webjars/**")) {
166-
registry
167-
.addResourceHandler("/webjars/**")
168-
.addResourceLocations("classpath:/META-INF/resources/webjars/")
169-
}
170-
if (!registry.hasMappingForPattern("/swagger-ui.html")) {
171-
registry
172-
.addResourceHandler("/swagger-ui.html")
173-
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html")
174-
}
175-
}
176-
}
177-
}
157+
===== Release
158+
[source,groovy]
159+
[subs="verbatim,attributes"]
160+
----
161+
repositories {
162+
jcenter()
163+
}
164+
165+
dependencies {
166+
compile "compile "io.springfox:springfox-swagger-ui:{springfoxReleaseVersion}" //<1>
167+
}
168+
----
169+
170+
NOTE: The latest released version is image:https://api.bintray.com/packages/springfox/maven-repo/springfox/images/download.svg["Springfox Version",
171+
link="https://bintray.com/springfox/maven-repo/springfox/_latestVersion"]
172+
173+
===== Snapshot
174+
175+
[source,groovy]
176+
[subs="verbatim,attributes"]
177+
----
178+
repositories {
179+
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
178180
}
179181
182+
dependencies {
183+
compile "compile "io.springfox:springfox-swagger-ui:{springfoxSnapshotVersion}" //<1>
184+
}
180185
----
181186

187+
NOTE: The current snapshot in development is `2.7.0-SNAPSHOT`
188+
182189
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
183190

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ class Application extends GrailsAutoConfiguration {
4949
}
5050

5151
@Bean
52-
Docket api(AlternateTypeRuleConvention convention) {
53-
def typeRules = convention.rules()
52+
Docket api(List<AlternateTypeRuleConvention> conventions) {
53+
def typeRules = conventions.collectMany {
54+
it.rules()
55+
}
5456
new Docket(DocumentationType.SWAGGER_2)
5557
.ignoredParameterTypes(MetaClass)
5658
.select()

0 commit comments

Comments
 (0)