use of io.swagger.v3.oas.annotations.ExternalDocumentation in project swagger-core by swagger-api.
the class ModelResolver method resolveExternalDocumentation.
protected ExternalDocumentation resolveExternalDocumentation(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) {
ExternalDocumentation external = null;
if (a != null) {
io.swagger.v3.oas.annotations.ExternalDocumentation externalDocumentation = a.getAnnotation(io.swagger.v3.oas.annotations.ExternalDocumentation.class);
external = resolveExternalDocumentation(externalDocumentation);
}
if (external == null) {
if (schema != null) {
external = resolveExternalDocumentation(schema.externalDocs());
}
}
return external;
}
use of io.swagger.v3.oas.annotations.ExternalDocumentation in project swagger-core by swagger-api.
the class AnnotationsUtils method getExternalDocumentation.
public static Optional<ExternalDocumentation> getExternalDocumentation(io.swagger.v3.oas.annotations.ExternalDocumentation externalDocumentation) {
if (externalDocumentation == null) {
return Optional.empty();
}
boolean isEmpty = true;
ExternalDocumentation external = new ExternalDocumentation();
if (StringUtils.isNotBlank(externalDocumentation.description())) {
isEmpty = false;
external.setDescription(externalDocumentation.description());
}
if (StringUtils.isNotBlank(externalDocumentation.url())) {
isEmpty = false;
external.setUrl(externalDocumentation.url());
}
if (externalDocumentation.extensions() != null && externalDocumentation.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(externalDocumentation.extensions());
if (extensions != null) {
extensions.forEach(external::addExtension);
isEmpty = false;
}
}
if (isEmpty) {
return Optional.empty();
}
return Optional.of(external);
}
use of io.swagger.v3.oas.annotations.ExternalDocumentation in project swagger-core by swagger-api.
the class ModelSerializerTest method shouldNotCreateXmlObjectForRef.
@Test(description = "it should not create an xml object for $ref")
public void shouldNotCreateXmlObjectForRef() throws IOException {
final Schema model = new Schema().$ref("Monster");
model.setDescription("oops");
model.setExternalDocs(new ExternalDocumentation().description("external docs").url("http://swagger.io"));
assertEquals(Json.mapper().writeValueAsString(model), "{\"$ref\":\"#/components/schemas/Monster\"}");
}
use of io.swagger.v3.oas.annotations.ExternalDocumentation in project swagger-core by swagger-api.
the class ReaderTest method testGetExternalDocs.
@Test(description = "External Docs")
public void testGetExternalDocs() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(ExternalDocsReference.class);
Operation externalDocsOperation = openAPI.getPaths().get("/").getGet();
ExternalDocumentation externalDocs = externalDocsOperation.getExternalDocs();
assertEquals(externalDocs.getDescription(), "External documentation description in method");
assertEquals(externalDocs.getUrl(), EXTERNAL_DOCS_URL);
externalDocs = openAPI.getComponents().getSchemas().get("ExternalDocsSchema").getExternalDocs();
assertEquals("External documentation description in schema", externalDocs.getDescription());
assertEquals(externalDocs.getUrl(), EXTERNAL_DOCS_URL);
}
use of io.swagger.v3.oas.annotations.ExternalDocumentation 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));
}
Aggregations