@@ -139,4 +139,52 @@ public void binaryDataTest() {
139
139
Assert .assertTrue (op .bodyParam .isBinary );
140
140
Assert .assertTrue (op .responses .get (0 ).isBinary );
141
141
}
142
+
143
+ @ Test (description = "use operation consumes and producus" )
144
+ public void localConsumesAndProducesTest () {
145
+ final Swagger model = new SwaggerParser ().read ("src/test/resources/2_0/globalConsumesAndProduces.json" );
146
+ final DefaultCodegen codegen = new DefaultCodegen ();
147
+ final String path = "/tests/localConsumesAndProduces" ;
148
+ final Operation p = model .getPaths ().get (path ).getGet ();
149
+ CodegenOperation op = codegen .fromOperation (path , "get" , p , model .getDefinitions (), model );
150
+
151
+ Assert .assertTrue (op .hasConsumes );
152
+ Assert .assertEquals (op .consumes .size (), 1 );
153
+ Assert .assertEquals (op .consumes .get (0 ).get ("mediaType" ), "application/json" );
154
+ Assert .assertTrue (op .hasProduces );
155
+ Assert .assertEquals (op .produces .size (), 1 );
156
+ Assert .assertEquals (op .produces .get (0 ).get ("mediaType" ), "application/json" );
157
+ }
158
+
159
+ @ Test (description = "use spec consumes and producus" )
160
+ public void globalConsumesAndProducesTest () {
161
+ final Swagger model = new SwaggerParser ().read ("src/test/resources/2_0/globalConsumesAndProduces.json" );
162
+ final DefaultCodegen codegen = new DefaultCodegen ();
163
+ final String path = "/tests/globalConsumesAndProduces" ;
164
+ final Operation p = model .getPaths ().get (path ).getGet ();
165
+ CodegenOperation op = codegen .fromOperation (path , "get" , p , model .getDefinitions (), model );
166
+
167
+ Assert .assertTrue (op .hasConsumes );
168
+ Assert .assertEquals (op .consumes .size (), 1 );
169
+ Assert .assertEquals (op .consumes .get (0 ).get ("mediaType" ), "application/global_consumes" );
170
+ Assert .assertTrue (op .hasProduces );
171
+ Assert .assertEquals (op .produces .size (), 1 );
172
+ Assert .assertEquals (op .produces .get (0 ).get ("mediaType" ), "application/global_produces" );
173
+ }
174
+
175
+ @ Test (description = "use spec consumes and producus (reset in operation with empty array)" )
176
+ public void localResetConsumesAndProducesTest () {
177
+ final Swagger model = new SwaggerParser ().read ("src/test/resources/2_0/globalConsumesAndProduces.json" );
178
+ final DefaultCodegen codegen = new DefaultCodegen ();
179
+ final String path = "/tests/localResetConsumesAndProduces" ;
180
+ final Operation p = model .getPaths ().get (path ).getGet ();
181
+ CodegenOperation op = codegen .fromOperation (path , "get" , p , model .getDefinitions (), model );
182
+
183
+ Assert .assertNotNull (op );
184
+ Assert .assertFalse (op .hasConsumes );
185
+ Assert .assertNull (op .consumes );
186
+ Assert .assertFalse (op .hasProduces );
187
+ Assert .assertNull (op .produces );
188
+
189
+ }
142
190
}
0 commit comments