File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
modules/swagger-codegen/src
main/java/io/swagger/codegen
test/java/io/swagger/codegen Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -219,7 +219,7 @@ public void flatten(Swagger swagger) {
219
219
private void fixStringModel (ModelImpl m ) {
220
220
if (m .getType () != null && m .getType ().equals ("string" ) && m .getExample () != null ) {
221
221
String example = m .getExample ().toString ();
222
- if (example .substring (0 , 1 ).equals ("\" " ) &&
222
+ if (! example . isEmpty () && example .substring (0 , 1 ).equals ("\" " ) &&
223
223
example .substring (example .length () - 1 ).equals ("\" " )) {
224
224
m .setExample (example .substring (1 , example .length () - 1 ));
225
225
}
Original file line number Diff line number Diff line change 5
5
import io .swagger .models .parameters .Parameter ;
6
6
import io .swagger .models .properties .*;
7
7
import io .swagger .util .Json ;
8
+ import org .apache .commons .lang3 .StringUtils ;
8
9
import org .testng .annotations .Test ;
9
10
11
+ import java .util .HashMap ;
10
12
import java .util .Map ;
11
13
12
14
import static org .testng .AssertJUnit .*;
@@ -988,5 +990,24 @@ public void testArbitraryObjectModelWithArrayInlineWithTitle() {
988
990
assertTrue (inlineProp instanceof ObjectProperty );
989
991
ObjectProperty op = (ObjectProperty ) inlineProp ;
990
992
assertNull (op .getProperties ());
991
- }
993
+ }
994
+
995
+ @ Test
996
+ public void testEmptyExampleOnStrinngTypeModels () {
997
+ Swagger swagger = new Swagger ();
998
+
999
+ RefProperty refProperty = new RefProperty ();
1000
+ refProperty .set$ref ("#/definitions/Test" );
1001
+
1002
+ swagger .path ("/hello" , new Path ()
1003
+ .get (new Operation ()
1004
+ .response (200 , new Response ()
1005
+ .schema (new ArrayProperty ()
1006
+ .items (refProperty )))));
1007
+
1008
+ swagger .addDefinition ("Test" , new ModelImpl ()
1009
+ .example (StringUtils .EMPTY )
1010
+ .type ("string" ));
1011
+ new InlineModelResolver ().flatten (swagger );
1012
+ }
992
1013
}
You can’t perform that action at this time.
0 commit comments