Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for issue #799 returning ref as internal #801

Merged
merged 3 commits into from Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -44,6 +44,7 @@
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.models.properties.UntypedProperty;
import io.swagger.models.refs.RefFormat;
import io.swagger.models.resourcelisting.ApiInfo;
import io.swagger.models.resourcelisting.ApiKeyAuthorization;
import io.swagger.models.resourcelisting.ApiListingReference;
Expand Down Expand Up @@ -346,9 +347,9 @@ public Model modelFromExtendedTypedObject(ExtendedTypedObject obj) {
am.setItems(innerType);
}
if (items.getRef() != null) {
am.setItems(new RefProperty(items.getRef()));
am.setItems(new RefProperty(items.getRef(),RefFormat.INTERNAL));
} else {
am.setItems(new RefProperty(type));
am.setItems(new RefProperty(type,RefFormat.INTERNAL));
}
output = am;
} else {
Expand Down Expand Up @@ -394,9 +395,9 @@ public Property propertyFromTypedObject(ExtendedTypedObject obj) {
if (innerType != null && !(innerType instanceof UntypedProperty)) {
am.setItems(innerType);
} else if (items.getRef() != null) {
am.setItems(new RefProperty(items.getRef()));
am.setItems(new RefProperty(items.getRef(),RefFormat.INTERNAL));
} else {
am.setItems(new RefProperty(type));
am.setItems(new RefProperty(type,RefFormat.INTERNAL));
}
output = am;
} else {
Expand All @@ -416,9 +417,9 @@ public Property propertyFromTypedObject(ExtendedTypedObject obj) {
output = i;
} else {
if (obj.getRef() != null) {
output = new RefProperty(obj.getRef());
output = new RefProperty(obj.getRef(),RefFormat.INTERNAL);
} else if (type != null && !type.equals("void")) {
output = new RefProperty(type);
output = new RefProperty(type,RefFormat.INTERNAL);
}
}
}
Expand Down Expand Up @@ -473,16 +474,16 @@ public Operation convertOperation(String tag, io.swagger.models.apideclaration.O

Model responseModel = null;
if (message.getResponseModel() != null) {
response.schema(new RefProperty(message.getResponseModel()));
response.setResponseSchema(new RefModel().asDefault(message.getResponseModel()));
}
output.response(message.getCode(), response);
}

// default response type
Property responseProperty = propertyFromTypedObject(operation);
Model responseProperty = modelFromExtendedTypedObject(operation);
Response response = new Response()
.description("success")
.schema(responseProperty);
.responseSchema(responseProperty);
if (output.getResponses() == null) {
output.defaultResponse(response);
} else if (responseProperty != null) {
Expand Down
Expand Up @@ -14,11 +14,13 @@
import io.swagger.models.auth.In;
import io.swagger.models.auth.OAuth2Definition;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.parameters.BodyParameter;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.parameters.PathParameter;
import io.swagger.models.parameters.QueryParameter;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.parser.SwaggerCompatConverter;
import io.swagger.parser.SwaggerParser;
Expand All @@ -30,6 +32,7 @@
import org.junit.Assert;
import org.testng.annotations.Test;

import javax.validation.constraints.AssertFalse;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -258,4 +261,25 @@ public void testIssue104() throws Exception {

assertEquals(actual, expected);
}

@Test
public void testIssue799() throws Exception {

Swagger swagger = converter.read("src/test/resources/specs/v1_2/issue799.json");
Assert.assertEquals( swagger.getPaths().get("/api/v1beta3/namespaces/{namespaces}/bindings").getPost().getResponses().get("200").getResponseSchema().getReference(), "#/definitions/v1beta3.Binding");
Parameter bodyParameter = swagger.getPaths().get("/api/v1beta3/namespaces/{namespaces}/bindings").getPost().getParameters().get(1);
Assert.assertEquals( bodyParameter.getName(), "body");
Assert.assertTrue( bodyParameter instanceof BodyParameter);
Assert.assertEquals( ((BodyParameter)bodyParameter).getSchema().getReference(), "#/definitions/v1beta3.Binding");
Assert.assertEquals( swagger.getPaths().get("/api/v1beta3/namespaces/{namespaces}/componentstatuses/{name}").getGet().getResponses().get("200").getResponseSchema().getReference(), "#/definitions/v1beta3.ComponentStatus");
Assert.assertEquals( swagger.getPaths().get("/api/v1beta3/namespaces/{namespaces}/componentstatuses").getGet().getResponses().get("200").getResponseSchema().getReference(), "#/definitions/v1beta3.ComponentStatusList");
Property conditionsProperty = swagger.getDefinitions().get("v1beta3.ComponentStatus").getProperties().get("conditions");
Assert.assertTrue( conditionsProperty instanceof ArrayProperty);
Property items = ((ArrayProperty)conditionsProperty).getItems();
Assert.assertTrue( items instanceof RefProperty);
Assert.assertEquals( ((RefProperty)items).get$ref(), "#/definitions/v1beta3.ObjectReference");
Property metadataProperty = swagger.getDefinitions().get("v1beta3.ComponentStatus").getProperties().get("metadata");
Assert.assertTrue( metadataProperty instanceof RefProperty);
Assert.assertEquals( ((RefProperty)metadataProperty).get$ref(), "#/definitions/v1beta3.ObjectMeta");
}
}