Skip to content

Commit

Permalink
fix some swagger issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SirCotare committed Oct 30, 2024
1 parent 6c4c09e commit f13285f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
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

0 comments on commit f13285f

Please sign in to comment.