Skip to content

Commit

Permalink
Fix for #4362 - Resolving Schema for system enums fails if enumsAsRef…
Browse files Browse the repository at this point in the history
… is enabled
  • Loading branch information
Martin Dendis authored and frantuma committed Feb 19, 2023
1 parent 0543bda commit b842b6d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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");
}

}

0 comments on commit b842b6d

Please sign in to comment.