@@ -11,6 +11,7 @@ describe('fromOpticConfig', () => {
1111 expect ( out )
1212 . toEqual ( `- ruleset/breaking-changes/exclude_operations_with_extension must be string
1313- ruleset/breaking-changes/exclude_operations_with_extension must be array
14+ - ruleset/breaking-changes/exclude_operations_with_extension must be array
1415- ruleset/breaking-changes/exclude_operations_with_extension must match exactly one schema in oneOf` ) ;
1516 } ) ;
1617
@@ -34,6 +35,18 @@ describe('fromOpticConfig', () => {
3435 expect ( out ) . toBeInstanceOf ( BreakingChangesRuleset ) ;
3536 } ) ;
3637
38+ test ( 'valid config with exclude_operations_with_extension as object' , async ( ) => {
39+ const out = await BreakingChangesRuleset . fromOpticConfig ( {
40+ exclude_operations_with_extension : [
41+ {
42+ 'x-stability' : [ 'beta' , 'alpha' , 'draft' ] ,
43+ } ,
44+ ] ,
45+ } ) ;
46+
47+ expect ( out ) . toBeInstanceOf ( BreakingChangesRuleset ) ;
48+ } ) ;
49+
3750 test ( 'does not throw breaking change if semvar has updated' , async ( ) => {
3851 const out = await BreakingChangesRuleset . fromOpticConfig ( {
3952 skip_when_major_version_changes : true ,
@@ -1234,7 +1247,7 @@ describe('breaking changes ruleset', () => {
12341247} ) ;
12351248
12361249describe ( 'breaking change ruleset configuration' , ( ) => {
1237- test ( 'breaking changes applies a matches function' , async ( ) => {
1250+ test ( 'breaking changes applies a matches function for string extension ' , async ( ) => {
12381251 const beforeJson : OpenAPIV3 . Document = {
12391252 ...TestHelpers . createEmptySpec ( ) ,
12401253 paths : {
@@ -1261,13 +1274,129 @@ describe('breaking change ruleset configuration', () => {
12611274 } ;
12621275 const results = await TestHelpers . runRulesWithInputs (
12631276 [
1264- BreakingChangesRuleset . fromOpticConfig ( {
1277+ await BreakingChangesRuleset . fromOpticConfig ( {
12651278 exclude_operations_with_extension : 'x-legacy' ,
12661279 } ) as any ,
12671280 ] ,
12681281 beforeJson ,
12691282 afterJson
12701283 ) ;
1271- expect ( results . length === 0 ) . toBe ( true ) ;
1284+ expect ( results . length ) . toBe ( 0 ) ;
1285+ } ) ;
1286+
1287+ test ( 'breaking changes applies a matches function for object extension value match' , async ( ) => {
1288+ const beforeJson : OpenAPIV3 . Document = {
1289+ ...TestHelpers . createEmptySpec ( ) ,
1290+ paths : {
1291+ '/api/users' : {
1292+ get : {
1293+ responses : { } ,
1294+ } ,
1295+ post : {
1296+ 'x-stability-level' : 'draft' ,
1297+ responses : { } ,
1298+ } as any ,
1299+ } ,
1300+ } ,
1301+ } ;
1302+ const afterJson : OpenAPIV3 . Document = {
1303+ ...TestHelpers . createEmptySpec ( ) ,
1304+ paths : {
1305+ '/api/users' : {
1306+ get : {
1307+ responses : { } ,
1308+ } ,
1309+ } ,
1310+ } ,
1311+ } ;
1312+ const results = await TestHelpers . runRulesWithInputs (
1313+ [
1314+ await BreakingChangesRuleset . fromOpticConfig ( {
1315+ exclude_operations_with_extension : [
1316+ { 'x-stability-level' : [ 'draft' ] } ,
1317+ ] ,
1318+ } ) as any ,
1319+ ] ,
1320+ beforeJson ,
1321+ afterJson
1322+ ) ;
1323+ expect ( results . length ) . toBe ( 0 )
1324+ } ) ;
1325+
1326+ test ( 'breaking changes applies a matches function for object extension value mismatch' , async ( ) => {
1327+ const beforeJson : OpenAPIV3 . Document = {
1328+ ...TestHelpers . createEmptySpec ( ) ,
1329+ paths : {
1330+ '/api/users' : {
1331+ get : {
1332+ responses : { } ,
1333+ } ,
1334+ post : {
1335+ 'x-stability-level' : 'stable' ,
1336+ responses : { } ,
1337+ } as any ,
1338+ } ,
1339+ } ,
1340+ } ;
1341+ const afterJson : OpenAPIV3 . Document = {
1342+ ...TestHelpers . createEmptySpec ( ) ,
1343+ paths : {
1344+ '/api/users' : {
1345+ get : {
1346+ responses : { } ,
1347+ } ,
1348+ } ,
1349+ } ,
1350+ } ;
1351+ const results = await TestHelpers . runRulesWithInputs (
1352+ [
1353+ await BreakingChangesRuleset . fromOpticConfig ( {
1354+ exclude_operations_with_extension : [
1355+ { 'x-stability-level' : [ 'draft' ] } ,
1356+ ] ,
1357+ } ) as any ,
1358+ ] ,
1359+ beforeJson ,
1360+ afterJson
1361+ ) ;
1362+ expect ( results . length ) . toEqual ( 1 ) ;
1363+ } ) ;
1364+
1365+ test ( 'breaking changes applies a matches function for object extension value missing' , async ( ) => {
1366+ const beforeJson : OpenAPIV3 . Document = {
1367+ ...TestHelpers . createEmptySpec ( ) ,
1368+ paths : {
1369+ '/api/users' : {
1370+ get : {
1371+ responses : { } ,
1372+ } ,
1373+ post : {
1374+ responses : { } ,
1375+ } as any ,
1376+ } ,
1377+ } ,
1378+ } ;
1379+ const afterJson : OpenAPIV3 . Document = {
1380+ ...TestHelpers . createEmptySpec ( ) ,
1381+ paths : {
1382+ '/api/users' : {
1383+ get : {
1384+ responses : { } ,
1385+ } ,
1386+ } ,
1387+ } ,
1388+ } ;
1389+ const results = await TestHelpers . runRulesWithInputs (
1390+ [
1391+ await BreakingChangesRuleset . fromOpticConfig ( {
1392+ exclude_operations_with_extension : [
1393+ { 'x-stability-level' : [ 'draft' ] } ,
1394+ ] ,
1395+ } ) as any ,
1396+ ] ,
1397+ beforeJson ,
1398+ afterJson
1399+ ) ;
1400+ expect ( results . length ) . toEqual ( 1 ) ;
12721401 } ) ;
12731402} ) ;
0 commit comments