use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.
the class ParameterDeSerializationTest method testIssue1765.
@Test(description = "should serialize correctly typed numeric enums")
public void testIssue1765() throws Exception {
String yaml = "openapi: '3.0.1'\n" + "paths:\n" + " /test:\n" + " get:\n" + " parameters:\n" + " - name: \"days\"\n" + " in: \"path\"\n" + " required: true\n" + " schema:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - 3\n" + " - 4\n" + " - 5\n" + " responses:\n" + " default:\n" + " description: great";
OpenAPI swagger = Yaml.mapper().readValue(yaml, OpenAPI.class);
SerializationMatchers.assertEqualsToYaml(swagger, yaml);
}
use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.
the class JsonDeserializationTest method testNullExampleDeserialization.
@Test
public void testNullExampleDeserialization() throws Exception {
String yamlNull = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " description: Operation Description\n" + " operationId: operationId\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: string\n" + " example: null\n";
String yamlMissing = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " description: Operation Description\n" + " operationId: operationId\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: string\n";
OpenAPI oas = Yaml.mapper().readValue(yamlNull, OpenAPI.class);
Yaml.prettyPrint(oas);
assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
assertTrue(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
oas = Yaml.mapper().readValue(yamlMissing, OpenAPI.class);
Yaml.prettyPrint(oas);
assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
assertFalse(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
Yaml.prettyPrint(oas);
}
use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.
the class JsonDeserializationTest method testDeserializeAPathRef.
@Test
public void testDeserializeAPathRef() throws Exception {
final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/pathRef.json", OpenAPI.class);
final PathItem petPath = oas.getPaths().get("/pet");
assertNotNull(petPath.get$ref());
assertEquals(petPath.get$ref(), "http://my.company.com/paths/health.json");
assertTrue(oas.getPaths().get("/user") instanceof PathItem);
}
use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.
the class JsonDeserializationTest method testNullEnumItem.
@Test(description = "Deserialize null enum item")
public void testNullEnumItem() throws Exception {
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " tags:\n" + " - MyTag\n" + " summary: Operation Summary\n" + " description: Operation Description\n" + " operationId: operationId\n" + " parameters:\n" + " - name: subscriptionId\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: integer\n" + " description: some int values with null\n" + " format: int32\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - null\n";
OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList(1, 2, null));
yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " tags:\n" + " - MyTag\n" + " summary: Operation Summary\n" + " description: Operation Description\n" + " operationId: operationId\n" + " parameters:\n" + " - name: subscriptionId\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: string\n" + " description: some int values with null\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - null\n";
oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList("1", "2", null));
}
use of io.swagger.v3.oas.models.Paths 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 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 Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "value");
info.addExtension("x-test2", map);
info.addExtension("x-test", "value");
final OpenAPI swagger = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel).schema("Error", errorModel);
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").addTagsItem("Pet Operations").operationId("get pet by id").deprecated(true);
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("application/json", new MediaType().schema(new Schema().$ref("Person")).example("fun")));
final ApiResponse errorResponse = new ApiResponse().description("error response").addLink("myLink", new Link().description("a link").operationId("theLinkedOperationId").addParameter("userId", "gah")).content(new Content().addMediaType("application/json", new MediaType().schema(new Schema().$ref("Error"))));
get.responses(new ApiResponses().addApiResponse("200", response).addApiResponse("default", errorResponse));
final Operation post = new Operation().summary("adds a new pet").description("you can add a new pet this way").addTagsItem("Pet Operations").operationId("add pet").responses(new ApiResponses().addApiResponse("default", errorResponse)).requestBody(new RequestBody().description("the pet to add").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Person")))));
swagger.paths(new Paths().addPathItem("/pets", new PathItem().get(get).post(post)));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
Json.prettyPrint(swagger);
final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
}
Aggregations