use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.
the class ReaderTest method testResponseWithRef.
@Test(description = "Responses with ref")
public void testResponseWithRef() {
Components components = new Components();
components.addResponses("invalidJWT", new ApiResponse().description("when JWT token invalid/expired"));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefResponsesResource.class);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /:\n" + " get:\n" + " summary: Simple get operation\n" + " description: Defines a simple get operation with no inputs and a complex output\n" + " object\n" + " operationId: getWithPayloadResponse\n" + " responses:\n" + " \"200\":\n" + " description: voila!\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/SampleResponseSchema'\n" + " default:\n" + " description: boo\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/GenericError'\n" + " \"401\":\n" + " $ref: '#/components/responses/invalidJWT'\n" + " deprecated: true\n" + "components:\n" + " schemas:\n" + " GenericError:\n" + " type: object\n" + " SampleResponseSchema:\n" + " type: object\n" + " responses:\n" + " invalidJWT:\n" + " description: when JWT token invalid/expired";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.media.Content 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);
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.
the class ReaderTest method testMoreResponses.
@Test(description = "More Responses")
public void testMoreResponses() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(EnhancedResponsesResource.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " summary: Simple get operation\n" + " description: Defines a simple get operation with no inputs and a complex output\n" + " object\n" + " operationId: getWithPayloadResponse\n" + " responses:\n" + " \"200\":\n" + " description: voila!\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/SampleResponseSchema'\n" + " \"404\":\n" + " description: not found!\n" + " \"400\":\n" + " description: boo\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/GenericError'\n" + " deprecated: true\n" + "components:\n" + " schemas:\n" + " GenericError:\n" + " type: object\n" + " SampleResponseSchema:\n" + " type: object\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.
the class SimpleBuilderTest method testBuilder.
@Test
public void testBuilder() throws Exception {
// basic metadata
OpenAPI oai = new OpenAPI().info(new Info().contact(new Contact().email("tony@eatbacon.org").name("Tony the Tam").url("https://foo.bar"))).externalDocs(new ExternalDocumentation().description("read more here").url("http://swagger.io")).addTagsItem(new Tag().name("funky dunky").description("all about neat things")).extensions(new HashMap<String, Object>() {
{
put("x-fancy-extension", "something");
}
});
Map<String, Schema> schemas = new HashMap<>();
schemas.put("StringSchema", new StringSchema().description("simple string schema").minLength(3).maxLength(100).example("it works"));
schemas.put("IntegerSchema", new IntegerSchema().description("simple integer schema").multipleOf(new BigDecimal(3)).minimum(new BigDecimal(6)));
oai.components(new Components().schemas(schemas));
schemas.put("Address", new Schema().description("address object").addProperties("street", new StringSchema().description("the street number")).addProperties("city", new StringSchema().description("city")).addProperties("state", new StringSchema().description("state").minLength(2).maxLength(2)).addProperties("zip", new StringSchema().description("zip code").pattern("^\\d{5}(?:[-\\s]\\d{4})?$").minLength(2).maxLength(2)).addProperties("country", new StringSchema()._enum(new ArrayList<String>() {
{
this.add("US");
}
})).description("2-digit country code").minLength(2).maxLength(2));
oai.paths(new Paths().addPathItem("/foo", new PathItem().description("the foo path").get(new Operation().addParametersItem(new QueryParameter().description("Records to skip").required(false).schema(new IntegerSchema())).responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("it worked").content(new Content().addMediaType("application/json", new MediaType().schema(new Schema().$ref("#/components/schemas/Address")))).addLink("funky", new Link().operationId("getFunky")))))));
System.out.println(writeJson(oai));
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.
the class Reader method resolveEmptyContent.
protected Content resolveEmptyContent(Produces classProduces, Produces methodProduces) {
Content content = new Content();
MediaType mediaType = new MediaType();
AnnotationsUtils.applyTypes(classProduces == null ? new String[0] : classProduces.value(), methodProduces == null ? new String[0] : methodProduces.value(), content, mediaType);
return content;
}
Aggregations