| 
 | 1 | +import { apiDiff, ClassifierType, DiffAction } from '../src'  | 
 | 2 | +import { diffsMatcher } from './helper/matchers'  | 
 | 3 | + | 
 | 4 | +const COMPONENTS_RESPONSE_PATH = [  | 
 | 5 | +  'components',  | 
 | 6 | +  'pathItems',  | 
 | 7 | +  'componentsPathItem',  | 
 | 8 | +  'post',  | 
 | 9 | +  'responses',  | 
 | 10 | +  '200',  | 
 | 11 | +]  | 
 | 12 | + | 
 | 13 | +describe('Openapi3.1 Components PathItems Rules', () => {  | 
 | 14 | +  test('could be a replace annotation', async () => {  | 
 | 15 | +    const before = {  | 
 | 16 | +      'openapi': '3.1.0',  | 
 | 17 | +      'paths': {  | 
 | 18 | +        '/path1': {  | 
 | 19 | +          'post': {  | 
 | 20 | +            'responses': {  | 
 | 21 | +              '200': {},  | 
 | 22 | +            },  | 
 | 23 | +          },  | 
 | 24 | +        },  | 
 | 25 | +      },  | 
 | 26 | +      'components': {  | 
 | 27 | +        'pathItems': {  | 
 | 28 | +          'componentsPathItem': {  | 
 | 29 | +            'post': {  | 
 | 30 | +              'responses': {  | 
 | 31 | +                '200': {  | 
 | 32 | +                  'description': 'Pet successfully added',  | 
 | 33 | +                },  | 
 | 34 | +              },  | 
 | 35 | +            },  | 
 | 36 | +          },  | 
 | 37 | +        },  | 
 | 38 | +      },  | 
 | 39 | +    }  | 
 | 40 | + | 
 | 41 | +    const after = {  | 
 | 42 | +      'openapi': '3.1.0',  | 
 | 43 | +      'paths': {  | 
 | 44 | +        '/path1': {  | 
 | 45 | +          'post': {  | 
 | 46 | +            'responses': {  | 
 | 47 | +              '200': {},  | 
 | 48 | +            },  | 
 | 49 | +          },  | 
 | 50 | +        },  | 
 | 51 | +      },  | 
 | 52 | +      'components': {  | 
 | 53 | +        'pathItems': {  | 
 | 54 | +          'componentsPathItem': {  | 
 | 55 | +            'post': {  | 
 | 56 | +              'responses': {  | 
 | 57 | +                '200': {  | 
 | 58 | +                  'description': 'new value',  | 
 | 59 | +                },  | 
 | 60 | +              },  | 
 | 61 | +            },  | 
 | 62 | +          },  | 
 | 63 | +        },  | 
 | 64 | +      },  | 
 | 65 | +    }  | 
 | 66 | + | 
 | 67 | +    const result = apiDiff(before, after)  | 
 | 68 | +    expect(result.diffs).toEqual(diffsMatcher([  | 
 | 69 | +      expect.objectContaining({  | 
 | 70 | +        action: DiffAction.replace,  | 
 | 71 | +        beforeValue: 'Pet successfully added',  | 
 | 72 | +        afterValue: 'new value',  | 
 | 73 | +        beforeDeclarationPaths: [[  | 
 | 74 | +          ...COMPONENTS_RESPONSE_PATH,  | 
 | 75 | +          'description',  | 
 | 76 | +        ]],  | 
 | 77 | +        afterDeclarationPaths: [[  | 
 | 78 | +          ...COMPONENTS_RESPONSE_PATH,  | 
 | 79 | +          'description',  | 
 | 80 | +        ]],  | 
 | 81 | +        type: ClassifierType.annotation,  | 
 | 82 | +      }),  | 
 | 83 | +    ]))  | 
 | 84 | +  })  | 
 | 85 | + | 
 | 86 | +  test('could be a remove annotation', async () => {  | 
 | 87 | +    const before = {  | 
 | 88 | +      'openapi': '3.1.0',  | 
 | 89 | +      'paths': {  | 
 | 90 | +        '/path1': {  | 
 | 91 | +          'post': {  | 
 | 92 | +            'responses': {  | 
 | 93 | +              '200': {},  | 
 | 94 | +            },  | 
 | 95 | +          },  | 
 | 96 | +        },  | 
 | 97 | +      },  | 
 | 98 | +      'components': {  | 
 | 99 | +        'pathItems': {  | 
 | 100 | +          'componentsPathItem': {  | 
 | 101 | +            'post': {  | 
 | 102 | +              'responses': {  | 
 | 103 | +                '200': {  | 
 | 104 | +                  'description': 'Pet successfully added',  | 
 | 105 | +                },  | 
 | 106 | +              },  | 
 | 107 | +            },  | 
 | 108 | +          },  | 
 | 109 | +        },  | 
 | 110 | +      },  | 
 | 111 | +    }  | 
 | 112 | + | 
 | 113 | +    const after = {  | 
 | 114 | +      'openapi': '3.1.0',  | 
 | 115 | +      'paths': {  | 
 | 116 | +        '/path1': {  | 
 | 117 | +          'post': {  | 
 | 118 | +            'responses': {  | 
 | 119 | +              '200': {},  | 
 | 120 | +            },  | 
 | 121 | +          },  | 
 | 122 | +        },  | 
 | 123 | +      },  | 
 | 124 | +      'components': {  | 
 | 125 | +        'pathItems': {  | 
 | 126 | +          'componentsPathItem': {  | 
 | 127 | +            'post': {  | 
 | 128 | +              'responses': {  | 
 | 129 | +                '200': {  | 
 | 130 | +                },  | 
 | 131 | +              },  | 
 | 132 | +            },  | 
 | 133 | +          },  | 
 | 134 | +        },  | 
 | 135 | +      },  | 
 | 136 | +    }  | 
 | 137 | + | 
 | 138 | +    const result = apiDiff(before, after)  | 
 | 139 | +    expect(result.diffs).toEqual(diffsMatcher([  | 
 | 140 | +      expect.objectContaining({  | 
 | 141 | +        action: DiffAction.remove,  | 
 | 142 | +        beforeValue: 'Pet successfully added',  | 
 | 143 | +        beforeDeclarationPaths: [[  | 
 | 144 | +          ...COMPONENTS_RESPONSE_PATH,  | 
 | 145 | +          'description',  | 
 | 146 | +        ]],  | 
 | 147 | +        type: ClassifierType.annotation,  | 
 | 148 | +      }),  | 
 | 149 | +    ]))  | 
 | 150 | +  })  | 
 | 151 | +  test('could be a add annotation', async () => {  | 
 | 152 | +    const before = {  | 
 | 153 | +      'openapi': '3.1.0',  | 
 | 154 | +      'paths': {  | 
 | 155 | +        '/path1': {  | 
 | 156 | +          'post': {  | 
 | 157 | +            'responses': {  | 
 | 158 | +              '200': {},  | 
 | 159 | +            },  | 
 | 160 | +          },  | 
 | 161 | +        },  | 
 | 162 | +      },  | 
 | 163 | +      'components': {  | 
 | 164 | +        'pathItems': {  | 
 | 165 | +          'componentsPathItem': {  | 
 | 166 | +            'post': {  | 
 | 167 | +              'responses': {  | 
 | 168 | +                '200': {  | 
 | 169 | +                },  | 
 | 170 | +              },  | 
 | 171 | +            },  | 
 | 172 | +          },  | 
 | 173 | +        },  | 
 | 174 | +      },  | 
 | 175 | +    }  | 
 | 176 | + | 
 | 177 | +    const after = {  | 
 | 178 | +      'openapi': '3.1.0',  | 
 | 179 | +      'paths': {  | 
 | 180 | +        '/path1': {  | 
 | 181 | +          'post': {  | 
 | 182 | +            'responses': {  | 
 | 183 | +              '200': {},  | 
 | 184 | +            },  | 
 | 185 | +          },  | 
 | 186 | +        },  | 
 | 187 | +      },  | 
 | 188 | +      'components': {  | 
 | 189 | +        'pathItems': {  | 
 | 190 | +          'componentsPathItem': {  | 
 | 191 | +            'post': {  | 
 | 192 | +              'responses': {  | 
 | 193 | +                '200': {  | 
 | 194 | +                  'description': 'Pet successfully added',  | 
 | 195 | +                },  | 
 | 196 | +              },  | 
 | 197 | +            },  | 
 | 198 | +          },  | 
 | 199 | +        },  | 
 | 200 | +      },  | 
 | 201 | +    }  | 
 | 202 | + | 
 | 203 | +    const result = apiDiff(before, after)  | 
 | 204 | +    expect(result.diffs).toEqual(diffsMatcher([  | 
 | 205 | +      expect.objectContaining({  | 
 | 206 | +        action: DiffAction.add,  | 
 | 207 | +        afterValue: 'Pet successfully added',  | 
 | 208 | +        afterDeclarationPaths: [[  | 
 | 209 | +          ...COMPONENTS_RESPONSE_PATH,  | 
 | 210 | +          'description',  | 
 | 211 | +        ]],  | 
 | 212 | +        type: ClassifierType.annotation,  | 
 | 213 | +      }),  | 
 | 214 | +    ]))  | 
 | 215 | +  })  | 
 | 216 | +})  | 
0 commit comments