|
4 | 4 | } = require('../../../../src/plugins/validation/swagger2/semantic-validators/operations-ibm');
|
5 | 5 |
|
6 | 6 | describe('validation plugin - semantic - operations-ibm - swagger2', function() {
|
7 |
| - it('should complain about a missing consumes with content', function() { |
| 7 | + it('should complain about PUT operation with body parameter and a missing consumes', function() { |
8 | 8 | const config = {
|
9 | 9 | operations: {
|
10 | 10 | no_consumes_for_put_or_post: 'error'
|
@@ -41,12 +41,12 @@ describe('validation plugin - semantic - operations-ibm - swagger2', function()
|
41 | 41 | expect(res.errors.length).toEqual(1);
|
42 | 42 | expect(res.errors[0].path).toEqual('paths./CoolPath.put.consumes');
|
43 | 43 | expect(res.errors[0].message).toEqual(
|
44 |
| - 'PUT and POST operations must have a non-empty `consumes` field.' |
| 44 | + 'PUT and POST operations with a body parameter must have a non-empty `consumes` field.' |
45 | 45 | );
|
46 | 46 | expect(res.warnings.length).toEqual(0);
|
47 | 47 | });
|
48 | 48 |
|
49 |
| - it('should complain about an empty consumes', function() { |
| 49 | + it('should complain about POST operation with body parameter and a missing consumes', function() { |
50 | 50 | const config = {
|
51 | 51 | operations: {
|
52 | 52 | no_consumes_for_put_or_post: 'error'
|
@@ -84,11 +84,121 @@ describe('validation plugin - semantic - operations-ibm - swagger2', function()
|
84 | 84 | expect(res.errors.length).toEqual(1);
|
85 | 85 | expect(res.errors[0].path).toEqual('paths./CoolPath.post.consumes');
|
86 | 86 | expect(res.errors[0].message).toEqual(
|
87 |
| - 'PUT and POST operations must have a non-empty `consumes` field.' |
| 87 | + 'PUT and POST operations with a body parameter must have a non-empty `consumes` field.' |
88 | 88 | );
|
89 | 89 | expect(res.warnings.length).toEqual(0);
|
90 | 90 | });
|
91 | 91 |
|
| 92 | + it('should complain about PUT opeartion with body parameter in path and a missing consumes', function() { |
| 93 | + const config = { |
| 94 | + operations: { |
| 95 | + no_consumes_for_put_or_post: 'error' |
| 96 | + } |
| 97 | + }; |
| 98 | + |
| 99 | + const spec = { |
| 100 | + paths: { |
| 101 | + '/CoolPath': { |
| 102 | + parameters: [ |
| 103 | + { |
| 104 | + name: 'BadParameter', |
| 105 | + in: 'body', |
| 106 | + schema: { |
| 107 | + required: ['Property'], |
| 108 | + properties: [ |
| 109 | + { |
| 110 | + name: 'Property' |
| 111 | + } |
| 112 | + ] |
| 113 | + } |
| 114 | + } |
| 115 | + ], |
| 116 | + put: { |
| 117 | + consumes: [' '], |
| 118 | + produces: ['application/json'], |
| 119 | + summary: 'this is a summary', |
| 120 | + operationId: 'operationId' |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + }; |
| 125 | + |
| 126 | + const res = validate({ jsSpec: spec }, config); |
| 127 | + expect(res.errors.length).toEqual(1); |
| 128 | + expect(res.errors[0].path).toEqual('paths./CoolPath.put.consumes'); |
| 129 | + expect(res.errors[0].message).toEqual( |
| 130 | + 'PUT and POST operations with a body parameter must have a non-empty `consumes` field.' |
| 131 | + ); |
| 132 | + expect(res.warnings.length).toEqual(0); |
| 133 | + }); |
| 134 | + |
| 135 | + it('should complain about POST opeartion with body parameter in path and a missing consumes', function() { |
| 136 | + const config = { |
| 137 | + operations: { |
| 138 | + no_consumes_for_put_or_post: 'error' |
| 139 | + } |
| 140 | + }; |
| 141 | + |
| 142 | + const spec = { |
| 143 | + paths: { |
| 144 | + '/CoolPath': { |
| 145 | + parameters: [ |
| 146 | + { |
| 147 | + name: 'BadParameter', |
| 148 | + in: 'body', |
| 149 | + schema: { |
| 150 | + required: ['Property'], |
| 151 | + properties: [ |
| 152 | + { |
| 153 | + name: 'Property' |
| 154 | + } |
| 155 | + ] |
| 156 | + } |
| 157 | + } |
| 158 | + ], |
| 159 | + post: { |
| 160 | + consumes: [' '], |
| 161 | + produces: ['application/json'], |
| 162 | + summary: 'this is a summary', |
| 163 | + operationId: 'operationId' |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + }; |
| 168 | + |
| 169 | + const res = validate({ jsSpec: spec }, config); |
| 170 | + expect(res.errors.length).toEqual(1); |
| 171 | + expect(res.errors[0].path).toEqual('paths./CoolPath.post.consumes'); |
| 172 | + expect(res.errors[0].message).toEqual( |
| 173 | + 'PUT and POST operations with a body parameter must have a non-empty `consumes` field.' |
| 174 | + ); |
| 175 | + expect(res.warnings.length).toEqual(0); |
| 176 | + }); |
| 177 | + |
| 178 | + it('should not complain about missing consumes when there is no body parameter', function() { |
| 179 | + const config = { |
| 180 | + operations: { |
| 181 | + no_consumes_for_put_or_post: 'error' |
| 182 | + } |
| 183 | + }; |
| 184 | + |
| 185 | + const spec = { |
| 186 | + paths: { |
| 187 | + '/CoolPath': { |
| 188 | + put: { |
| 189 | + produces: ['application/json'], |
| 190 | + summary: 'this is a summary', |
| 191 | + operationId: 'operationId' |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | + }; |
| 196 | + |
| 197 | + const res = validate({ jsSpec: spec }, config); |
| 198 | + expect(res.errors.length).toEqual(0); |
| 199 | + expect(res.warnings.length).toEqual(0); |
| 200 | + }); |
| 201 | + |
92 | 202 | it('should not complain about a missing consumes when there is a global consumes', function() {
|
93 | 203 | const config = {
|
94 | 204 | operations: {
|
|
0 commit comments