40
40
41
41
import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
42
42
import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
43
+ import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
44
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
43
45
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
46
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingClass ;
44
47
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
45
48
import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication ;
46
49
import org .springframework .boot .context .properties .bind .BindResult ;
@@ -68,6 +71,8 @@ public class SpringDocConfiguration {
68
71
getConfig ().replaceWithSchema (ObjectNode .class , new ObjectSchema ());
69
72
}
70
73
74
+ private final String BINDRESULT_CLASS = "org.springframework.boot.context.properties.bind.BindResult" ;
75
+
71
76
@ Bean
72
77
LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer () {
73
78
return new LocalVariableTableParameterNameDiscoverer ();
@@ -158,6 +163,7 @@ OpenApiCustomiser propertiesResolverForSchema(PropertyResolverUtils propertyReso
158
163
159
164
@ Bean
160
165
@ Conditional (CacheOrGroupedOpenApiCondition .class )
166
+ @ ConditionalOnClass (name = BINDRESULT_CLASS )
161
167
@ Lazy (false )
162
168
BeanFactoryPostProcessor springdocBeanFactoryPostProcessor (Environment environment ) {
163
169
return beanFactory -> {
@@ -177,10 +183,23 @@ BeanFactoryPostProcessor springdocBeanFactoryPostProcessor(Environment environme
177
183
.collect (Collectors .toList ());
178
184
groupedOpenApis .forEach (elt -> beanFactory .registerSingleton (elt .getGroup (), elt ));
179
185
}
180
- for (String beanName : beanFactory .getBeanNamesForType (OpenAPIBuilder .class ))
181
- beanFactory .getBeanDefinition (beanName ).setScope (SCOPE_PROTOTYPE );
182
- for (String beanName : beanFactory .getBeanNamesForType (OpenAPI .class ))
183
- beanFactory .getBeanDefinition (beanName ).setScope (SCOPE_PROTOTYPE );
186
+ initBeanFactoryPostProcessor (beanFactory );
184
187
};
185
188
}
189
+
190
+ // For spring-boot-1 compatibility
191
+ @ Bean
192
+ @ Conditional (CacheOrGroupedOpenApiCondition .class )
193
+ @ ConditionalOnMissingClass (value = BINDRESULT_CLASS )
194
+ @ Lazy (false )
195
+ BeanFactoryPostProcessor springdocBeanFactoryPostProcessor2 (Environment environment ) {
196
+ return beanFactory -> initBeanFactoryPostProcessor (beanFactory );
197
+ }
198
+
199
+ private void initBeanFactoryPostProcessor (ConfigurableListableBeanFactory beanFactory ) {
200
+ for (String beanName : beanFactory .getBeanNamesForType (OpenAPIBuilder .class ))
201
+ beanFactory .getBeanDefinition (beanName ).setScope (SCOPE_PROTOTYPE );
202
+ for (String beanName : beanFactory .getBeanNamesForType (OpenAPI .class ))
203
+ beanFactory .getBeanDefinition (beanName ).setScope (SCOPE_PROTOTYPE );
204
+ }
186
205
}
0 commit comments