Search in sources :

Example 1 with ExternalDocumentation

use of io.swagger.v3.oas.models.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;
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation)

Example 2 with ExternalDocumentation

use of io.swagger.v3.oas.models.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);
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject)

Example 3 with ExternalDocumentation

use of io.swagger.v3.oas.models.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\"}");
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 4 with ExternalDocumentation

use of io.swagger.v3.oas.models.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);
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 5 with ExternalDocumentation

use of io.swagger.v3.oas.models.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));
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HashMap(java.util.HashMap) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Paths(io.swagger.v3.oas.models.Paths) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Info(io.swagger.v3.oas.models.info.Info) BigDecimal(java.math.BigDecimal) Contact(io.swagger.v3.oas.models.info.Contact) Content(io.swagger.v3.oas.models.media.Content) Tag(io.swagger.v3.oas.models.tags.Tag) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Link(io.swagger.v3.oas.models.links.Link) Test(org.testng.annotations.Test)

Aggregations

ExternalDocumentation (io.swagger.v3.oas.models.ExternalDocumentation)8 OpenAPI (io.swagger.v3.oas.models.OpenAPI)5 Operation (io.swagger.v3.oas.models.Operation)5 PathItem (io.swagger.v3.oas.models.PathItem)4 Paths (io.swagger.v3.oas.models.Paths)4 Schema (io.swagger.v3.oas.models.media.Schema)4 Test (org.testng.annotations.Test)4 Components (io.swagger.v3.oas.models.Components)3 Content (io.swagger.v3.oas.models.media.Content)3 MediaType (io.swagger.v3.oas.models.media.MediaType)3 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)3 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)3 Tag (io.swagger.v3.oas.models.tags.Tag)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JsonView (com.fasterxml.jackson.annotation.JsonView)2 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 JavaType (com.fasterxml.jackson.databind.JavaType)2 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)2 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)2