Skip to content

Commit

Permalink
set schema name for EnumTypes
Browse files Browse the repository at this point in the history
Co-authored-by: Timon Back <[email protected]>
  • Loading branch information
sam0r040 and timonback committed Aug 30, 2024
1 parent ed6be13 commit 5ee9cef
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context

if (model == null && type.isEnumType()) {
model = new StringSchema();
model.setName(name);
_addEnumProps(type.getRawClass(), model);
isPrimitive = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.core.oas.models.Cat;
Expand Down Expand Up @@ -231,7 +232,7 @@ public void overridePropertyName() {
@Test(description = "it should convert a model with enum array")
public void convertModelWithEnumArray() {
final Map<String, Schema> schemas = readAll(ModelWithEnumArray.class);
assertEquals(schemas.size(), 1);
assertEquals(schemas.keySet(), Sets.newHashSet("ModelWithEnumArray", "Action"));
}

private Type getGenericType(Class<?> cls) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import io.swagger.v3.core.resolving.v31.model.AnnotatedArray;
import io.swagger.v3.core.resolving.v31.model.ModelWithDependentSchema;
import io.swagger.v3.core.resolving.v31.model.ModelWithOAS31Stuff;
import io.swagger.v3.core.resolving.v31.model.ModelWithOAS31StuffMinimal;
import io.swagger.v3.core.util.Yaml31;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -69,6 +67,11 @@ public void testOAS31Fields() {
" creditCard:\n" +
" type: integer\n" +
" format: int32\n" +
"CountryEnum:\n" +
" type: string\n" +
" enum:\n" +
" - UNITED_STATES_OF_AMERICA\n" +
" - CANADA\n" +
"CreditCard:\n" +
" properties:\n" +
" billingAddress:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ public void testEnum() throws IOException {
"components:\n" +
" schemas:\n" +
" TaskDTO:\n" +
" type: object\n";
}
" type: object\n" +
" TaskType:\n" +
" type: string\n" +
" enum:\n" +
" - A\n" +
" - B";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.swagger.v3.jaxrs2;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverter;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
Expand All @@ -15,32 +14,22 @@
import io.swagger.v3.jaxrs2.matchers.SerializationMatchers;
import io.swagger.v3.jaxrs2.petstore31.PetResource;
import io.swagger.v3.jaxrs2.petstore31.TagResource;
import io.swagger.v3.jaxrs2.resources.DefaultResponseResource;
import io.swagger.v3.jaxrs2.resources.Misc31Resource;
import io.swagger.v3.jaxrs2.resources.ParameterMaximumValueResource;
import io.swagger.v3.jaxrs2.resources.ResponseReturnTypeResource;
import io.swagger.v3.jaxrs2.resources.SchemaAdditionalPropertiesResource;
import io.swagger.v3.jaxrs2.resources.SchemaPropertiesResource;
import io.swagger.v3.jaxrs2.resources.SiblingPropResource;
import io.swagger.v3.jaxrs2.resources.SiblingsResource;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBody;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBodyMultiple;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceResponse;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceSimple;
import io.swagger.v3.jaxrs2.resources.SingleExampleResource;
import io.swagger.v3.jaxrs2.resources.BasicFieldsResource;
import io.swagger.v3.jaxrs2.resources.BookStoreTicket2646;
import io.swagger.v3.jaxrs2.resources.ClassPathParentResource;
import io.swagger.v3.jaxrs2.resources.ClassPathSubResource;
import io.swagger.v3.jaxrs2.resources.CompleteFieldsResource;
import io.swagger.v3.jaxrs2.resources.DefaultResponseResource;
import io.swagger.v3.jaxrs2.resources.DeprecatedFieldsResource;
import io.swagger.v3.jaxrs2.resources.DuplicatedOperationIdResource;
import io.swagger.v3.jaxrs2.resources.DuplicatedOperationMethodNameResource;
import io.swagger.v3.jaxrs2.resources.DuplicatedSecurityResource;
import io.swagger.v3.jaxrs2.resources.EnhancedResponsesResource;
import io.swagger.v3.jaxrs2.resources.ExternalDocsReference;
import io.swagger.v3.jaxrs2.resources.Misc31Resource;
import io.swagger.v3.jaxrs2.resources.MyClass;
import io.swagger.v3.jaxrs2.resources.MyOtherClass;
import io.swagger.v3.jaxrs2.resources.ParameterMaximumValueResource;
import io.swagger.v3.jaxrs2.resources.RefCallbackResource;
import io.swagger.v3.jaxrs2.resources.RefExamplesResource;
import io.swagger.v3.jaxrs2.resources.RefHeaderResource;
Expand All @@ -53,15 +42,25 @@
import io.swagger.v3.jaxrs2.resources.RefSecurityResource;
import io.swagger.v3.jaxrs2.resources.ResourceWithSubResource;
import io.swagger.v3.jaxrs2.resources.ResponseContentWithArrayResource;
import io.swagger.v3.jaxrs2.resources.ResponseReturnTypeResource;
import io.swagger.v3.jaxrs2.resources.ResponsesResource;
import io.swagger.v3.jaxrs2.resources.SchemaAdditionalPropertiesResource;
import io.swagger.v3.jaxrs2.resources.SchemaPropertiesResource;
import io.swagger.v3.jaxrs2.resources.SecurityResource;
import io.swagger.v3.jaxrs2.resources.ServersResource;
import io.swagger.v3.jaxrs2.resources.SiblingPropResource;
import io.swagger.v3.jaxrs2.resources.SiblingsResource;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBody;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceRequestBodyMultiple;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceResponse;
import io.swagger.v3.jaxrs2.resources.SiblingsResourceSimple;
import io.swagger.v3.jaxrs2.resources.SimpleCallbackResource;
import io.swagger.v3.jaxrs2.resources.SimpleExamplesResource;
import io.swagger.v3.jaxrs2.resources.SimpleMethods;
import io.swagger.v3.jaxrs2.resources.SimpleParameterResource;
import io.swagger.v3.jaxrs2.resources.SimpleRequestBodyResource;
import io.swagger.v3.jaxrs2.resources.SimpleResponsesResource;
import io.swagger.v3.jaxrs2.resources.SingleExampleResource;
import io.swagger.v3.jaxrs2.resources.SubResourceHead;
import io.swagger.v3.jaxrs2.resources.TagsResource;
import io.swagger.v3.jaxrs2.resources.Test2607;
Expand Down Expand Up @@ -143,9 +142,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
Expand Down Expand Up @@ -3985,6 +3982,11 @@ public void testMisc31() {
" properties:\n" +
" country:\n" +
" const: United States\n" +
" CountryEnum:\n" +
" type: string\n" +
" enum:\n" +
" - United States of America\n" +
" - Canada\n" +
" CreditCard:\n" +
" properties:\n" +
" billingAddress:\n" +
Expand Down

0 comments on commit 5ee9cef

Please sign in to comment.