Skip to content

Commit 53584f9

Browse files
committed
Fixed the rendering by applying conventions
(6)
1 parent 919ac63 commit 53584f9

19 files changed

+449
-204
lines changed

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

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,79 @@ package grails.springfox.sample
22

33
import grails.boot.GrailsApp
44
import grails.boot.config.GrailsAutoConfiguration
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
56
import org.springframework.context.annotation.Bean
67
import org.springframework.context.annotation.Import
78
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
89
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
10+
import springfox.documentation.grails.AlternateTypeRuleConvention
11+
import springfox.documentation.grails.DefaultGrailsPropertySelector
12+
import springfox.documentation.grails.DefaultGrailsPropertyTransformer
13+
import springfox.documentation.grails.DefaultGeneratedClassNamingStrategy
14+
import springfox.documentation.grails.GrailsPropertySelector
15+
import springfox.documentation.grails.GrailsPropertyTransformer
16+
import springfox.documentation.grails.GeneratedClassNamingStrategy
917
import springfox.documentation.grails.SpringfoxGrailsIntegrationConfiguration
18+
import springfox.documentation.schema.AlternateTypeRule
1019
import springfox.documentation.spi.DocumentationType
1120
import springfox.documentation.spring.web.plugins.Docket
1221
import springfox.documentation.swagger2.annotations.EnableSwagger2
1322

14-
import static com.google.common.base.Predicates.not
15-
import static springfox.documentation.builders.PathSelectors.ant
23+
import static com.google.common.base.Predicates.*
24+
import static springfox.documentation.builders.PathSelectors.*
1625

