29
29
import io .swagger .v3 .oas .models .media .StringSchema ;
30
30
import org .springdoc .core .converters .Pageable ;
31
31
import org .springdoc .core .customizers .OpenApiCustomiser ;
32
-
33
32
import org .springdoc .core .hal .RepresentationModelLinksOASMixin ;
33
+
34
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
34
35
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
35
36
import org .springframework .context .annotation .Bean ;
36
37
import org .springframework .context .annotation .Configuration ;
@@ -51,31 +52,36 @@ public class SpringDocDataRestConfiguration {
51
52
.replaceWithClass (org .springframework .data .domain .PageRequest .class ,Pageable .class );
52
53
}
53
54
54
- @ Bean
55
- public HalProvider halProvider (RepositoryRestConfiguration repositoryRestConfiguration ) {
56
- return new HalProvider (repositoryRestConfiguration );
57
- }
55
+ @ Configuration
56
+ @ ConditionalOnClass (RepositoryRestConfiguration .class )
57
+ class HalProviderConfiguration {
58
58
59
- /**
60
- * Registers an OpenApiCustomiser and a jackson mixin to ensure the definition of `Links` matches the serialized
61
- * output. This is done because the customer serializer converts the data to a map before serializing it.
62
- *
63
- * @see org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalLinkListSerializer#serialize(Links, JsonGenerator, SerializerProvider)
64
- */
65
- @ Bean
66
- public OpenApiCustomiser linksSchemaCustomiser (RepositoryRestConfiguration repositoryRestConfiguration ) {
67
- if (!repositoryRestConfiguration .useHalAsDefaultJsonMediaType ()) {
68
- return openApi -> {};
69
- }
70
- Json .mapper ().addMixIn (RepresentationModel .class , RepresentationModelLinksOASMixin .class );
59
+ @ Bean
60
+ public HalProvider halProvider (RepositoryRestConfiguration repositoryRestConfiguration ) {
61
+ return new HalProvider (repositoryRestConfiguration );
62
+ }
71
63
72
- ResolvedSchema resolvedLinkSchema = ModelConverters .getInstance ()
73
- .resolveAsResolvedSchema (new AnnotatedType (Link .class ));
64
+ /**
65
+ * Registers an OpenApiCustomiser and a jackson mixin to ensure the definition of `Links` matches the serialized
66
+ * output. This is done because the customer serializer converts the data to a map before serializing it.
67
+ *
68
+ * @see org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalLinkListSerializer#serialize(Links, JsonGenerator, SerializerProvider)
69
+ */
70
+ @ Bean
71
+ public OpenApiCustomiser linksSchemaCustomiser (RepositoryRestConfiguration repositoryRestConfiguration ) {
72
+ if (!repositoryRestConfiguration .useHalAsDefaultJsonMediaType ()) {
73
+ return openApi -> {};
74
+ }
75
+ Json .mapper ().addMixIn (RepresentationModel .class , RepresentationModelLinksOASMixin .class );
74
76
75
- return openApi -> openApi
76
- .schema ("Link" , resolvedLinkSchema .schema )
77
- .schema ("Links" , new MapSchema ()
78
- .additionalProperties (new StringSchema ())
79
- .additionalProperties (new ObjectSchema ().$ref ("#/components/schemas/Link" )));
80
- }
77
+ ResolvedSchema resolvedLinkSchema = ModelConverters .getInstance ()
78
+ .resolveAsResolvedSchema (new AnnotatedType (Link .class ));
79
+
80
+ return openApi -> openApi
81
+ .schema ("Link" , resolvedLinkSchema .schema )
82
+ .schema ("Links" , new MapSchema ()
83
+ .additionalProperties (new StringSchema ())
84
+ .additionalProperties (new ObjectSchema ().$ref ("#/components/schemas/Link" )));
85
+ }
86
+ }
81
87
}
0 commit comments