@@ -26,6 +26,70 @@ describe('openapi-format core API', () => {
2626 expect ( result . data . tags ) . toEqual ( [ { name : 'pets' } ] ) ;
2727 } ) ;
2828
29+ it ( 'openapiFilter should keep inverseFlags-matched operations when stripFlags removes the same key' , 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 , {
45+ filterSet : { inverseFlags : [ 'x-public' ] , stripFlags : [ 'x-public' ] }
46+ } ) ;
47+ expect ( inverseAndStrip . data . paths ) . toHaveProperty ( '/pets.get' ) ;
48+ expect ( inverseAndStrip . data . paths [ '/pets' ] . get [ 'x-public' ] ) . toBeUndefined ( ) ;
49+ expect ( inverseAndStrip . data . paths [ '/pets' ] . post ) . toBeUndefined ( ) ;
50+ } ) ;
51+
52+ it ( 'adding responses to unusedComponents should not remove still-referenced schemas' , async ( ) => {
53+ const doc = {
54+ openapi : '3.0.0' ,
55+ info : { title : 'API' , version : '1.0.0' } ,
56+ paths : {
57+ '/pets' : {
58+ get : {
59+ 'x-public' : true ,
60+ responses : {
61+ 200 : { description : 'ok' , content : { 'application/json' : { schema : { $ref : '#/components/schemas/Pet' } } } }
62+ }
63+ } ,
64+ post : {
65+ responses : {
66+ 200 : { description : 'ok' , content : { 'application/json' : { schema : { $ref : '#/components/schemas/Pet' } } } }
67+ }
68+ }
69+ }
70+ } ,
71+ components : {
72+ schemas : {
73+ Pet : { type : 'object' }
74+ }
75+ }
76+ } ;
77+
78+ const base = {
79+ inverseFlags : [ 'x-public' ] ,
80+ stripFlags : [ 'x-public' ] ,
81+ unusedComponents : [ 'schemas' , 'parameters' , 'examples' , 'headers' , 'requestBodies' ]
82+ } ;
83+ const withResponses = { ...base , unusedComponents : [ ...base . unusedComponents , 'responses' ] } ;
84+
85+ const resultBase = await openapiFilter ( doc , { filterSet : base } ) ;
86+ const resultWithResponses = await openapiFilter ( doc , { filterSet : withResponses } ) ;
87+
88+ expect ( resultBase . data ) . toEqual ( resultWithResponses . data ) ;
89+ expect ( resultWithResponses . data . paths ) . toHaveProperty ( '/pets.get' ) ;
90+ expect ( resultWithResponses . data . components . schemas ) . toHaveProperty ( 'Pet' ) ;
91+ } ) ;
92+
2993 it ( 'openapiChangeCase should apply summary, description and securitySchemes ref casing' , async ( ) => {
3094 const doc = {
3195 openapi : '3.0.0' ,
0 commit comments