@@ -57,6 +57,37 @@ describe('Definition generation', () => {
5757 expect ( expression . evaluate ( spec ) ) . to . eq ( 'Joe' ) ;
5858 } ) ;
5959
60+ it ( 'should include default response if a non-conflicting response is declared with a decorator' , ( ) => {
61+ let expression = jsonata ( 'paths."/promise".get.responses' ) ;
62+ expect ( Object . keys ( expression . evaluate ( spec ) ) . length ) . to . eq ( 2 ) ;
63+ expression = jsonata ( 'paths."/promise".get.responses."200".description' ) ;
64+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'Ok' ) ;
65+ expression = jsonata ( 'paths."/promise".get.responses."401".description' ) ;
66+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'Unauthorized' ) ;
67+ } ) ;
68+
69+ it ( 'should not include default response if it conflicts with a declared response' , ( ) => {
70+ let expression = jsonata ( 'paths."/promise".post.responses' ) ;
71+ expect ( Object . keys ( expression . evaluate ( spec ) ) . length ) . to . eq ( 2 ) ;
72+ expression = jsonata ( 'paths."/promise".post.responses."201".description' ) ;
73+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'Person Created' ) ;
74+ expression = jsonata ( 'paths."/promise".post.responses."201".examples."application/json".name' ) ;
75+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'Test Person' ) ;
76+ expression = jsonata ( 'paths."/promise".post.responses."401".description' ) ;
77+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'Unauthorized' ) ;
78+ } ) ;
79+
80+ it ( 'should update a declared response with the declared default response example if response annotation doesn\'t specify one' , ( ) => {
81+ let expression = jsonata ( 'paths."/promise/{id}".get.responses' ) ;
82+ expect ( Object . keys ( expression . evaluate ( spec ) ) . length ) . to . eq ( 2 ) ;
83+ expression = jsonata ( 'paths."/promise/{id}".get.responses."200".description' ) ;
84+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'All Good' ) ;
85+ expression = jsonata ( 'paths."/promise/{id}".get.responses."200".examples."application/json".name' ) ;
86+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'Test Person' ) ;
87+ expression = jsonata ( 'paths."/promise/{id}".get.responses."401".description' ) ;
88+ expect ( expression . evaluate ( spec ) ) . to . eq ( 'Unauthorized' ) ;
89+ } ) ;
90+
6091 it ( 'should generate a definition with a referenced type' , ( ) => {
6192 const expression = jsonata ( 'definitions.Person.properties.address."$ref"' ) ;
6293 expect ( expression . evaluate ( spec ) ) . to . eq ( '#/definitions/Address' ) ;
0 commit comments