Search in sources :

Example 21 with StringProperty

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

the class ArrayModelTest method testClone.

@Test
public void testClone() {
    // given
    instance.setProperties(new HashMap<String, Property>());
    instance.setType("type");
    instance.setDescription("description");
    instance.setItems(new StringProperty());
    instance.setExample(new Object());
    // when
    ArrayModel cloned = (ArrayModel) instance.clone();
    // then
    assertEquals(instance.getProperties(), cloned.getProperties(), "The instance and the clone must have the same properties value");
    assertEquals(instance.getType(), cloned.getType(), "The instance and the clone must have the same type value");
    assertEquals(instance.getDescription(), cloned.getDescription(), "The instance and the clone must have the same description value");
    assertEquals(instance.getExample(), cloned.getExample(), "The instance and the clone must have the same example value");
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 22 with StringProperty

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

the class SwaggerSerializerTest method convertSpec.

@Test(description = "it should convert a spec")
public void convertSpec() throws IOException {
    final Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
    final Model errorModel = ModelConverters.getInstance().read(Error.class).get("Error");
    final Info info = new Info().version("1.0.0").title("Swagger Petstore");
    final Contact contact = new Contact().name("Swagger API Team").email("foo@bar.baz").url("http://swagger.io");
    info.setContact(contact);
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put("name", "value");
    info.setVendorExtension("x-test2", map);
    info.setVendorExtension("x-test", "value");
    final Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").securityDefinition("api-key", new ApiKeyAuthDefinition("key", In.HEADER)).scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
    final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id").deprecated(true);
    get.parameter(new QueryParameter().name("tags").description("tags to filter by").required(false).property(new StringProperty()));
    get.parameter(new PathParameter().name("petId").description("pet to fetch").property(new LongProperty()));
    final Response response = new Response().description("pets returned").schema(new RefProperty().asDefault("Person")).example("application/json", "fun!");
    final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
    get.response(200, response).defaultResponse(errorResponse);
    final Operation post = new Operation().summary("adds a new pet").description("you can add a new pet this way").tag("Pet Operations").operationId("add pet").defaultResponse(errorResponse).parameter(new BodyParameter().description("the pet to add").schema(new RefModel().asDefault("Person")));
    swagger.path("/pets", new Path().get(get).post(post));
    final String swaggerJson = Json.mapper().writeValueAsString(swagger);
    final Swagger rebuilt = Json.mapper().readValue(swaggerJson, Swagger.class);
    SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
}
Also used : Path(io.swagger.models.Path) QueryParameter(io.swagger.models.parameters.QueryParameter) RefModel(io.swagger.models.RefModel) HashMap(java.util.HashMap) Error(io.swagger.models.Error) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Contact(io.swagger.models.Contact) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) Swagger(io.swagger.models.Swagger) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) Person(io.swagger.models.Person) Test(org.testng.annotations.Test)

Example 23 with StringProperty

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

the class XMLGregorianCalendarTest method testXMLGregorianCalendar.

@Test(description = "it should read a model with XMLGregorianCalendar")
public void testXMLGregorianCalendar() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(ModelWithCalendar.class);
    // don't create a Joda DateTime object
    assertEquals(models.size(), 1);
    final Map<String, Property> properties = models.get("ModelWithCalendar").getProperties();
    final Property nameProperty = properties.get("name");
    assertTrue(nameProperty instanceof StringProperty);
    assertEquals((int) nameProperty.getPosition(), 2);
    assertEquals(nameProperty.getDescription(), "name of the model");
    final Property dateTimeProperty = properties.get("createdAt");
    assertTrue(dateTimeProperty instanceof DateTimeProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
}
Also used : DateTimeProperty(io.swagger.models.properties.DateTimeProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 24 with StringProperty

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

the class ModelConverterTest method serializeParameterizedType.

@Test(description = "it should serialize a parameterized type per 606")
public void serializeParameterizedType() {
    final Map<String, Model> schemas = readAll(Employee.class);
    final ModelImpl employee = (ModelImpl) schemas.get("employee");
    final Map<String, Property> props = employee.getProperties();
    final Iterator<String> et = props.keySet().iterator();
    final Property id = props.get(et.next());
    assertTrue(id instanceof IntegerProperty);
    final Property firstName = props.get(et.next());
    assertTrue(firstName instanceof StringProperty);
    final Property lastName = props.get(et.next());
    assertTrue(lastName instanceof StringProperty);
    final Property department = props.get(et.next());
    assertTrue(department instanceof RefProperty);
    final Property manager = props.get(et.next());
    assertTrue(manager instanceof RefProperty);
    final Property team = props.get(et.next());
    assertTrue(team instanceof ArrayProperty);
    final ArrayProperty ap = (ArrayProperty) team;
    assertTrue(ap.getUniqueItems());
    assertNotNull(employee.getXml());
    assertEquals(employee.getXml().getName(), "employee");
}
Also used : BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) AbstractModelWithApiModel(io.swagger.models.composition.AbstractModelWithApiModel) Model(io.swagger.models.Model) ModelWithApiModel(io.swagger.models.ModelWithApiModel) EmptyModel(io.swagger.models.EmptyModel) JodaDateTimeModel(io.swagger.models.JodaDateTimeModel) JacksonReadonlyModel(io.swagger.models.JacksonReadonlyModel) StringProperty(io.swagger.models.properties.StringProperty) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) ModelWithUrlProperty(io.swagger.models.composition.ModelWithUrlProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 25 with StringProperty

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

the class ModelExampleTest method createModel.

@Test(description = "it should create a model")
public void createModel() {
    ModelImpl model = new ModelImpl().property("name", new StringProperty().example("Tony")).property("id", new LongProperty().example(123L));
    assertNotNull(model);
}
Also used : LongProperty(io.swagger.models.properties.LongProperty) StringProperty(io.swagger.models.properties.StringProperty) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.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