1726
@EnableSwagger2
1827
@Import([SpringfoxGrailsIntegrationConfiguration])
1928
class Application extends GrailsAutoConfiguration {
20-
static void main(String[] args) {
21-
GrailsApp.run(Application, args)
22-
}
29+
static void main(String[] args) {
30+
GrailsApp.run(Application, args)
31+
}
2332

24-
@Bean
25-
Docket api() {
26-
new Docket(DocumentationType.SWAGGER_2)
27-
.ignoredParameterTypes(MetaClass)
28-
.select()
29-
.paths(not(ant("/error")))
30-
.build()
31-
}
33+
@Bean
34+
@ConditionalOnMissingBean(GrailsPropertySelector)
35+
GrailsPropertySelector propertySelector() {
36+
new DefaultGrailsPropertySelector()
37+
}
38+
39+
@Bean
40+
@ConditionalOnMissingBean(GrailsPropertyTransformer)
41+
GrailsPropertyTransformer propertyTransformer() {
42+
new DefaultGrailsPropertyTransformer()
43+
}
3244

33-
@Bean
34-
static WebMvcConfigurerAdapter webConfigurer() {
35-
new WebMvcConfigurerAdapter() {
36-
@Override
37-
void addResourceHandlers(ResourceHandlerRegistry registry) {
38-
if (!registry.hasMappingForPattern("/webjars/**")) {
39-
registry
40-
.addResourceHandler("/webjars/**")
41-
.addResourceLocations("classpath:/META-INF/resources/webjars/")
42-
}
43-
if (!registry.hasMappingForPattern("/swagger-ui.html")) {
44-
registry
45-
.addResourceHandler("/swagger-ui.html")
46-
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html")
47-
}
48-
}
45+
@Bean
46+
@ConditionalOnMissingBean(GeneratedClassNamingStrategy)
47+
GeneratedClassNamingStrategy namingStrategy() {
48+
new DefaultGeneratedClassNamingStrategy()
49+
}
50+
51+
@Bean
52+
Docket api(AlternateTypeRuleConvention convention) {
53+
def typeRules = convention.rules()
54+
new Docket(DocumentationType.SWAGGER_2)
55+
.ignoredParameterTypes(MetaClass)
56+
.select()
57+
.paths(not(ant("/error")))
58+
.build()
59+
.alternateTypeRules(typeRules.toArray(new AlternateTypeRule[typeRules.size()]))
60+
}
61+
62+
@Bean
63+
static WebMvcConfigurerAdapter webConfigurer() {
64+
new WebMvcConfigurerAdapter() {
65+
@Override
66+
void addResourceHandlers(ResourceHandlerRegistry registry) {
67+
if (!registry.hasMappingForPattern("/webjars/**")) {
68+
registry
69+
.addResourceHandler("/webjars/**")
70+
.addResourceLocations("classpath:/META-INF/resources/webjars/")
71+
}
72+
if (!registry.hasMappingForPattern("/swagger-ui.html")) {
73+
registry
74+
.addResourceHandler("/swagger-ui.html")
75+
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html")
4976
}
77+
}
5078
}
79+
}
5180
}

springfox-grails-contract-tests/src/integration-test/resources/expected-service-description.json

Lines changed: 12 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,27 +3636,6 @@
36363636
"Artist": {
36373637
"type": "object",
36383638
"properties": {
3639-
"albums": {
3640-
"type": "array",
3641-
"items": {
3642-
"$ref": "#/definitions/Album"
3643-
}
3644-
},
3645-
"attached": {
3646-
"type": "boolean"
3647-
},
3648-
"dirty": {
3649-
"type": "boolean"
3650-
},
3651-
"dirtyPropertyNames": {
3652-
"type": "array",
3653-
"items": {
3654-
"type": "object"
3655-
}
3656-
},
3657-
"errors": {
3658-
"$ref": "#/definitions/Errors"
3659-
},
36603639
"id": {
36613640
"type": "integer",
36623641
"format": "int64"
@@ -3667,22 +3646,7 @@
36673646
"name": {
36683647
"type": "string"
36693648
},
3670-
"properties": {
3671-
"type": "object"
3672-
},
3673-
"signedTo": {
3674-
"$ref": "#/definitions/Label"
3675-
},
36763649
"signedToId": {
3677-
"type": "object"
3678-
},
3679-
"songs": {
3680-
"type": "array",
3681-
"items": {
3682-
"$ref": "#/definitions/Song"
3683-
}
3684-
},
3685-
"version": {
36863650
"type": "integer",
36873651
"format": "int64"
36883652
}
@@ -3738,52 +3702,24 @@
37383702
"Song": {
37393703
"type": "object",
37403704
"properties": {
3741-
"album": {
3742-
"$ref": "#/definitions/Album"
3743-
},
37443705
"albumId": {
3745-
"type": "object"
3746-
},
3747-
"artist": {
3748-
"$ref": "#/definitions/Artist"
3706+
"type": "integer",
3707+
"format": "int64"
37493708
},
37503709
"artistId": {
3751-
"type": "object"
3752-
},
3753-
"attached": {
3754-
"type": "boolean"
3755-
},
3756-
"dirty": {
3757-
"type": "boolean"
3758-
},
3759-
"dirtyPropertyNames": {
3760-
"type": "array",
3761-
"items": {
3762-
"type": "object"
3763-
}
3764-
},
3765-
"errors": {
3766-
"$ref": "#/definitions/Errors"
3767-
},
3768-
"genre": {
3769-
"$ref": "#/definitions/Genre"
3710+
"type": "integer",
3711+
"format": "int64"
37703712
},
37713713
"genreId": {
3772-
"type": "object"
3714+
"type": "integer",
3715+
"format": "int64"
37733716
},
37743717
"id": {
37753718
"type": "integer",
37763719
"format": "int64"
37773720
},
3778-
"properties": {
3779-
"type": "object"
3780-
},
37813721
"title": {
37823722
"type": "string"
3783-
},
3784-
"version": {
3785-
"type": "integer",
3786-
"format": "int64"
37873723
}
37883724
}
37893725
},
@@ -3819,94 +3755,36 @@
38193755
"address": {
38203756
"type": "string"
38213757
},
3822-
"albums": {
3823-
"type": "array",
3824-
"items": {
3825-
"$ref": "#/definitions/Album"
3826-
}
3827-
},
3828-
"artists": {
3829-
"type": "array",
3830-
"items": {
3831-
"$ref": "#/definitions/Artist"
3832-
}
3833-
},
3834-
"attached": {
3835-
"type": "boolean"
3836-
},
3837-
"dirty": {
3838-
"type": "boolean"
3839-
},
3840-
"dirtyPropertyNames": {
3841-
"type": "array",
3842-
"items": {
3843-
"type": "object"
3844-
}
3845-
},
3846-
"errors": {
3847-
"$ref": "#/definitions/Errors"
3848-
},
38493758
"id": {
38503759
"type": "integer",
38513760
"format": "int64"
38523761
},
38533762
"name": {
38543763
"type": "string"
3855-
},
3856-
"properties": {
3857-
"type": "object"
3858-
},
3859-
"version": {
3860-
"type": "integer",
3861-
"format": "int64"
38623764
}
38633765
}
38643766
},
38653767
"Album": {
38663768
"type": "object",
38673769
"properties": {
3868-
"albumArtist": {
3869-
"$ref": "#/definitions/Artist"
3870-
},
38713770
"albumArtistId": {
3872-
"type": "object"
3873-
},
3874-
"attached": {
3875-
"type": "boolean"
3771+
"type": "integer",
3772+
"format": "int64"
38763773
},
38773774
"coverImage": {
38783775
"type": "string"
38793776
},
3880-
"dirty": {
3881-
"type": "boolean"
3882-
},
3883-
"dirtyPropertyNames": {
3884-
"type": "array",
3885-
"items": {
3886-
"type": "object"
3887-
}
3888-
},
3889-
"errors": {
3890-
"$ref": "#/definitions/Errors"
3891-
},
3892-
"genre": {
3893-
"$ref": "#/definitions/Genre"
3894-
},
38953777
"genreId": {
3896-
"type": "object"
3778+
"type": "integer",
3779+
"format": "int64"
38973780
},
38983781
"id": {
38993782
"type": "integer",
39003783
"format": "int64"
39013784
},
3902-
"label": {
3903-
"$ref": "#/definitions/Label"
3904-
},
39053785
"labelId": {
3906-
"type": "object"
3907-
},
3908-
"properties": {
3909-
"type": "object"
3786+
"type": "integer",
3787+
"format": "int64"
39103788
},
39113789
"rating": {
39123790
"type": "string",
@@ -3922,21 +3800,11 @@
39223800
"type": "string",
39233801
"format": "date-time"
39243802
},
3925-
"songs": {
3926-
"type": "array",
3927-
"items": {
3928-
"$ref": "#/definitions/Song"
3929-
}
3930-
},
39313803
"subtitle": {
39323804
"type": "string"
39333805
},
39343806
"title": {
39353807
"type": "string"
3936-
},
3937-
"version": {
3938-
"type": "integer",
3939-
"format": "int64"
39403808
}
39413809
}
39423810
},
@@ -3978,40 +3846,12 @@
39783846
"Genre": {
39793847
"type": "object",
39803848
"properties": {
3981-
"albums": {
3982-
"type": "array",
3983-
"items": {
3984-
"$ref": "#/definitions/Album"
3985-
}
3986-
},
3987-
"attached": {
3988-
"type": "boolean"
3989-
},
3990-
"dirty": {
3991-
"type": "boolean"
3992-
},
3993-
"dirtyPropertyNames": {
3994-
"type": "array",
3995-
"items": {
3996-
"type": "object"
3997-
}
3998-
},
3999-
"errors": {
4000-
"$ref": "#/definitions/Errors"
4001-
},
40023849
"id": {
40033850
"type": "integer",
40043851
"format": "int64"
40053852
},
40063853
"name": {
40073854
"type": "string"
4008-
},
4009-
"properties": {
4010-
"type": "object"
4011-
},
4012-
"version": {
4013-
"type": "integer",
4014-
"format": "int64"
40153855
}
40163856
}
40173857
}

springfox-grails/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dependencies {
6868
compile "io.springfox:springfox-spi:${springfox}"
6969
compile "io.springfox:springfox-core:${springfox}"
7070
compile "io.springfox:springfox-swagger2:${springfox}"
71-
//compile "net.bytebuddy:byte-buddy:${byteBuddyVersion}"
71+
compile "net.bytebuddy:byte-buddy:${byteBuddyVersion}"
7272
}
7373

7474
task sourcesJar(type: Jar, dependsOn: classes) {

0 commit comments

Comments
 (0)