use of io.swagger.v3.oas.models.Operation 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);
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class SwaggerSerializerTest method writeSpecWithParameterReferences.
@Test(description = "it should write a spec with parameter references")
public void writeSpecWithParameterReferences() throws IOException {
final Schema personModel = ModelConverters.getInstance().read(Person.class).get("Person");
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 swagger = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel);
final QueryParameter parameter = (QueryParameter) new QueryParameter().name("id").description("a common get parameter").schema(new IntegerSchema());
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").operationId("get pet by id").addParametersItem(new Parameter().$ref("#/parameters/Foo"));
swagger.components(new Components().addParameters("Foo", parameter)).path("/pets", new PathItem().get(get));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
assertEquals(Json.pretty(rebuilt), Json.pretty(swagger));
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class SpecFilterTest method replaceGetResources.
@Test(description = "it should replace away with a new operation")
public void replaceGetResources() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
OpenAPI filter = new SpecFilter().filter(openAPI, new ReplaceGetOperationsFilter(), null, null, null);
assertOperations(filter, NEW_OPERATION_ID, NEW_OPERATION_DESCRIPTION);
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class SpecFilterTest method changeGetResources.
@Test(description = "it should change away with a new operation")
public void changeGetResources() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
OpenAPI filter = new SpecFilter().filter(openAPI, new ChangeGetOperationsFilter(), null, null, null);
assertOperations(filter, CHANGED_OPERATION_ID, CHANGED_OPERATION_DESCRIPTION);
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class Ticket2926Test method testExtensionsInMapDeserializeAndSerialize.
@Test
public void testExtensionsInMapDeserializeAndSerialize() throws Exception {
String yaml = "openapi: 3.0.1\n" + "info:\n" + " title: My title\n" + " description: API under test\n" + " version: 1.0.7\n" + " x-info: test\n" + "servers:\n" + "- url: http://localhost:9999/api\n" + " x-server: test\n" + " description: desc\n" + " variables: \n" + " serVar: \n" + " description: desc\n" + " x-serverVariable: test\n" + "paths:\n" + " /foo/bar:\n" + " get:\n" + " callbacks:\n" + " /foo/bar:\n" + " get:\n" + " description: getoperation\n" + " x-callback: test\n" + " responses:\n" + " default:\n" + " description: it works!\n" + " content:\n" + " application/json:\n" + " schema:\n" + " title: inline_response_200\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " x-mediatype: test\n" + " x-response: test\n" + " x-responses: test\n" + " x-responses-object: \n" + " aaa: bbb\n" + " x-responses-array: \n" + " - aaa\n" + " - bbb\n" + " x-operation: test\n" + " x-pathitem: test\n" + " x-paths: test\n" + "x-openapi-object: \n" + " aaa: bbb\n" + "x-openapi-array: \n" + " - aaa\n" + " - bbb\n" + "x-openapi: test";
OpenAPI aa = Yaml.mapper().readValue(yaml, OpenAPI.class);
SerializationMatchers.assertEqualsToYaml(aa, yaml);
}
Aggregations