11package io .swagger .v3 .core .util ;
22
3+ import com .fasterxml .jackson .databind .node .IntNode ;
34import com .google .common .collect .ImmutableMap ;
45import io .swagger .v3 .oas .annotations .media .Content ;
56import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
@@ -102,6 +103,12 @@ class DummyClass implements Serializable {}
102103 static class ExampleHolder {
103104 @ io .swagger .v3 .oas .annotations .media .Schema (type = "string" , example = "5 lacs per annum" )
104105 String value ;
106+
107+ @ io .swagger .v3 .oas .annotations .media .Schema (type = "number" , example = "10" )
108+ String numberValue ;
109+
110+ @ io .swagger .v3 .oas .annotations .media .Schema (type = "integer" , example = "5" )
111+ String integerValue ;
105112 }
106113
107114 @ Test
@@ -126,4 +133,48 @@ public void testExampleStartingWithNumberShouldBeString() throws Exception {
126133 assertEquals (schema .get ().getExample (), "5 lacs per annum" );
127134 }
128135
136+ @ Test
137+ public void testExampleWithNumberTypeShouldHaveExampleAsNumber () throws Exception {
138+ io .swagger .v3 .oas .annotations .media .Schema schemaAnnotation =
139+ ExampleHolder .class
140+ .getDeclaredField ("numberValue" )
141+ .getAnnotation (io .swagger .v3 .oas .annotations .media .Schema .class );
142+
143+ Optional <Schema > schema =
144+ AnnotationsUtils .getSchemaFromAnnotation (
145+ schemaAnnotation ,
146+ null ,
147+ null ,
148+ false ,
149+ null ,
150+ Schema .SchemaResolution .DEFAULT ,
151+ null
152+ );
153+
154+ assertTrue (schema .isPresent ());
155+ assertEquals (schema .get ().getExample (), IntNode .valueOf (10 ));
156+ }
157+
158+ @ Test
159+ public void testExampleWithIntegerTypeShouldHaveExampleAsNumber () throws Exception {
160+ io .swagger .v3 .oas .annotations .media .Schema schemaAnnotation =
161+ ExampleHolder .class
162+ .getDeclaredField ("integerValue" )
163+ .getAnnotation (io .swagger .v3 .oas .annotations .media .Schema .class );
164+
165+ Optional <Schema > schema =
166+ AnnotationsUtils .getSchemaFromAnnotation (
167+ schemaAnnotation ,
168+ null ,
169+ null ,
170+ false ,
171+ null ,
172+ Schema .SchemaResolution .DEFAULT ,
173+ null
174+ );
175+
176+ assertTrue (schema .isPresent ());
177+ assertEquals (schema .get ().getExample (), IntNode .valueOf (5 ));
178+ }
179+
129180}
0 commit comments