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

Fix for #4362 - Resolving Schema for system enums fails if enumsAsRef is enabled #4364

Merged
merged 1 commit into from
Feb 19, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
if (!annotatedType.isSkipSchemaName() && resolvedSchemaAnnotation != null && !resolvedSchemaAnnotation.name().isEmpty()) {
name = resolvedSchemaAnnotation.name();
}
if (StringUtils.isBlank(name) && !ReflectionUtils.isSystemType(type)) {
if (StringUtils.isBlank(name) && (type.isEnumType() || !ReflectionUtils.isSystemType(type))) {
name = _typeName(type, beanDesc);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.swagger.v3.core.resolving;

import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import java.time.DayOfWeek;

public class Ticket4362Test extends SwaggerTestBase {

@AfterMethod
public void afterTest() {
ModelResolver.enumsAsRef = false;
}

@Test
public void testAnyOf() throws Exception {
ModelResolver.enumsAsRef = true;

final ModelResolver modelResolver = new ModelResolver(mapper());

final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

final Schema model = context
.resolve(new AnnotatedType(DayOfWeek.class));

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "DayOfWeek:\n" +
" type: string\n" +
" enum:\n" +
" - MONDAY\n" +
" - TUESDAY\n" +
" - WEDNESDAY\n" +
" - THURSDAY\n" +
" - FRIDAY\n" +
" - SATURDAY\n" +
" - SUNDAY");
}

}