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,78 @@ 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
+ /**
410
+ * Indents are removed for properties that are mainly used as “explanations” using Open API.
411
+ * @param openAPI the open api
412
+ */
413
+ private void trimIndent (OpenAPI openAPI ) {
414
+ trimComponents (openAPI );
415
+ trimPaths (openAPI );
416
+ }
417
+
418
+ /**
419
+ * Trim the indent for descriptions in the 'components' of open api.
420
+ * @param openAPI the open api
421
+ */
422
+ private void trimComponents (OpenAPI openAPI ) {
423
+ final PropertyResolverUtils propertyResolverUtils = operationParser .getPropertyResolverUtils ();
424
+ if (openAPI .getComponents () == null || openAPI .getComponents ().getSchemas () == null ) {
425
+ return ;
426
+ }
427
+ for (Schema <?> schema : openAPI .getComponents ().getSchemas ().values ()) {
428
+ schema .description (propertyResolverUtils .trimIndent (schema .getDescription ()));
429
+ if (schema .getProperties () == null ) {
430
+ continue ;
431
+ }
432
+ for (Object prop : schema .getProperties ().values ()) {
433
+ if (prop instanceof Schema <?> schemaProp ) {
434
+ schemaProp .setDescription (propertyResolverUtils .trimIndent (schemaProp .getDescription ()));
435
+ }
436
+ }
437
+ }
438
+ }
439
+
440
+ /**
441
+ * Trim the indent for descriptions in the 'paths' of open api.
442
+ * @param openAPI the open api
443
+ */
444
+ private void trimPaths (OpenAPI openAPI ) {
445
+ final PropertyResolverUtils propertyResolverUtils = operationParser .getPropertyResolverUtils ();
446
+ if (openAPI .getPaths () == null ) {
447
+ return ;
448
+ }
449
+ for (PathItem value : openAPI .getPaths ().values ()) {
450
+ value .setDescription (propertyResolverUtils .trimIndent (value .getDescription ()));
451
+ trimIndentOperation (value .getGet ());
452
+ trimIndentOperation (value .getPut ());
453
+ trimIndentOperation (value .getPost ());
454
+ trimIndentOperation (value .getDelete ());
455
+ trimIndentOperation (value .getOptions ());
456
+ trimIndentOperation (value .getHead ());
457
+ trimIndentOperation (value .getPatch ());
458
+ trimIndentOperation (value .getTrace ());
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Trim the indent for 'operation'
464
+ * @param operation the operation
465
+ */
466
+ private void trimIndentOperation (Operation operation ) {
467
+ final PropertyResolverUtils propertyResolverUtils = operationParser .getPropertyResolverUtils ();
468
+ if (operation == null ) {
469
+ return ;
470
+ }
471
+ operation .setSummary (propertyResolverUtils .trimIndent (operation .getSummary ()));
472
+ operation .setDescription (propertyResolverUtils .trimIndent (operation .getDescription ()));
473
+ }
474
+
405
475
/**
406
476
* Gets paths.
407
477
*
0 commit comments