use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testSerializePetstore.
@Test
public void testSerializePetstore() throws Exception {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1.yaml");
final OpenAPI swagger = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(swagger);
assertEquals(swagger.getInfo().getLicense().getIdentifier(), "test");
SerializationMatchers.assertEqualsToYaml31(swagger, "openapi: 3.1.0\n" + "info:\n" + " title: Swagger Petstore\n" + " license:\n" + " name: MIT\n" + " identifier: test\n" + " version: 1.0.0\n" + "servers:\n" + "- url: http://petstore.swagger.io/v1\n" + "paths:\n" + " /pets:\n" + " get:\n" + " tags:\n" + " - pets\n" + " summary: List all pets\n" + " operationId: listPets\n" + " parameters:\n" + " - name: limit\n" + " in: query\n" + " description: How many items to return at one time (max 100)\n" + " required: false\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " responses:\n" + " \"200\":\n" + " description: An paged array of pets\n" + " headers:\n" + " x-next:\n" + " description: A link to the next page of responses\n" + " schema:\n" + " type: string\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Pets'\n" + " default:\n" + " description: unexpected error\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Error'\n" + " post:\n" + " tags:\n" + " - pets\n" + " summary: Create a pet\n" + " operationId: createPets\n" + " responses:\n" + " \"201\":\n" + " description: Null response\n" + " default:\n" + " description: unexpected error\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Error'\n" + " /pets/{petId}:\n" + " get:\n" + " tags:\n" + " - pets\n" + " summary: Info for a specific pet\n" + " operationId: showPetById\n" + " parameters:\n" + " - name: petId\n" + " in: path\n" + " description: The id of the pet to retrieve\n" + " required: true\n" + " schema:\n" + " type: string\n" + " responses:\n" + " \"200\":\n" + " description: Expected response to a valid request\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Pets'\n" + " default:\n" + " description: unexpected error\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Error'\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " required:\n" + " - id\n" + " - name\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type:\n" + " - string\n" + " - integer\n" + " tag:\n" + " type: string\n" + " Pets:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/Pet'\n" + " Error:\n" + " required:\n" + " - code\n" + " - message\n" + " properties:\n" + " code:\n" + " type: integer\n" + " format: int32\n" + " message:\n" + " type: string\n" + "webhooks:\n" + " newPet:\n" + " post:\n" + " requestBody:\n" + " description: Information about a new pet in the system\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Pet'\n" + " responses:\n" + " \"200\":\n" + " description: Return a 200 status to indicate that the data was received\n" + " successfully");
SerializationMatchers.assertEqualsToJson31(swagger, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"info\" : {\n" + " \"title\" : \"Swagger Petstore\",\n" + " \"license\" : {\n" + " \"name\" : \"MIT\",\n" + " \"identifier\" : \"test\"\n" + " },\n" + " \"version\" : \"1.0.0\"\n" + " },\n" + " \"servers\" : [ {\n" + " \"url\" : \"http://petstore.swagger.io/v1\"\n" + " } ],\n" + " \"paths\" : {\n" + " \"/pets\" : {\n" + " \"get\" : {\n" + " \"tags\" : [ \"pets\" ],\n" + " \"summary\" : \"List all pets\",\n" + " \"operationId\" : \"listPets\",\n" + " \"parameters\" : [ {\n" + " \"name\" : \"limit\",\n" + " \"in\" : \"query\",\n" + " \"description\" : \"How many items to return at one time (max 100)\",\n" + " \"required\" : false,\n" + " \"schema\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int32\"\n" + " }\n" + " } ],\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"An paged array of pets\",\n" + " \"headers\" : {\n" + " \"x-next\" : {\n" + " \"description\" : \"A link to the next page of responses\",\n" + " \"schema\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " },\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Pets\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"default\" : {\n" + " \"description\" : \"unexpected error\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Error\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"post\" : {\n" + " \"tags\" : [ \"pets\" ],\n" + " \"summary\" : \"Create a pet\",\n" + " \"operationId\" : \"createPets\",\n" + " \"responses\" : {\n" + " \"201\" : {\n" + " \"description\" : \"Null response\"\n" + " },\n" + " \"default\" : {\n" + " \"description\" : \"unexpected error\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Error\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"/pets/{petId}\" : {\n" + " \"get\" : {\n" + " \"tags\" : [ \"pets\" ],\n" + " \"summary\" : \"Info for a specific pet\",\n" + " \"operationId\" : \"showPetById\",\n" + " \"parameters\" : [ {\n" + " \"name\" : \"petId\",\n" + " \"in\" : \"path\",\n" + " \"description\" : \"The id of the pet to retrieve\",\n" + " \"required\" : true,\n" + " \"schema\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " } ],\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"Expected response to a valid request\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Pets\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"default\" : {\n" + " \"description\" : \"unexpected error\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Error\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"components\" : {\n" + " \"schemas\" : {\n" + " \"Pet\" : {\n" + " \"required\" : [ \"id\", \"name\" ],\n" + " \"properties\" : {\n" + " \"id\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int64\"\n" + " },\n" + " \"name\" : {\n" + " \"type\" : [\"string\", \"integer\"]\n" + " },\n" + " \"tag\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " },\n" + " \"Pets\" : {\n" + " \"type\" : \"array\",\n" + " \"items\" : {\n" + " \"$ref\" : \"#/components/schemas/Pet\"\n" + " }\n" + " },\n" + " \"Error\" : {\n" + " \"required\" : [ \"code\", \"message\" ],\n" + " \"properties\" : {\n" + " \"code\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int32\"\n" + " },\n" + " \"message\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"webhooks\" : {\n" + " \"newPet\" : {\n" + " \"post\" : {\n" + " \"requestBody\" : {\n" + " \"description\" : \"Information about a new pet in the system\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Pet\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"Return a 200 status to indicate that the data was received successfully\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}");
}
use of io.swagger.v3.oas.annotations.tags.Tags 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.annotations.tags.Tags in project swagger-core by swagger-api.
the class ReaderTest method testGetTags.
@Test(description = "Get tags")
public void testGetTags() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(TagsResource.class);
Operation operation = openAPI.getPaths().get("/").getGet();
assertNotNull(operation);
assertEquals(6, operation.getTags().size());
assertEquals(operation.getTags().get(3), EXAMPLE_TAG);
assertEquals(operation.getTags().get(1), SECOND_TAG);
assertEquals(openAPI.getTags().get(1).getDescription(), "desc definition");
assertEquals(openAPI.getTags().get(2).getExternalDocs().getDescription(), "docs desc");
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class ReaderTest method testTicket3624.
@Test(description = "Optional handling")
public void testTicket3624() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Service.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /example/model:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve models for display to the user'\n" + " operationId: getModels\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Response'\n" + " /example/model/by/ids:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve models by their ids'\n" + " operationId: getModelsById\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ByIdResponse'\n" + " /example/containerized/model:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve review insights for a specific product'\n" + " operationId: getContainerizedModels\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ContainerizedResponse'\n" + "components:\n" + " schemas:\n" + " Model:\n" + " type: object\n" + " properties:\n" + " text:\n" + " type: string\n" + " title:\n" + " type: string\n" + " active:\n" + " type: boolean\n" + " schemaParent:\n" + " $ref: '#/components/schemas/Model'\n" + " optionalString:\n" + " type: string\n" + " parent:\n" + " $ref: '#/components/schemas/Model'\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " Response:\n" + " type: object\n" + " properties:\n" + " count:\n" + " type: integer\n" + " format: int32\n" + " models:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/Model'\n" + " ByIdResponse:\n" + " type: object\n" + " properties:\n" + " modelsById:\n" + " type: object\n" + " additionalProperties:\n" + " $ref: '#/components/schemas/Model'\n" + " ContainerizedResponse:\n" + " type: object\n" + " properties:\n" + " totalCount:\n" + " type: integer\n" + " format: int32\n" + " containerizedModels:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/ModelContainer'\n" + " ModelContainer:\n" + " type: object\n" + " properties:\n" + " text:\n" + " type: string\n" + " model:\n" + " $ref: '#/components/schemas/Model'\n" + " id:\n" + " type: integer\n" + " format: int32";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class ReaderTest method testTicket3694.
@Test(description = "overridden generic resource methods")
public void testTicket3694() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Ticket3694ResourceExtendedType.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /foo:\n" + " post:\n" + " tags:\n" + " - Foo\n" + " summary: Foo List in Interface\n" + " operationId: foo\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " /bar:\n" + " post:\n" + " operationId: bar\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: string\n" + " /another:\n" + " post:\n" + " operationId: another\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
reader = new Reader(new OpenAPI());
openAPI = reader.read(Ticket3694Resource.class);
yaml = "openapi: 3.0.1\n" + "paths:\n" + " /foo:\n" + " post:\n" + " tags:\n" + " - Foo\n" + " summary: Foo List in Interface\n" + " operationId: foo\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " /bar:\n" + " post:\n" + " operationId: bar\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: string\n" + " /another:\n" + " post:\n" + " operationId: another\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
reader = new Reader(new OpenAPI());
openAPI = reader.read(Ticket3694ResourceSimple.class);
yaml = "openapi: 3.0.1\n" + "paths:\n" + " /bar:\n" + " post:\n" + " operationId: bar\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: string";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
reader = new Reader(new OpenAPI());
openAPI = reader.read(Ticket3694ResourceSimpleSameReturn.class);
yaml = "openapi: 3.0.1\n" + "paths:\n" + " /bar:\n" + " post:\n" + " operationId: bar\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Aggregations