-
Notifications
You must be signed in to change notification settings - Fork 0
update swagger tooling for code generator #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b2ea25
update swagger tooling for code generator
SirCotare 6e9447a
remove old annotation
SirCotare c8672bd
rename test support package
SirCotare 806e690
update deps
SirCotare 7981fba
remove comment
SirCotare 3885bff
extract common function to util
SirCotare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
19 changes: 0 additions & 19 deletions
19
...boutbits/springboot/toolbox/autoconfiguration/swagger/RegisterCustomTypesWithSwagger.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
12 changes: 0 additions & 12 deletions
12
src/main/java/it/aboutbits/springboot/toolbox/swagger/annotations/SwaggerScopedAuth.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
.../springboot/toolbox/swagger/customization/authorization_docs/AuthorizationDescriptor.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...wagger/type/CustomTypeModelConverter.java → ...custom_type/CustomTypeModelConverter.java
This file contains hidden or 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
...oolbox/swagger/customization/custom_type/CustomTypeOpenApiCustomizerForCodeGenerator.java
This file contains hidden or 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 @@ | ||
| package it.aboutbits.springboot.toolbox.swagger.customization.custom_type; | ||
|
|
||
| import io.swagger.v3.oas.models.OpenAPI; | ||
| import io.swagger.v3.oas.models.media.Schema; | ||
| import it.aboutbits.springboot.toolbox.swagger.SwaggerMetaUtil; | ||
| import it.aboutbits.springboot.toolbox.type.CustomType; | ||
| import it.aboutbits.springboot.toolbox.type.identity.EntityId; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springdoc.core.customizers.OpenApiCustomizer; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @Slf4j | ||
| public class CustomTypeOpenApiCustomizerForCodeGenerator implements OpenApiCustomizer { | ||
| @Override | ||
| public void customise(OpenAPI openApi) { | ||
| openApi.getComponents().getSchemas().forEach(this::updateSchema); | ||
| } | ||
|
|
||
| public Optional<Class<?>> getClassFromSchemaReference(String schemaRef) { | ||
| try { | ||
| var className = schemaRef.replace("#/components/schemas/", ""); | ||
| return Optional.of(Class.forName(className)); | ||
| } catch (ClassNotFoundException e) { | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
|
|
||
| private void updateSchema(String fqn, Schema<?> schema) { | ||
| var type = getClassFromSchemaReference(fqn); | ||
|
|
||
| if (type.isEmpty()) { | ||
| log.debug("Can not resolve type for schema reference: {}", fqn); | ||
| return; | ||
| } | ||
|
|
||
| var clazz = type.get(); | ||
|
|
||
| if (CustomType.class.isAssignableFrom(clazz)) { | ||
|
|
||
| var isIdentity = EntityId.class.isAssignableFrom(clazz); | ||
|
|
||
| var description = SwaggerMetaUtil.setOriginalTypeFqn( | ||
| schema.getDescription(), | ||
| fqn | ||
| ); | ||
| description = SwaggerMetaUtil.setIsIdentity(description, isIdentity); | ||
| description = SwaggerMetaUtil.setIsCustomType(description, true); | ||
| schema.setDescription(description); | ||
| } | ||
|
|
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is duplicated across multiple customizer classes. Consider extracting it to a shared utility class to reduce code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find!