Skip to content
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

Swagger fixes #14

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class OrderModelsCustomizer implements OpenApiCustomizer {
public void customise(OpenAPI openApi) {
var components = openApi.getComponents();

components.schemas(new TreeMap<>(components.getSchemas()));
if (components != null && components.getSchemas() != null) {
components.schemas(new TreeMap<>(components.getSchemas()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class NullableCustomizer implements OpenApiCustomizer {
@Override
@SuppressWarnings("unchecked")
public void customise(OpenAPI openApi) {
if (openApi.getComponents() == null || openApi.getComponents().getSchemas() == null) {
return;
}
openApi.getComponents().getSchemas().values()
.forEach(schema -> {
var requiredProperties = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.responses.ApiResponses;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.customizers.OpenApiCustomizer;

@RequiredArgsConstructor
public class LogoutCustomizer implements OpenApiCustomizer {
@NonNull
private final String logoutUrl;
@NonNull
private final String tag;

@Override
public void customise(OpenAPI openApi) {
var operation = new Operation();
operation.addTagsItem("Authentication API");
operation.addTagsItem(tag);
operation.summary("Logout the current user");
operation.operationId("logout");
operation.responses(new ApiResponses());

var pathItem = new PathItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ public class CustomTypePropertyCustomizer implements PropertyCustomizer {
public Schema<?> customize(Schema property, AnnotatedType annotatedType) {
var type = annotatedType.getType();

if (type instanceof SimpleType simpleType) {
var rawClass = simpleType.getRawClass();

// We set the enum name as the description because swagger treats each usage as a new enum.
// This way we can preserve the information about the original enum type.
if (rawClass.isEnum()) {
var displayName = rawClass.getCanonicalName().replace(rawClass.getPackage().getName() + ".", "");
property.setDescription(displayName);
}
}

if (type instanceof SimpleType simpleType && CustomType.class.isAssignableFrom(simpleType.getRawClass())) {
var rawClass = simpleType.getRawClass();

Expand Down