Search in sources :

Example 81 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class ParameterSerializationTest method serializeEnumPathParameter.

@Test(description = "it should serialize a path parameter with enum")
public void serializeEnumPathParameter() {
    List<String> values = new ArrayList<>();
    values.add("a");
    values.add("b");
    values.add("c");
    Parameter p = new PathParameter().schema(new StringSchema()._enum(values));
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"schema\":{" + "      \"type\":\"string\"," + "       \"enum\":[\"a\",\"b\",\"c\"]" + "   }" + "}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : ArrayList(java.util.ArrayList) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 82 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class ParameterSerializationTest method serializeArrayQueryParameter.

@Test(description = "it should serialize a QueryParameter with array")
public void serializeArrayQueryParameter() {
    final Parameter p = new QueryParameter().schema(new ArraySchema().items(new StringSchema()));
    final String json = "{" + "   \"in\":\"query\"," + "   \"schema\":{" + "     \"type\":\"array\"," + "     \"items\":{" + "       \"type\":\"string\"" + "   }}" + "}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 83 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class ParameterSerializationTest method serializeStringArrayPathParameter.

@Test(description = "it should serialize a PathParameter with string array")
public void serializeStringArrayPathParameter() {
    Parameter p = new PathParameter().schema(new ArraySchema().items(new StringSchema()));
    final String json = "{\"in\":\"path\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}";
    SerializationMatchers.assertEqualsToJson(p, json);
    final String yaml = "---\n" + "in: \"path\"\n" + "required: true\n" + "schema:\n" + "  type: \"array\"\n" + "  items:\n" + "    type: \"string\"";
    SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 84 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class ParameterSerializationTest method serializeBodyParameter.

@Test(description = "it should serialize a BodyParameter")
public void serializeBodyParameter() {
    final Schema model = new Schema().title("Cat").addProperties("name", new StringSchema());
    final RequestBody p = new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(model)));
    final String json = "{\"content\":{\"*/*\":{\"schema\":{\"title\":\"Cat\",\"properties\":{\"name\":{\"type\":\"string\"}}}}}}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : Content(io.swagger.v3.oas.models.media.Content) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 85 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class ModelSerializerTest method testEnumParser.

@Test(description = "it retains enums per ")
public void testEnumParser() throws IOException {
    String json = "{\n" + "  \"properties\": {\n" + "    \"AdvStateType\": {\n" + "      \"description\": \"Advertising State\",\n" + "      \"enum\": [\n" + "        \"off\",\n" + "        \"on\"\n" + "      ],\n" + "      \"type\": \"string\"\n" + "    }\n" + "  }\n" + "}";
    final Schema model = Json.mapper().readValue(json, Schema.class);
    StringSchema p = (StringSchema) model.getProperties().get("AdvStateType");
    assertNotNull(p.getEnum());
    assertEquals(p.getEnum().get(0), "off");
    assertEquals(p.getEnum().get(1), "on");
}
Also used : DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Aggregations

StringSchema (io.swagger.v3.oas.models.media.StringSchema)89 Test (org.testng.annotations.Test)79 Schema (io.swagger.v3.oas.models.media.Schema)70 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)54 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)53 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)47 OpenAPI (io.swagger.v3.oas.models.OpenAPI)40 PathItem (io.swagger.v3.oas.models.PathItem)22 Operation (io.swagger.v3.oas.models.Operation)21 MediaType (io.swagger.v3.oas.models.media.MediaType)21 Content (io.swagger.v3.oas.models.media.Content)20 MapSchema (io.swagger.v3.oas.models.media.MapSchema)20 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)20 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)19 DateSchema (io.swagger.v3.oas.models.media.DateSchema)17 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)16 Components (io.swagger.v3.oas.models.Components)15 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)15 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)14