-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for externalizing strings in openapi groups
- Loading branch information
Anton Tkachenko
committed
Feb 25, 2024
1 parent
2601b3c
commit 4618041
Showing
5 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,14 @@ | |
* <li>springdoc.specification-strings.paths.{operationId}.description - to set description of {operationId}</li> | ||
* <li>springdoc.specification-strings.paths.{operationId}.summary - to set summary of {operationId}</li> | ||
* </ul> | ||
* <p> | ||
* Support for groped openapi customization is similar to the above, but with a group name prefix. | ||
* E.g. | ||
* <ul> | ||
* <li>springdoc.specification-strings.{group-name}.info.title - to set title of api-info</li> | ||
* <li>springdoc.specification-strings.{group-name}.components.User.description - to set description of User model</li> | ||
* <li>springdoc.specification-strings.{group-name}.paths.{operationId}.description - to set description of {operationId}</li> | ||
* </ul> | ||
* | ||
* @author Anton Tkachenko [email protected] | ||
*/ | ||
|
@@ -71,9 +79,16 @@ public class SpecificationStringPropertiesCustomizer implements GlobalOpenApiCus | |
private static final String SPECIFICATION_STRINGS_PREFIX = "springdoc.specification-strings."; | ||
|
||
private final PropertyResolver propertyResolver; | ||
private final String propertyPrefix; | ||
|
||
public SpecificationStringPropertiesCustomizer(PropertyResolver resolverUtils) { | ||
this.propertyResolver = resolverUtils; | ||
this.propertyPrefix = SPECIFICATION_STRINGS_PREFIX; | ||
} | ||
|
||
public SpecificationStringPropertiesCustomizer(PropertyResolver propertyResolver, String groupName) { | ||
this.propertyResolver = propertyResolver; | ||
this.propertyPrefix = SPECIFICATION_STRINGS_PREFIX + groupName + "."; | ||
} | ||
|
||
@Override | ||
|
@@ -140,7 +155,7 @@ private void setComponentsProperties(OpenAPI openApi) { | |
private void resolveString( | ||
Consumer<String> setter, String node | ||
) { | ||
String nodeWithPrefix = SPECIFICATION_STRINGS_PREFIX + node; | ||
String nodeWithPrefix = propertyPrefix + node; | ||
String value = propertyResolver.getProperty(nodeWithPrefix); | ||
if (StringUtils.isNotBlank(value)) { | ||
setter.accept(value); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...enapi-tests/springdoc-openapi-groovy-tests/src/test/resources/results/app212-grouped.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "ApiGroupName info title", | ||
"description": "ApiGroupName info description", | ||
"version": "ApiGroupName info version" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost", | ||
"description": "Generated server url" | ||
} | ||
], | ||
"paths": { | ||
"/persons": { | ||
"get": { | ||
"tags": [ | ||
"hello-controller" | ||
], | ||
"summary": "Summary of operationId 'persons' in ApiGroupName", | ||
"description": "Description of operationId 'persons' in ApiGroupName", | ||
"operationId": "persons", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": { | ||
"*/*": { | ||
"schema": { | ||
"$ref": "#/components/schemas/PersonDTO" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"PersonDTO": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Description for 'name' property in ApiGroupName", | ||
"example": "Example value for 'name' property in ApiGroupName" | ||
} | ||
}, | ||
"description": "Description for PersonDTO component in ApiGroupName" | ||
} | ||
} | ||
} | ||
} |