use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class SecurityDefinitionTest method createModelWithSecurityRequirements.
@Test(description = "it should create a model with security requirements")
public void createModelWithSecurityRequirements() throws IOException {
final Schema personModel = ModelConverters.getInstance().read(Person.class).get("Person");
final Schema 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 OpenAPI oas = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel).schema("Error", errorModel);
oas.schemaRequirement("githubAccessCode", new SecurityScheme().flows(new OAuthFlows().authorizationCode(new OAuthFlow().scopes(new Scopes().addString("user:email", "Grants read access to a user’s email addresses.")))));
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").addTagsItem("Pet Operations").operationId("get pet by id");
get.addParametersItem(new Parameter().in("query").name("tags").description("tags to filter by").required(false).schema(new StringSchema()));
get.addParametersItem(new Parameter().in("path").name("petId").description("pet to fetch").schema(new IntegerSchema().format("int64")));
final ApiResponse response = new ApiResponse().description("pets returned").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Person"))));
final ApiResponse errorResponse = new ApiResponse().description("error response").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Error"))));
get.responses(new ApiResponses().addApiResponse("200", response).addApiResponse("default", errorResponse)).addSecurityItem(new SecurityRequirement().addList("internal_oauth2", "user:email")).addSecurityItem(new SecurityRequirement().addList("api_key"));
oas.path("/pets", new PathItem().get(get));
final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json");
SerializationMatchers.assertEqualsToJson(oas, json);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeEnumStringProperty.
@Test(description = "it should serialize a StringProperty with enums")
public void serializeEnumStringProperty() throws IOException {
final StringSchema p = new StringSchema();
p._enum(new ArrayList<String>() {
{
this.add("a");
this.add("b");
}
});
final String json = "{\"type\":\"string\",\"enum\":[\"a\",\"b\"]}";
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializePathParameter.
@Test(description = "it should serialize a PathParameter")
public void serializePathParameter() {
final Parameter p = new PathParameter().schema(new StringSchema());
final String json = "{\"in\":\"path\",\"required\":true,\"schema\":{\"type\":\"string\"}}";
SerializationMatchers.assertEqualsToJson(p, json);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeHeaderParameter.
@Test(description = "it should it should serialize a HeaderParameter")
public void serializeHeaderParameter() {
final Parameter p = new HeaderParameter().schema(new StringSchema());
final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"string\"}}";
SerializationMatchers.assertEqualsToJson(p, json);
final String yaml = "---\n" + "in: \"header\"\n" + "schema:\n" + " type: \"string\"";
SerializationMatchers.assertEqualsToYaml(p, yaml);
}
use of io.swagger.v3.oas.models.media.StringSchema 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 Parameter p = new HeaderParameter().schema(new ArraySchema().items(new StringSchema()));
final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}";
SerializationMatchers.assertEqualsToJson(p, json);
}
Aggregations