use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ParameterProcessorTest method implicitParameterProcessorTest.
@Test(description = "parse implicit parameters from method")
public void implicitParameterProcessorTest() throws NoSuchMethodException {
final ApiImplicitParams params = getClass().getDeclaredMethod("implicitParametrizedMethod").getAnnotation(ApiImplicitParams.class);
final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), String.class, Collections.<Annotation>singletonList(params.value()[0]));
assertNotNull(param0);
assertEquals(param0.getIn(), "path");
assertEquals(param0.getName(), "paramName1");
assertEquals(param0.getDescription(), "paramValue1");
assertNull(param0.getEnum());
assertNotNull(param0.getItems());
final BodyParameter param1 = (BodyParameter) ParameterProcessor.applyAnnotations(null, new BodyParameter(), String.class, Collections.<Annotation>singletonList(params.value()[1]));
assertNotNull(param1);
assertEquals(param1.getIn(), "body");
assertEquals(param1.getName(), "body");
assertEquals(param1.getDescription(), "paramValue2");
assertEquals(param1.getAccess(), "test");
final ModelImpl model = (ModelImpl) param1.getSchema();
assertNotNull(model);
assertEquals(model.getDefaultValue(), "10");
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelConverterTest method setReadOnly.
@Test(description = "it should set readOnly per #854")
public void setReadOnly() {
final Map<String, Model> schemas = readAll(JacksonReadonlyModel.class);
final ModelImpl model = (ModelImpl) schemas.get("JacksonReadonlyModel");
final Property prop = model.getProperties().get("count");
assertTrue(prop.getReadOnly());
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelConverterTest method processModelWithPairProperties.
@Test(description = "it should process a model with org.apache.commons.lang3.tuple.Pair properties")
public void processModelWithPairProperties() {
final ModelWithTuple2.TupleAsMapModelConverter asMapConverter = new ModelWithTuple2.TupleAsMapModelConverter(Json.mapper());
ModelConverters.getInstance().addConverter(asMapConverter);
final Map<String, Model> asMap = readAll(ModelWithTuple2.class);
ModelConverters.getInstance().removeConverter(asMapConverter);
assertEquals(asMap.size(), 4);
for (String item : Arrays.asList("MapOfString", "MapOfComplexLeft")) {
ModelImpl model = (ModelImpl) asMap.get(item);
assertEquals(model.getType(), "object");
assertNull(model.getProperties());
assertNotNull(model.getAdditionalProperties());
}
final ModelWithTuple2.TupleAsMapPropertyConverter asPropertyConverter = new ModelWithTuple2.TupleAsMapPropertyConverter(Json.mapper());
ModelConverters.getInstance().addConverter(asPropertyConverter);
final Map<String, Model> asProperty = readAll(ModelWithTuple2.class);
ModelConverters.getInstance().removeConverter(asPropertyConverter);
assertEquals(asProperty.size(), 2);
for (Map.Entry<String, Property> entry : asProperty.get("ModelWithTuple2").getProperties().entrySet()) {
String name = entry.getKey();
Property property = entry.getValue();
if ("timesheetStates".equals(name)) {
assertEquals(property.getClass(), MapProperty.class);
} else if ("manyPairs".equals(name)) {
assertEquals(property.getClass(), ArrayProperty.class);
Property items = ((ArrayProperty) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapProperty.class);
Property stringProperty = ((MapProperty) items).getAdditionalProperties();
assertNotNull(stringProperty);
assertEquals(stringProperty.getClass(), StringProperty.class);
} else if ("complexLeft".equals(name)) {
assertEquals(property.getClass(), ArrayProperty.class);
Property items = ((ArrayProperty) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapProperty.class);
Property additionalProperty = ((MapProperty) items).getAdditionalProperties();
assertNotNull(additionalProperty);
assertEquals(additionalProperty.getClass(), RefProperty.class);
assertEquals(((RefProperty) additionalProperty).getSimpleRef(), "ComplexLeft");
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelPropertyTest method testReadOnlyProperty.
@Test
public void testReadOnlyProperty() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(ReadOnlyFields.class);
ModelImpl model = (ModelImpl) models.get("ReadOnlyFields");
assertTrue(model.getProperties().get("id").getReadOnly());
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ByteConverterTest method testByteArray.
@Test
public void testByteArray() {
Model model = new ModelImpl().property("byteArray", new ArrayProperty(new BinaryProperty()));
assertEquals(Json.pretty(model), "{" + NEWLINE + " \"properties\" : {" + NEWLINE + " \"byteArray\" : {" + NEWLINE + " \"type\" : \"array\"," + NEWLINE + " \"items\" : {" + NEWLINE + " \"type\" : \"string\"," + NEWLINE + " \"format\" : \"binary\"" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + "}");
}
Aggregations