use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class SwaggerReaderTest method testIssue207.
@Test
public void testIssue207() throws Exception {
String spec = "{\n" + " \"swagger\": \"2.0\",\n" + " \"paths\": {\n" + " \"/foo\": {\n" + " \"get\": {\n" + " \"parameters\": {},\n" + " \"responses\": {\n" + " \"200\": {\n" + " \"description\": \"successful operation\",\n" + " \"schema\": {\n" + " \"type\": \"array\",\n" + " \"items\": {\n" + " \"$ref\": \"#/definitions/Pet\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"definitions\": {\n" + " \"Pet\": {\n" + " \"type\": \"object\",\n" + " \"properties\": {\n" + " \"name\": {\n" + " \"type\": \"string\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(spec);
assertNotNull(result);
Response response = result.getSwagger().getPath("/foo").getGet().getResponses().get("200");
assertNotNull(response);
Property schema = response.getSchema();
assertTrue(schema instanceof ArrayProperty);
ArrayProperty ap = (ArrayProperty) schema;
assertTrue(ap.getItems() instanceof RefProperty);
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class SwaggerReaderTest method testIssue136.
@Test
public void testIssue136() {
String spec = "swagger: '2.0'\n" + "info:\n" + " title: issue 136\n" + "paths:\n" + " /foo:\n" + " get:\n" + " parameters: []\n" + " responses:\n" + " 200:\n" + " description: 'the pet'\n" + " schema:\n" + " $ref: 'http://petstore.swagger.io/v2/swagger.json#/definitions/Pet'";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(spec);
Swagger swagger = result.getSwagger();
Property property = swagger.getPath("/foo").getGet().getResponses().get("200").getSchema();
assertNotNull(property);
assertTrue(property instanceof RefProperty);
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class PropertyProcessorTest method testProcessRefProperty_ExternalRef.
@Test
public void testProcessRefProperty_ExternalRef() throws Exception {
expectCreationOfExternalRefProcessor();
final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
final RefProperty refProperty = new RefProperty(ref);
expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar");
new PropertyProcessor(cache, swagger).processProperty(refProperty);
new FullVerifications() {
{
}
};
assertEquals(refProperty.get$ref(), "#/definitions/bar");
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class PropertyProcessorTest method testProcessArrayProperty_ItemsIsRefProperty.
@Test
public void testProcessArrayProperty_ItemsIsRefProperty() throws Exception {
expectCreationOfExternalRefProcessor();
final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
final RefProperty refProperty = new RefProperty(ref);
ArrayProperty arrayProperty = new ArrayProperty();
arrayProperty.setItems(refProperty);
expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar");
new PropertyProcessor(cache, swagger).processProperty(arrayProperty);
new FullVerifications() {
{
}
};
assertEquals(((RefProperty) arrayProperty.getItems()).get$ref(), "#/definitions/bar");
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method propertyFromTypedObject.
public Property propertyFromTypedObject(ExtendedTypedObject obj) {
String type = obj.getType() == null ? null : obj.getType().toString();
String format = obj.getFormat() == null ? null : obj.getFormat().toString();
Property output = null;
if ("array".equals(type)) {
ArrayProperty am = new ArrayProperty();
Items items = obj.getItems();
if (items == null) {
LOGGER.error("Error! Missing array type for property! Assuming `object` -- please fix your spec");
items = new Items();
items.setType("object");
}
type = items.getType() == null ? null : items.getType().toString();
format = items.getFormat() == null ? null : items.getFormat().toString();
Map<PropertyBuilder.PropertyId, Object> args = new HashMap<>();
if (items.getExtraFields().get("enum") != null && items.getExtraFields().get("enum").isArray()) {
ArrayNode an = (ArrayNode) items.getExtraFields().get("enum");
List<String> enumValues = new ArrayList<>();
for (JsonNode jn : an) {
enumValues.add(jn.textValue());
}
args.put(PropertyBuilder.PropertyId.ENUM, enumValues);
}
Property innerType = PropertyBuilder.build(type, format, args);
if (innerType != null && !(innerType instanceof UntypedProperty)) {
am.setItems(innerType);
} else if (items.getRef() != null) {
am.setItems(new RefProperty(items.getRef()));
} else {
am.setItems(new RefProperty(type));
}
output = am;
} else {
Map<PropertyBuilder.PropertyId, Object> args = new HashMap<PropertyBuilder.PropertyId, Object>();
if (obj.getEnumValues() != null && obj.getEnumValues().size() > 0) {
args.put(PropertyBuilder.PropertyId.ENUM, obj.getEnumValues());
}
if (obj.getMinimum() != null) {
args.put(PropertyBuilder.PropertyId.MINIMUM, new BigDecimal(obj.getMinimum()));
}
if (obj.getMaximum() != null) {
args.put(PropertyBuilder.PropertyId.MAXIMUM, new BigDecimal(obj.getMaximum()));
}
Property i = PropertyBuilder.build(type, format, args);
if (i != null && !(i instanceof UntypedProperty)) {
output = i;
} else {
if (obj.getRef() != null) {
output = new RefProperty(obj.getRef());
} else if (type != null && !type.equals("void")) {
output = new RefProperty(type);
}
}
}
return output;
}
Aggregations