@@ -26,6 +26,56 @@ describe('openapi-format core API', () => {
2626 expect ( result . data . tags ) . toEqual ( [ { name : 'pets' } ] ) ;
2727 } ) ;
2828
29+ it ( 'openapiFilter inverseFlags + stripFlags currently removes previously kept operations after recurse' , async ( ) => {
30+ const doc = {
31+ openapi : '3.0.0' ,
32+ info : { title : 'API' , version : '1.0.0' } ,
33+ paths : {
34+ '/pets' : {
35+ get : { 'x-public' : true , responses : { '200' : { description : 'ok' } } } ,
36+ post : { responses : { '200' : { description : 'ok' } } }
37+ }
38+ }
39+ } ;
40+
41+ const onlyInverse = await openapiFilter ( doc , { filterSet : { inverseFlags : [ 'x-public' ] } } ) ;
42+ expect ( onlyInverse . data . paths ) . toHaveProperty ( '/pets.get' ) ;
43+
44+ const inverseAndStrip = await openapiFilter ( doc , { filterSet : { inverseFlags : [ 'x-public' ] , stripFlags : [ 'x-public' ] } } ) ;
45+ expect ( inverseAndStrip . data . paths ) . toBeUndefined ( ) ;
46+ } ) ;
47+
48+ it ( 'adding responses to unusedComponents does not change inverseFlags+stripFlags outcome' , async ( ) => {
49+ const doc = {
50+ openapi : '3.0.0' ,
51+ info : { title : 'API' , version : '1.0.0' } ,
52+ paths : {
53+ '/pets' : {
54+ get : { 'x-public' : true , responses : { '200' : { description : 'ok' } } } ,
55+ post : { responses : { '200' : { description : 'ok' } } }
56+ }
57+ } ,
58+ components : {
59+ schemas : {
60+ Pet : { type : 'object' }
61+ }
62+ }
63+ } ;
64+
65+ const base = {
66+ inverseFlags : [ 'x-public' ] ,
67+ stripFlags : [ 'x-public' ] ,
68+ unusedComponents : [ 'schemas' , 'parameters' , 'examples' , 'headers' , 'requestBodies' ]
69+ } ;
70+ const withResponses = { ...base , unusedComponents : [ ...base . unusedComponents , 'responses' ] } ;
71+
72+ const resultBase = await openapiFilter ( doc , { filterSet : base } ) ;
73+ const resultWithResponses = await openapiFilter ( doc , { filterSet : withResponses } ) ;
74+
75+ expect ( resultBase . data ) . toEqual ( resultWithResponses . data ) ;
76+ expect ( resultWithResponses . data . paths ) . toBeUndefined ( ) ;
77+ } ) ;
78+
2979 it ( 'openapiChangeCase should apply summary, description and securitySchemes ref casing' , async ( ) => {
3080 const doc = {
3181 openapi : '3.0.0' ,
0 commit comments