Search in sources :

Example 1 with ByteArrayProperty

use of io.swagger.models.properties.ByteArrayProperty in project swagger-core by swagger-api.

the class ByteConverterTest method testByteProperty.

@Test
public void testByteProperty() {
    Model model = new ModelImpl().property("byteProperty", new ByteArrayProperty());
    assertEquals(Json.pretty(model), "{" + NEWLINE + "  \"properties\" : {" + NEWLINE + "    \"byteProperty\" : {" + NEWLINE + "      \"type\" : \"string\"," + NEWLINE + "      \"format\" : \"byte\"" + NEWLINE + "    }" + NEWLINE + "  }" + NEWLINE + "}");
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 2 with ByteArrayProperty

use of io.swagger.models.properties.ByteArrayProperty in project swagger-core by swagger-api.

the class JsonDeserializationTest method testDeserializeConstrainedBase64StringProperty.

@Test(description = "should deserialize a base64 encoded string property with constraints")
public void testDeserializeConstrainedBase64StringProperty() throws Exception {
    Swagger swagger = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", Swagger.class);
    ByteArrayProperty property = (ByteArrayProperty) swagger.getDefinitions().get("Health").getProperties().get("string_base64_encoded");
    assertEquals(property.getMinLength(), Integer.valueOf(5));
    assertEquals(property.getMaxLength(), Integer.valueOf(50));
    assertEquals(property.getPattern(), "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$");
    assertNull(property.getEnum());
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) Test(org.testng.annotations.Test)

Example 3 with ByteArrayProperty

use of io.swagger.models.properties.ByteArrayProperty in project swagger-parser by swagger-api.

the class SwaggerParserTest method testIssue75.

@Test
public void testIssue75() {
    SwaggerParser parser = new SwaggerParser();
    final Swagger swagger = parser.read("src/test/resources/issue99.json");
    BodyParameter param = (BodyParameter) swagger.getPaths().get("/albums").getPost().getParameters().get(0);
    Model model = param.getSchema();
    assertNotNull(model);
    assertTrue(model instanceof ArrayModel);
    ArrayModel am = (ArrayModel) model;
    assertTrue(am.getItems() instanceof ByteArrayProperty);
    assertEquals(am.getItems().getFormat(), "byte");
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) ArrayModel(io.swagger.models.ArrayModel) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 4 with ByteArrayProperty

use of io.swagger.models.properties.ByteArrayProperty in project java-chassis by ServiceComb.

the class TestArrayType method test.

@Test
public void test() {
    SwaggerOperations swaggerOperations = SwaggerOperations.generate(ArrayType.class);
    SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testBytes");
    BodyParameter bodyParameter = (BodyParameter) swaggerOperation.getOperation().getParameters().get(0);
    ModelImpl model = SwaggerUtils.getModelImpl(swaggerOperations.getSwagger(), bodyParameter);
    Assert.assertEquals(ModelImpl.OBJECT, model.getType());
    Assert.assertEquals(1, model.getProperties().size());
    ByteArrayProperty byteArrayProperty = (ByteArrayProperty) model.getProperties().get("value");
    Assert.assertEquals("string", byteArrayProperty.getType());
    Assert.assertEquals("byte", byteArrayProperty.getFormat());
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) SwaggerOperations(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations) SwaggerOperation(org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test)

Aggregations

ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)4 Test (org.testng.annotations.Test)3 Model (io.swagger.models.Model)2 ModelImpl (io.swagger.models.ModelImpl)2 BodyParameter (io.swagger.models.parameters.BodyParameter)2 ArrayModel (io.swagger.models.ArrayModel)1 ComposedModel (io.swagger.models.ComposedModel)1 RefModel (io.swagger.models.RefModel)1 Swagger (io.swagger.models.Swagger)1 SwaggerOperation (org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation)1 SwaggerOperations (org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations)1 Test (org.junit.Test)1