11import { compareFiles } from '../utils'
22import { diffsMatcher } from '../../helper/matchers'
33import { annotation , DiffAction } from '../../../src'
4+ import { runRefObjectDescriptionTests } from './templates/reference-object-31.template'
45
56const SUITE_ID = 'request-body-examples'
67
7- const REQUEST_BODY_PATH = [
8- 'paths' ,
9- '/path1' ,
10- 'post' ,
11- 'requestBody' ,
12- ]
8+ const REQUEST_BODY_CONTENT_EXAMPLES_PATH = [ 'paths' , '/path1' , 'post' , 'requestBody' , 'content' , 'application/json' , 'examples' ]
139
1410describe ( 'Openapi3 Request Body Examples' , ( ) => {
1511
@@ -19,7 +15,7 @@ describe('Openapi3 Request Body Examples', () => {
1915 expect ( result ) . toEqual ( diffsMatcher ( [
2016 expect . objectContaining ( {
2117 action : DiffAction . add ,
22- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' ] ] ,
18+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' ] ] ,
2319 type : annotation ,
2420 } ) ,
2521 ] ) )
@@ -31,7 +27,7 @@ describe('Openapi3 Request Body Examples', () => {
3127 expect ( result ) . toEqual ( diffsMatcher ( [
3228 expect . objectContaining ( {
3329 action : DiffAction . add ,
34- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example2' ] ] ,
30+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example2' ] ] ,
3531 type : annotation ,
3632 } ) ,
3733 ] ) )
@@ -43,8 +39,8 @@ describe('Openapi3 Request Body Examples', () => {
4339 expect ( result ) . toEqual ( diffsMatcher ( [
4440 expect . objectContaining ( {
4541 action : DiffAction . replace ,
46- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'value' ] ] ,
47- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'value' ] ] ,
42+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'value' ] ] ,
43+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'value' ] ] ,
4844 type : annotation ,
4945 } ) ,
5046 ] ) )
@@ -56,12 +52,12 @@ describe('Openapi3 Request Body Examples', () => {
5652 expect ( result ) . toEqual ( diffsMatcher ( [
5753 expect . objectContaining ( {
5854 action : DiffAction . remove ,
59- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' ] ] ,
55+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' ] ] ,
6056 type : annotation ,
6157 } ) ,
6258 expect . objectContaining ( {
6359 action : DiffAction . add ,
64- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example0' ] ] ,
60+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example0' ] ] ,
6561 type : annotation ,
6662 } ) ,
6763 ] ) )
@@ -73,8 +69,8 @@ describe('Openapi3 Request Body Examples', () => {
7369 expect ( result ) . toEqual ( diffsMatcher ( [
7470 expect . objectContaining ( {
7571 action : DiffAction . replace ,
76- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'externalValue' ] ] ,
77- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'externalValue' ] ] ,
72+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'externalValue' ] ] ,
73+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'externalValue' ] ] ,
7874 type : annotation ,
7975 } ) ,
8076 ] ) )
@@ -86,7 +82,7 @@ describe('Openapi3 Request Body Examples', () => {
8682 expect ( result ) . toEqual ( diffsMatcher ( [
8783 expect . objectContaining ( {
8884 action : DiffAction . remove ,
89- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'externalValue' ] ] ,
85+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'externalValue' ] ] ,
9086 type : annotation ,
9187 } ) ,
9288 ] ) )
@@ -98,7 +94,7 @@ describe('Openapi3 Request Body Examples', () => {
9894 expect ( result ) . toEqual ( diffsMatcher ( [
9995 expect . objectContaining ( {
10096 action : DiffAction . add ,
101- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'summary' ] ] ,
97+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'summary' ] ] ,
10298 type : annotation ,
10399 } ) ,
104100 ] ) )
@@ -110,8 +106,8 @@ describe('Openapi3 Request Body Examples', () => {
110106 expect ( result ) . toEqual ( diffsMatcher ( [
111107 expect . objectContaining ( {
112108 action : DiffAction . replace ,
113- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'summary' ] ] ,
114- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'summary' ] ] ,
109+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'summary' ] ] ,
110+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'summary' ] ] ,
115111 type : annotation ,
116112 } ) ,
117113 ] ) )
@@ -123,7 +119,7 @@ describe('Openapi3 Request Body Examples', () => {
123119 expect ( result ) . toEqual ( diffsMatcher ( [
124120 expect . objectContaining ( {
125121 action : DiffAction . remove ,
126- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'summary' ] ] ,
122+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'summary' ] ] ,
127123 type : annotation ,
128124 } ) ,
129125 ] ) )
@@ -135,7 +131,7 @@ describe('Openapi3 Request Body Examples', () => {
135131 expect ( result ) . toEqual ( diffsMatcher ( [
136132 expect . objectContaining ( {
137133 action : DiffAction . add ,
138- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'description' ] ] ,
134+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'description' ] ] ,
139135 type : annotation ,
140136 } ) ,
141137 ] ) )
@@ -147,8 +143,8 @@ describe('Openapi3 Request Body Examples', () => {
147143 expect ( result ) . toEqual ( diffsMatcher ( [
148144 expect . objectContaining ( {
149145 action : DiffAction . replace ,
150- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'description' ] ] ,
151- afterDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'description' ] ] ,
146+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'description' ] ] ,
147+ afterDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'description' ] ] ,
152148 type : annotation ,
153149 } ) ,
154150 ] ) )
@@ -160,9 +156,14 @@ describe('Openapi3 Request Body Examples', () => {
160156 expect ( result ) . toEqual ( diffsMatcher ( [
161157 expect . objectContaining ( {
162158 action : DiffAction . remove ,
163- beforeDeclarationPaths : [ [ ...REQUEST_BODY_PATH , 'content' , 'application/json' , 'examples' , 'example1' , 'description' ] ] ,
159+ beforeDeclarationPaths : [ [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'example1' , 'description' ] ] ,
164160 type : annotation ,
165161 } ) ,
166162 ] ) )
167163 } )
168164} )
165+
166+ const COMPONENTS_EXAMPLES_PATH = [ 'components' , 'examples' , 'ex1' ]
167+ describe ( 'Reference object. Request body examples. Description fields in ref object' , ( ) => {
168+ runRefObjectDescriptionTests ( SUITE_ID , [ ...REQUEST_BODY_CONTENT_EXAMPLES_PATH , 'ex1' ] , COMPONENTS_EXAMPLES_PATH )
169+ } )
0 commit comments