Fix for issue 765
@@ -80,6 +80,7 @@ public class SwaggerConverter implements SwaggerParserExtension {
private List<String> globalConsumes = new ArrayList<>();
private List<String> globalProduces = new ArrayList<>();
private Components components = new Components();
+ private Map<String, io.swagger.models.parameters.Parameter> globalV2Parameters = new HashMap<>();
@Override
public SwaggerParseResult readLocation(String url, List<AuthorizationValue> auths, ParseOptions options) {
@@ -185,6 +186,7 @@ public class SwaggerConverter implements SwaggerParserExtension {
}
if (swagger.getParameters() != null) {
+ globalV2Parameters.putAll(swagger.getParameters());
swagger.getParameters().forEach((k, v) -> {
if ("body".equals(v.getIn())) {
components.addRequestBodies(k, convertParameterToRequestBody(v));
@@ -510,6 +512,16 @@ public class SwaggerConverter implements SwaggerParserExtension {
return v3Path;
}
+ private boolean isRefABodyParam(io.swagger.models.parameters.Parameter param) {
+ if (param instanceof RefParameter) {
+ RefParameter refParameter = (RefParameter) param;
+ String simpleRef = refParameter.getSimpleRef();
+ io.swagger.models.parameters.Parameter parameter = globalV2Parameters.get(simpleRef);
+ return "body".equals(parameter.getIn());
+ }
+ return false;
+ }
+
public Operation convert(io.swagger.models.Operation v2Operation) {
Operation operation = new Operation();
if (StringUtils.isNotBlank(v2Operation.getDescription())) {
@@ -534,11 +546,12 @@ public class SwaggerConverter implements SwaggerParserExtension {
} else {
Parameter convert = convert(param);
String $ref = convert.get$ref();
- if ($ref != null && $ref.startsWith("#/components/requestBodies/")) {
+ if ($ref != null && $ref.startsWith("#/components/requestBodies/") && isRefABodyParam(param)) {
operation.setRequestBody(new RequestBody().$ref($ref));
} else {
operation.addParametersItem(convert);
}
+ //operation.addParametersItem(convert(param));
}
}
