use of io.swagger.models.properties.RefProperty in project swagger-core by swagger-api.
the class PostParamTest method findPostOperationWithObjectsCollection.
@Test(description = "find a Post operation with collection of objects")
public void findPostOperationWithObjectsCollection() {
Path petPath = getPath("collectionOfObjects");
assertNotNull(petPath);
Operation petPost = petPath.getPost();
assertNotNull(petPost);
assertEquals(petPost.getParameters().size(), 1);
BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
assertEquals(petPostBodyParam.getName(), BODY);
Model inputModel = petPostBodyParam.getSchema();
assertTrue(inputModel instanceof ArrayModel);
ArrayModel ap = (ArrayModel) inputModel;
Property inputSchema = ap.getItems();
assertTrue(inputSchema instanceof RefProperty);
RefProperty rm = (RefProperty) inputSchema;
assertEquals(rm.getSimpleRef(), PET);
}
use of io.swagger.models.properties.RefProperty in project swagger-core by swagger-api.
the class ChildTypeTest method testChildTypeResponse.
@Test(description = "Tests child type response schema ref is correctly set up")
public void testChildTypeResponse() {
Operation op = swagger.getPath("/childType/testChildTypeResponse").getGet();
Property schema = op.getResponses().get("200").getSchema();
assertEquals(schema.getClass().getName(), RefProperty.class.getName());
assertEquals(((RefProperty) schema).getSimpleRef(), "Sub1Bean");
}
use of io.swagger.models.properties.RefProperty in project swagger-core by swagger-api.
the class RefPropertyTest method identifyRefFormats.
@Test(description = "it should correctly identify ref formats")
public void identifyRefFormats() {
assertRefFormat(new RefProperty("http://my.company.com/models/model.json"), RefFormat.URL);
assertRefFormat(new RefProperty("http://my.company.com/models/model.json#/thing"), RefFormat.URL);
assertRefFormat(new RefProperty("./models/model.json"), RefFormat.RELATIVE);
assertRefFormat(new RefProperty("./models/model.json#/thing"), RefFormat.RELATIVE);
assertRefFormat(new RefProperty("#/definitions/foo"), RefFormat.INTERNAL);
assertRefFormat(new RefProperty("foo"), RefFormat.INTERNAL);
}
use of io.swagger.models.properties.RefProperty in project swagger-core by swagger-api.
the class RefPropertyTest method testEquals.
@Test
public void testEquals() {
final RefProperty prop1 = new RefProperty();
prop1.setName(PROP_1);
prop1.setRequired(true);
final RefProperty prop2 = new RefProperty();
prop2.setName(PROP_2);
assertNotEquals(prop1, prop2);
prop2.setName(PROP_1);
prop2.setRequired(true);
assertEquals(prop1, prop2);
}
use of io.swagger.models.properties.RefProperty in project herd by FINRAOS.
the class DefinitionGenerator method getPropertyFromType.
/**
* Gets a property from the given fieldType. This method may be called recursively.
*
* @param fieldType the field type class.
*
* @return the property.
* @throws MojoExecutionException if any problems were encountered.
*/
private Property getPropertyFromType(Class<?> fieldType) throws MojoExecutionException {
Property property;
if (String.class.isAssignableFrom(fieldType)) {
property = new StringProperty();
} else if (Integer.class.isAssignableFrom(fieldType) || int.class.isAssignableFrom(fieldType)) {
property = new IntegerProperty();
} else if (Long.class.isAssignableFrom(fieldType) || long.class.isAssignableFrom(fieldType)) {
property = new LongProperty();
} else if (BigDecimal.class.isAssignableFrom(fieldType)) {
property = new DecimalProperty();
} else if (XMLGregorianCalendar.class.isAssignableFrom(fieldType)) {
property = new DateTimeProperty();
} else if (Boolean.class.isAssignableFrom(fieldType) || boolean.class.isAssignableFrom(fieldType)) {
property = new BooleanProperty();
} else if (Collection.class.isAssignableFrom(fieldType)) {
property = new ArrayProperty(new StringProperty());
} else if (fieldType.getAnnotation(XmlEnum.class) != null) {
/*
* Enums are a string property which have enum constants
*/
List<String> enums = new ArrayList<>();
for (Enum<?> anEnum : (Enum<?>[]) fieldType.getEnumConstants()) {
enums.add(anEnum.name());
}
property = new StringProperty()._enum(enums);
} else /*
* Recursively process complex objects which is a XmlType
*/
if (fieldType.getAnnotation(XmlType.class) != null) {
processDefinitionClass(fieldType);
property = new RefProperty(fieldType.getAnnotation(XmlType.class).name());
} else {
// Default to a string property in other cases.
property = new StringProperty();
}
log.debug("Field type \"" + fieldType.getName() + "\" is a property type \"" + property.getType() + "\".");
return property;
}
Aggregations