2
2
3
3
4
4
5
- import io .swagger .v3 .core .util .Yaml ;
5
+ import static org .testng .AssertJUnit .assertEquals ;
6
+ import static org .testng .AssertJUnit .assertNotNull ;
7
+ import static org .testng .AssertJUnit .assertNull ;
8
+ import static org .testng .AssertJUnit .assertTrue ;
9
+
10
+ import java .math .BigDecimal ;
11
+ import java .util .ArrayList ;
12
+ import java .util .HashMap ;
13
+ import java .util .LinkedList ;
14
+ import java .util .List ;
15
+ import java .util .Map ;
16
+
17
+ import org .testng .annotations .Test ;
18
+
6
19
import io .swagger .v3 .oas .models .Components ;
7
20
import io .swagger .v3 .oas .models .OpenAPI ;
8
21
import io .swagger .v3 .oas .models .Operation ;
20
33
import io .swagger .v3 .oas .models .responses .ApiResponses ;
21
34
import io .swagger .v3 .parser .OpenAPIV3Parser ;
22
35
import io .swagger .v3 .parser .core .models .ParseOptions ;
23
- import org .testng .annotations .Test ;
24
-
25
-
26
- import java .util .ArrayList ;
27
- import java .util .HashMap ;
28
- import java .util .LinkedList ;
29
- import java .util .List ;
30
- import java .util .Map ;
31
36
32
- import static org .testng .AssertJUnit .*;
33
-
34
- @ SuppressWarnings ("static-method" )
37
+ @ SuppressWarnings ({"static-method" , "rawtypes" })
35
38
public class InlineModelResolverTest {
36
39
37
40
@ Test
@@ -476,7 +479,7 @@ public void testSkipInlineMatchesFalse() {
476
479
assertNotNull (openAPI );
477
480
assertNotNull (openAPI .getComponents ());
478
481
assertNotNull (openAPI .getComponents ().getSchemas ());
479
- assertEquals (4 , openAPI .getComponents ().getSchemas ().size ());
482
+ assertEquals (openAPI .getComponents ().getSchemas ().size (), 6 );
480
483
}
481
484
482
485
@ Test
@@ -1334,7 +1337,7 @@ public void testArbitraryObjectModelWithArrayInlineWithTitle() {
1334
1337
}
1335
1338
1336
1339
1337
- @ Test (description = "https://github.com/swagger-api/swagger-parser/issues/1200 " )
1340
+ @ Test (description = "https://github.com/swagger-api/swagger-parser/issues/1527 " )
1338
1341
public void testInlineItemsSchema () throws Exception {
1339
1342
ParseOptions options = new ParseOptions ();
1340
1343
options .setFlatten (true );
@@ -1343,4 +1346,76 @@ public void testInlineItemsSchema() throws Exception {
1343
1346
assertNotNull (openAPI );
1344
1347
assertNotNull (openAPI .getComponents ().getSchemas ().get ("inline_response_200" ));
1345
1348
}
1349
+
1350
+ @ Test (description = "https://github.com/swagger-api/swagger-parser/issues/1200" )
1351
+ public void testSchemaPropertiesBeingPassedToFlattenedModel () {
1352
+ OpenAPI openAPI = new OpenAPI ();
1353
+ openAPI .setComponents (new Components ());
1354
+
1355
+ Schema address = new ObjectSchema ();
1356
+ address .setDeprecated (false );
1357
+ address .setDescription ("My address" );
1358
+ address .setExclusiveMaximum (true );
1359
+ address .setExclusiveMinimum (true );
1360
+ address .setFormat ("format" );
1361
+ address .setMinLength (Integer .getInteger ("10" ));
1362
+ address .setMaximum (BigDecimal .valueOf (50 ));
1363
+ address .setMaxItems (Integer .getInteger ("1" ));
1364
+ address .setMaxLength (Integer .getInteger ("100" ));
1365
+ address .setMaxProperties (Integer .getInteger ("1" ));
1366
+ address .setMinimum (BigDecimal .ZERO );
1367
+ address .setMinItems (Integer .getInteger ("0" ));
1368
+ address .setMinLength (Integer .getInteger ("10" ));
1369
+ address .setMinProperties (Integer .getInteger ("0" ));
1370
+ address .setMultipleOf (BigDecimal .valueOf (2 ));
1371
+ address .setName ("Address" );
1372
+ address .setNullable (true );
1373
+ address .setPattern ("%dd" );
1374
+ address .setReadOnly (false );
1375
+ address .setTitle ("my address" );
1376
+ address .setUniqueItems (true );
1377
+ address .setWriteOnly (false );
1378
+ address .addProperties ("city" , new StringSchema ());
1379
+
1380
+
1381
+ Schema user = new ObjectSchema ();
1382
+ user .setTitle ("InnerUserTitle" );
1383
+ user .setDefault ("default" );
1384
+ user .setReadOnly (false );
1385
+ user .setDescription ("user description" );
1386
+ user .setName ("user name" );
1387
+ user .addProperties ("address" , address );
1388
+
1389
+ openAPI .getComponents ().addSchemas ("User" , user );
1390
+
1391
+ new InlineModelResolver (true , true ).flatten (openAPI );
1392
+
1393
+ Schema model = openAPI .getComponents ().getSchemas ().get ("User" );
1394
+ assertTrue (model instanceof ObjectSchema );
1395
+
1396
+ Schema userAddress = openAPI .getComponents ().getSchemas ().get ("MyAddress" );
1397
+ assertNotNull (userAddress );
1398
+ assertEquals (userAddress .getDeprecated (), Boolean .FALSE );
1399
+ assertEquals (userAddress .getDescription (), "My address" );
1400
+ assertEquals (userAddress .getExclusiveMaximum (), Boolean .TRUE );
1401
+ assertEquals (userAddress .getExclusiveMinimum (), Boolean .TRUE );
1402
+ assertEquals (userAddress .getFormat (), "format" );
1403
+ assertEquals (userAddress .getMaximum (), BigDecimal .valueOf (50 ));
1404
+ assertEquals (userAddress .getMaxItems (), Integer .getInteger ("1" ));
1405
+ assertEquals (userAddress .getMaxLength (), Integer .getInteger ("100" ));
1406
+ assertEquals (userAddress .getMaxProperties (), Integer .getInteger ("1" ));
1407
+ assertEquals (userAddress .getMinimum (), BigDecimal .ZERO );
1408
+ assertEquals (userAddress .getMinItems (), Integer .getInteger ("1" ));
1409
+ assertEquals (userAddress .getMinLength (), Integer .getInteger ("100" ));
1410
+ assertEquals (userAddress .getMinProperties (), Integer .getInteger ("0" ));
1411
+ assertEquals (userAddress .getMultipleOf (), BigDecimal .valueOf (2 ));
1412
+ assertEquals (userAddress .getName (), "Address" );
1413
+ assertEquals (userAddress .getNullable (), Boolean .TRUE );
1414
+ assertEquals (userAddress .getPattern (), "%dd" );
1415
+ assertEquals (userAddress .getReadOnly (), Boolean .FALSE );
1416
+ assertEquals (userAddress .getTitle (), "my address" );
1417
+ assertEquals (userAddress .getUniqueItems (), Boolean .TRUE );
1418
+ assertEquals (userAddress .getWriteOnly (), Boolean .FALSE );
1419
+
1420
+ }
1346
1421
}
0 commit comments