69
69
import io .swagger .v3 .oas .models .PathItem .HttpMethod ;
70
70
import io .swagger .v3 .oas .models .Paths ;
71
71
import io .swagger .v3 .oas .models .SpecVersion ;
72
+ import io .swagger .v3 .oas .models .media .Schema ;
72
73
import io .swagger .v3 .oas .models .media .StringSchema ;
73
74
import io .swagger .v3 .oas .models .parameters .Parameter ;
74
75
import io .swagger .v3 .oas .models .responses .ApiResponses ;
100
101
import org .springdoc .core .service .GenericResponseService ;
101
102
import org .springdoc .core .service .OpenAPIService ;
102
103
import org .springdoc .core .service .OperationService ;
104
+ import org .springdoc .core .utils .PropertyResolverUtils ;
103
105
import org .springdoc .core .utils .SpringDocUtils ;
104
106
105
107
import org .springframework .aop .support .AopUtils ;
@@ -352,6 +354,9 @@ protected OpenAPI getOpenApi(Locale locale) {
352
354
}
353
355
getPaths (mappingsMap , finalLocale , openAPI );
354
356
357
+ if (springDocConfigProperties .isTrimKotlinIndent ())
358
+ this .trimIndent (openAPI );
359
+
355
360
Optional <CloudFunctionProvider > cloudFunctionProviderOptional = springDocProviders .getSpringCloudFunctionProvider ();
356
361
cloudFunctionProviderOptional .ifPresent (cloudFunctionProvider -> {
357
362
List <RouterOperation > routerOperationList = cloudFunctionProvider .getRouterOperations (openAPI );
@@ -384,7 +389,6 @@ protected OpenAPI getOpenApi(Locale locale) {
384
389
if (!CollectionUtils .isEmpty (openAPI .getServers ()) && !openAPI .getServers ().equals (serversCopy ))
385
390
openAPIService .setServersPresent (true );
386
391
387
-
388
392
openAPIService .setCachedOpenAPI (openAPI , finalLocale );
389
393
390
394
LOGGER .info ("Init duration for springdoc-openapi is: {} ms" ,
@@ -396,12 +400,62 @@ protected OpenAPI getOpenApi(Locale locale) {
396
400
openAPIService .updateServers (openAPI );
397
401
}
398
402
openAPIService .updateServers (openAPI );
399
- return openAPI ; }
400
- finally {
403
+ return openAPI ;
404
+ } finally {
401
405
this .reentrantLock .unlock ();
402
406
}
403
407
}
404
408
409
+ private void trimIndent (OpenAPI openAPI ) {
410
+ trimComponents (openAPI );
411
+ trimPaths (openAPI );
412
+ }
413
+
414
+ private void trimComponents (OpenAPI openAPI ) {
415
+ final PropertyResolverUtils propertyResolverUtils = operationParser .getPropertyResolverUtils ();
416
+ if (openAPI .getComponents () == null || openAPI .getComponents ().getSchemas () == null ) {
417
+ return ;
418
+ }
419
+ for (Schema <?> schema : openAPI .getComponents ().getSchemas ().values ()) {
420
+ schema .description (propertyResolverUtils .trimIndent (schema .getDescription ()));
421
+ if (schema .getProperties () == null ) {
422
+ continue ;
423
+ }
424
+ for (Object prop : schema .getProperties ().values ()) {
425
+ if (prop instanceof Schema <?> schemaProp ) {
426
+ schemaProp .setDescription (propertyResolverUtils .trimIndent (schemaProp .getDescription ()));
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ private void trimPaths (OpenAPI openAPI ) {
433
+ final PropertyResolverUtils propertyResolverUtils = operationParser .getPropertyResolverUtils ();
434
+ if (openAPI .getPaths () == null ) {
435
+ return ;
436
+ }
437
+ for (PathItem value : openAPI .getPaths ().values ()) {
438
+ value .setDescription (propertyResolverUtils .trimIndent (value .getDescription ()));
439
+ trimIndentOperation (value .getGet ());
440
+ trimIndentOperation (value .getPut ());
441
+ trimIndentOperation (value .getPost ());
442
+ trimIndentOperation (value .getDelete ());
443
+ trimIndentOperation (value .getOptions ());
444
+ trimIndentOperation (value .getHead ());
445
+ trimIndentOperation (value .getPatch ());
446
+ trimIndentOperation (value .getTrace ());
447
+ }
448
+ }
449
+
450
+ private void trimIndentOperation (Operation operation ) {
451
+ final PropertyResolverUtils propertyResolverUtils = operationParser .getPropertyResolverUtils ();
452
+ if (operation == null ) {
453
+ return ;
454
+ }
455
+ operation .setSummary (propertyResolverUtils .trimIndent (operation .getSummary ()));
456
+ operation .setDescription (propertyResolverUtils .trimIndent (operation .getDescription ()));
457
+ }
458
+
405
459
/**
406
460
* Gets paths.
407
461
*
0 commit comments