Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5ee9cef

Browse files
sam0r040timonback
andcommittedAug 30, 2024·
set schema name for EnumTypes
Co-authored-by: Timon Back <[email protected]>
1 parent ed6be13 commit 5ee9cef

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed
 

‎modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
305305

306306
if (model == null && type.isEnumType()) {
307307
model = new StringSchema();
308+
model.setName(name);
308309
_addEnumProps(type.getRawClass(), model);
309310
isPrimitive = true;
310311
}

‎modules/swagger-core/src/test/java/io/swagger/v3/core/converting/ModelConverterTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
55
import com.google.common.collect.ImmutableSet;
6+
import com.google.common.collect.Sets;
67
import io.swagger.v3.core.converter.ModelConverters;
78
import io.swagger.v3.core.matchers.SerializationMatchers;
89
import io.swagger.v3.core.oas.models.Cat;
@@ -231,7 +232,7 @@ public void overridePropertyName() {
231232
@Test(description = "it should convert a model with enum array")
232233
public void convertModelWithEnumArray() {
233234
final Map<String, Schema> schemas = readAll(ModelWithEnumArray.class);
234-
assertEquals(schemas.size(), 1);
235+
assertEquals(schemas.keySet(), Sets.newHashSet("ModelWithEnumArray", "Action"));
235236
}
236237

237238
private Type getGenericType(Class<?> cls) throws Exception {

‎modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/v31/ModelResolverOAS31Test.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import io.swagger.v3.core.resolving.v31.model.AnnotatedArray;
99
import io.swagger.v3.core.resolving.v31.model.ModelWithDependentSchema;
1010
import io.swagger.v3.core.resolving.v31.model.ModelWithOAS31Stuff;
11-
import io.swagger.v3.core.resolving.v31.model.ModelWithOAS31StuffMinimal;
12-
import io.swagger.v3.core.util.Yaml31;
1311
import io.swagger.v3.oas.models.media.Schema;
1412
import org.testng.annotations.Test;
1513

@@ -69,6 +67,11 @@ public void testOAS31Fields() {
6967
" creditCard:\n" +
7068
" type: integer\n" +
7169
" format: int32\n" +
70+
"CountryEnum:\n" +
71+
" type: string\n" +
72+
" enum:\n" +
73+
" - UNITED_STATES_OF_AMERICA\n" +
74+
" - CANADA\n" +
7275
"CreditCard:\n" +
7376
" properties:\n" +
7477
" billingAddress:\n" +

‎modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/EnumTest.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@ public void testEnum() throws IOException {
4848
"components:\n" +
4949
" schemas:\n" +
5050
" TaskDTO:\n" +
51-
" type: object\n";
52-
}
51+
" type: object\n" +
52+
" TaskType:\n" +
53+
" type: string\n" +
54+
" enum:\n" +
55+
" - A\n" +
56+
" - B";
57+
}

‎modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.swagger.v3.jaxrs2;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
54
import io.swagger.v3.core.converter.AnnotatedType;
65
import io.swagger.v3.core.converter.ModelConverter;
76
import io.swagger.v3.core.converter.ModelConverterContextImpl;
@@ -15,32 +14,22 @@
1514
import io.swagger.v3.jaxrs2.matchers.SerializationMatchers;
1615
import io.swagger.v3.jaxrs2.petstore31.PetResource;
1716
import io.swagger.v3.jaxrs2.petstore31.TagResource;
18-
import io.swagger.v3.jaxrs2.resources.DefaultResponseResource;
19-
import io.swagger.v3.jaxrs2.resources.Misc31Resource;
20-
import io.swagger.v3.jaxrs2.resources.ParameterMaximumValueResource;
21-
import io.swagger.v3.jaxrs2.resources.ResponseReturnTypeResource;
22-
import io.swagger.v3.jaxrs2.resources.SchemaAdditionalPropertiesResource;
23-
import io.swagger.v3.jaxrs2.resources.SchemaPropertiesResource;
24-
import io.swagger.v3.jaxrs2.resources.SiblingPropResource;
25-
import io.swagger.v3.jaxrs2.resources.SiblingsResource;
26-
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBody;
27-
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBodyMultiple;
28-
import io.swagger.v3.jaxrs2.resources.SiblingsResourceResponse;
29-
import io.swagger.v3.jaxrs2.resources.SiblingsResourceSimple;
30-
import io.swagger.v3.jaxrs2.resources.SingleExampleResource;
3117
import io.swagger.v3.jaxrs2.resources.BasicFieldsResource;
3218
import io.swagger.v3.jaxrs2.resources.BookStoreTicket2646;
3319
import io.swagger.v3.jaxrs2.resources.ClassPathParentResource;
3420
import io.swagger.v3.jaxrs2.resources.ClassPathSubResource;
3521
import io.swagger.v3.jaxrs2.resources.CompleteFieldsResource;
22+
import io.swagger.v3.jaxrs2.resources.DefaultResponseResource;
3623
import io.swagger.v3.jaxrs2.resources.DeprecatedFieldsResource;
3724
import io.swagger.v3.jaxrs2.resources.DuplicatedOperationIdResource;
3825
import io.swagger.v3.jaxrs2.resources.DuplicatedOperationMethodNameResource;
3926
import io.swagger.v3.jaxrs2.resources.DuplicatedSecurityResource;
4027
import io.swagger.v3.jaxrs2.resources.EnhancedResponsesResource;
4128
import io.swagger.v3.jaxrs2.resources.ExternalDocsReference;
29+
import io.swagger.v3.jaxrs2.resources.Misc31Resource;
4230
import io.swagger.v3.jaxrs2.resources.MyClass;
4331
import io.swagger.v3.jaxrs2.resources.MyOtherClass;
32+
import io.swagger.v3.jaxrs2.resources.ParameterMaximumValueResource;
4433
import io.swagger.v3.jaxrs2.resources.RefCallbackResource;
4534
import io.swagger.v3.jaxrs2.resources.RefExamplesResource;
4635
import io.swagger.v3.jaxrs2.resources.RefHeaderResource;
@@ -53,15 +42,25 @@
5342
import io.swagger.v3.jaxrs2.resources.RefSecurityResource;
5443
import io.swagger.v3.jaxrs2.resources.ResourceWithSubResource;
5544
import io.swagger.v3.jaxrs2.resources.ResponseContentWithArrayResource;
45+
import io.swagger.v3.jaxrs2.resources.ResponseReturnTypeResource;
5646
import io.swagger.v3.jaxrs2.resources.ResponsesResource;
47+
import io.swagger.v3.jaxrs2.resources.SchemaAdditionalPropertiesResource;
48+
import io.swagger.v3.jaxrs2.resources.SchemaPropertiesResource;
5749
import io.swagger.v3.jaxrs2.resources.SecurityResource;
5850
import io.swagger.v3.jaxrs2.resources.ServersResource;
51+
import io.swagger.v3.jaxrs2.resources.SiblingPropResource;
52+
import io.swagger.v3.jaxrs2.resources.SiblingsResource;
53+
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBody;
54+
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBodyMultiple;
55+
import io.swagger.v3.jaxrs2.resources.SiblingsResourceResponse;
56+
import io.swagger.v3.jaxrs2.resources.SiblingsResourceSimple;
5957
import io.swagger.v3.jaxrs2.resources.SimpleCallbackResource;
6058
import io.swagger.v3.jaxrs2.resources.SimpleExamplesResource;
6159
import io.swagger.v3.jaxrs2.resources.SimpleMethods;
6260
import io.swagger.v3.jaxrs2.resources.SimpleParameterResource;
6361
import io.swagger.v3.jaxrs2.resources.SimpleRequestBodyResource;
6462
import io.swagger.v3.jaxrs2.resources.SimpleResponsesResource;
63+
import io.swagger.v3.jaxrs2.resources.SingleExampleResource;
6564
import io.swagger.v3.jaxrs2.resources.SubResourceHead;
6665
import io.swagger.v3.jaxrs2.resources.TagsResource;
6766
import io.swagger.v3.jaxrs2.resources.Test2607;
@@ -143,9 +142,7 @@
143142
import java.util.Optional;
144143
import java.util.Set;
145144
import java.util.concurrent.CompletableFuture;
146-
import java.util.concurrent.CompletionStage;
147145
import java.util.concurrent.CopyOnWriteArrayList;
148-
import java.util.stream.Collectors;
149146

150147
import static org.testng.Assert.assertEquals;
151148
import static org.testng.Assert.assertFalse;
@@ -3985,6 +3982,11 @@ public void testMisc31() {
39853982
" properties:\n" +
39863983
" country:\n" +
39873984
" const: United States\n" +
3985+
" CountryEnum:\n" +
3986+
" type: string\n" +
3987+
" enum:\n" +
3988+
" - United States of America\n" +
3989+
" - Canada\n" +
39883990
" CreditCard:\n" +
39893991
" properties:\n" +
39903992
" billingAddress:\n" +

0 commit comments

Comments
 (0)