Search in sources :

Example 56 with StringProperty

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

the class ParameterSerializationTest method serializeStringArrayHeaderParameter.

@Test(description = "it should serialize a string array HeaderParameter")
public void serializeStringArrayHeaderParameter() {
    final HeaderParameter p = new HeaderParameter().type(ArrayProperty.TYPE).property(new StringProperty()).collectionFormat("multi");
    final String json = "{\"in\":\"header\",\"required\":false,\"type\":\"string\",\"collectionFormat\":\"multi\"}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 57 with StringProperty

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

the class ParameterSerializationTest method serializeBodyParameter.

@Test(description = "it should serialize a BodyParameter")
public void serializeBodyParameter() {
    final ModelImpl model = new ModelImpl().name("Cat").property("name", new StringProperty());
    final BodyParameter p = new BodyParameter().schema(model);
    final String json = "{" + "   \"in\":\"body\"," + "   \"required\":false," + "   \"schema\":{" + "      \"properties\":{" + "         \"name\":{" + "            \"type\":\"string\"" + "         }" + "      }" + "   }" + "}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) ModelImpl(io.swagger.models.ModelImpl) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 58 with StringProperty

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

the class PostParamTest method findAPostOperationWithStringsList.

@Test(description = "find a Post operation with list of strings")
public void findAPostOperationWithStringsList() {
    Path petPath = getPath("listOfStrings");
    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 StringProperty);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 59 with StringProperty

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

the class AbstractSerializableParameter method setProperty.

public void setProperty(Property property) {
    setType(property.getType());
    this.format = property.getFormat();
    if (property instanceof StringProperty) {
        final StringProperty string = (StringProperty) property;
        setEnum(string.getEnum());
    } else if (property instanceof IntegerProperty) {
        setEnumValue(((IntegerProperty) property).getEnum());
    } else if (property instanceof LongProperty) {
        setEnumValue(((LongProperty) property).getEnum());
    } else if (property instanceof FloatProperty) {
        setEnumValue(((FloatProperty) property).getEnum());
    } else if (property instanceof DoubleProperty) {
        setEnumValue(((DoubleProperty) property).getEnum());
    } else if (property instanceof ArrayProperty) {
        final ArrayProperty array = (ArrayProperty) property;
        setItems(array.getItems());
    }
}
Also used : BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) StringProperty(io.swagger.models.properties.StringProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty)

Example 60 with StringProperty

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

the class TestProperty method testStringProperty.

@Test
public void testStringProperty() {
    SwaggerGenerator generator = new SwaggerGeneratorForTest(context, null);
    List<String> enums = Arrays.asList("testStringProperty_a", "testStringProperty_b");
    StringProperty sp = new StringProperty();
    sp._enum(enums);
    StringPropertyConverter spc = new StringPropertyConverter();
    JavaType jt = spc.convert(generator.getClassLoader(), generator.ensureGetPackageName(), generator.getSwagger(), sp);
    StringProperty spNew = (StringProperty) ModelConverters.getInstance().readAsProperty(jt);
    Assert.assertEquals(enums, spNew.getEnum());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) StringProperty(io.swagger.models.properties.StringProperty) StringPropertyConverter(io.servicecomb.swagger.converter.property.StringPropertyConverter) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) Test(org.junit.Test)

Aggregations

StringProperty (io.swagger.models.properties.StringProperty)60 Test (org.testng.annotations.Test)47 Property (io.swagger.models.properties.Property)29 ArrayProperty (io.swagger.models.properties.ArrayProperty)21 Model (io.swagger.models.Model)20 IntegerProperty (io.swagger.models.properties.IntegerProperty)16 LongProperty (io.swagger.models.properties.LongProperty)16 RefProperty (io.swagger.models.properties.RefProperty)16 DoubleProperty (io.swagger.models.properties.DoubleProperty)14 ModelImpl (io.swagger.models.ModelImpl)9 FloatProperty (io.swagger.models.properties.FloatProperty)9 BooleanProperty (io.swagger.models.properties.BooleanProperty)8 ApiModelProperty (io.swagger.annotations.ApiModelProperty)7 BodyParameter (io.swagger.models.parameters.BodyParameter)7 MapProperty (io.swagger.models.properties.MapProperty)7 Operation (io.swagger.models.Operation)6 Path (io.swagger.models.Path)6 PathParameter (io.swagger.models.parameters.PathParameter)6 ObjectProperty (io.swagger.models.properties.ObjectProperty)6 QueryParameter (io.swagger.models.parameters.QueryParameter)5