Skip to content

Commit 0b4b5e8

Browse files
committed
Revert "Add support for top-level consumes and produces"
1 parent c7b08bc commit 0b4b5e8

File tree

6 files changed

+11
-229
lines changed

6 files changed

+11
-229
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public interface CodegenConfig {
6767

6868
CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions);
6969

70-
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger);
71-
7270
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions);
7371

7472
List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition> schemes);

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,8 @@ private Response findMethodResponse(Map<String, Response> responses) {
867867
}
868868
return responses.get(code);
869869
}
870-
870+
871871
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
872-
return fromOperation(path, httpMethod, operation, definitions, null);
873-
}
874-
875-
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
876872
CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION);
877873
Set<String> imports = new HashSet<String>();
878874
op.vendorExtensions = operation.getVendorExtensions();
@@ -908,32 +904,15 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
908904
op.summary = escapeText(operation.getSummary());
909905
op.notes = escapeText(operation.getDescription());
910906
op.tags = operation.getTags();
911-
op.hasConsumes = false;
912-
op.hasProduces = false;
913-
914-
List<String> consumes = new ArrayList<String>();
915-
if (operation.getConsumes() != null) {
916-
if (operation.getConsumes().size() > 0) {
917-
// use consumes defined in the operation
918-
consumes = operation.getConsumes();
919-
} else {
920-
// empty list, do nothing to override global setting
921-
}
922-
} else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) {
923-
// use consumes defined globally
924-
consumes = swagger.getConsumes();
925-
LOGGER.debug("No consumes defined in operation. Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId);
926-
}
927-
928-
// if "consumes" is defined (per operation or using global definition)
929-
if (consumes != null && consumes.size() > 0) {
907+
908+
if (operation.getConsumes() != null && operation.getConsumes().size() > 0) {
930909
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
931910
int count = 0;
932-
for (String key : consumes) {
911+
for (String key : operation.getConsumes()) {
933912
Map<String, String> mediaType = new HashMap<String, String>();
934913
mediaType.put("mediaType", key);
935914
count += 1;
936-
if (count < consumes.size()) {
915+
if (count < operation.getConsumes().size()) {
937916
mediaType.put("hasMore", "true");
938917
} else {
939918
mediaType.put("hasMore", null);
@@ -944,29 +923,14 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
944923
op.hasConsumes = true;
945924
}
946925

947-
List<String> produces = new ArrayList<String>();
948-
if (operation.getProduces() != null) {
949-
if (operation.getProduces().size() > 0) {
950-
// use produces defined in the operation
951-
produces = operation.getProduces();
952-
} else {
953-
// empty list, do nothing to override global setting
954-
}
955-
} else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) {
956-
// use produces defined globally
957-
produces = swagger.getProduces();
958-
LOGGER.debug("No produces defined in operation. Using global produces (" + swagger.getProduces() + ") for " + op.operationId);
959-
}
960-
961-
// if "produces" is defined (per operation or using global definition)
962-
if (produces != null && produces.size() > 0) {
926+
if (operation.getProduces() != null && operation.getProduces().size() > 0) {
963927
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
964928
int count = 0;
965-
for (String key : produces) {
929+
for (String key : operation.getProduces()) {
966930
Map<String, String> mediaType = new HashMap<String, String>();
967931
mediaType.put("mediaType", key);
968932
count += 1;
969-
if (count < produces.size()) {
933+
if (count < operation.getProduces().size()) {
970934
mediaType.put("hasMore", "true");
971935
} else {
972936
mediaType.put("hasMore", null);

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public void processOperation(String resourcePath, String httpMethod, Operation o
470470
for (String tag : tags) {
471471
CodegenOperation co = null;
472472
try {
473-
co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions(), swagger);
473+
co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
474474
co.tags = new ArrayList<String>();
475475
co.tags.add(sanitizeTag(tag));
476476
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package io.swagger.codegen.languages;
22

33
import com.google.common.base.Predicate;
4-
54
import com.google.common.collect.Iterators;
65
import com.google.common.collect.Lists;
76
import io.swagger.codegen.*;
8-
import io.swagger.models.Swagger;
97
import io.swagger.models.Model;
108
import io.swagger.models.Operation;
119
import io.swagger.models.parameters.HeaderParameter;
@@ -258,7 +256,7 @@ public String toApiName(String name) {
258256
}
259257

260258
@Override
261-
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
259+
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
262260
path = normalizePath(path);
263261
List<Parameter> parameters = operation.getParameters();
264262
parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate<Parameter>() {
@@ -268,7 +266,7 @@ public boolean apply(@Nullable Parameter parameter) {
268266
}
269267
}));
270268
operation.setParameters(parameters);
271-
return super.fromOperation(path, httpMethod, operation, definitions, swagger);
269+
return super.fromOperation(path, httpMethod, operation, definitions);
272270
}
273271

274272
private static String normalizePath(String path) {

modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -139,52 +139,4 @@ public void binaryDataTest() {
139139
Assert.assertTrue(op.bodyParam.isBinary);
140140
Assert.assertTrue(op.responses.get(0).isBinary);
141141
}
142-
143-
@Test(description = "use operation consumes and produces")
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 produces")
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 operation consumes and produces (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-
}
190142
}

modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)