Search in sources :

Example 16 with io.swagger.v3.oas.models.media

use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.

the class ParametersTest method scanClassAndFieldLevelAnnotations.

@Test(description = "scan class level and field level annotations")
public void scanClassAndFieldLevelAnnotations() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(ResourceWithKnownInjections.class);
    List<io.swagger.v3.oas.models.parameters.Parameter> resourceParameters = openAPI.getPaths().get("/resource/{id}").getGet().getParameters();
    assertNotNull(resourceParameters);
    assertEquals(resourceParameters.size(), 3);
    assertEquals(resourceParameters.get(0).getName(), "id");
    assertEquals(resourceParameters.get(1).getName(), "fieldParam");
    assertEquals(resourceParameters.get(2).getName(), "methodParam");
}
Also used : Reader(io.swagger.v3.jaxrs2.Reader) Parameter(io.swagger.v3.oas.annotations.Parameter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) AbstractAnnotationTest(io.swagger.v3.jaxrs2.annotations.AbstractAnnotationTest) Test(org.testng.annotations.Test)

Example 17 with io.swagger.v3.oas.models.media

use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.

the class OperationParser method getRequestBody.

public static Optional<RequestBody> getRequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody requestBody, Consumes classConsumes, Consumes methodConsumes, Components components, JsonView jsonViewAnnotation) {
    if (requestBody == null) {
        return Optional.empty();
    }
    RequestBody requestBodyObject = new RequestBody();
    boolean isEmpty = true;
    if (StringUtils.isNotBlank(requestBody.ref())) {
        requestBodyObject.set$ref(requestBody.ref());
        return Optional.of(requestBodyObject);
    }
    if (StringUtils.isNotBlank(requestBody.description())) {
        requestBodyObject.setDescription(requestBody.description());
        isEmpty = false;
    }
    if (requestBody.required()) {
        requestBodyObject.setRequired(requestBody.required());
        isEmpty = false;
    }
    if (requestBody.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(requestBody.extensions());
        if (extensions != null) {
            extensions.forEach(requestBodyObject::addExtension);
        }
        isEmpty = false;
    }
    if (requestBody.content().length > 0) {
        isEmpty = false;
    }
    if (isEmpty) {
        return Optional.empty();
    }
    AnnotationsUtils.getContent(requestBody.content(), classConsumes == null ? new String[0] : classConsumes.value(), methodConsumes == null ? new String[0] : methodConsumes.value(), null, components, jsonViewAnnotation).ifPresent(requestBodyObject::setContent);
    return Optional.of(requestBodyObject);
}
Also used : RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Example 18 with io.swagger.v3.oas.models.media

use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.

the class SecurityParser method getOAuthFlows.

public static Optional<OAuthFlows> getOAuthFlows(io.swagger.v3.oas.annotations.security.OAuthFlows oAuthFlows) {
    if (isEmpty(oAuthFlows)) {
        return Optional.empty();
    }
    OAuthFlows oAuthFlowsObject = new OAuthFlows();
    if (oAuthFlows.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(oAuthFlows.extensions());
        if (extensions != null) {
            extensions.forEach(oAuthFlowsObject::addExtension);
        }
    }
    getOAuthFlow(oAuthFlows.authorizationCode()).ifPresent(oAuthFlowsObject::setAuthorizationCode);
    getOAuthFlow(oAuthFlows.clientCredentials()).ifPresent(oAuthFlowsObject::setClientCredentials);
    getOAuthFlow(oAuthFlows.implicit()).ifPresent(oAuthFlowsObject::setImplicit);
    getOAuthFlow(oAuthFlows.password()).ifPresent(oAuthFlowsObject::setPassword);
    return Optional.of(oAuthFlowsObject);
}
Also used : OAuthFlows(io.swagger.v3.oas.models.security.OAuthFlows)

Example 19 with io.swagger.v3.oas.models.media

use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.

the class SecurityParser method getOAuthFlow.

public static Optional<OAuthFlow> getOAuthFlow(io.swagger.v3.oas.annotations.security.OAuthFlow oAuthFlow) {
    if (isEmpty(oAuthFlow)) {
        return Optional.empty();
    }
    OAuthFlow oAuthFlowObject = new OAuthFlow();
    if (StringUtils.isNotBlank(oAuthFlow.authorizationUrl())) {
        oAuthFlowObject.setAuthorizationUrl(oAuthFlow.authorizationUrl());
    }
    if (StringUtils.isNotBlank(oAuthFlow.refreshUrl())) {
        oAuthFlowObject.setRefreshUrl(oAuthFlow.refreshUrl());
    }
    if (StringUtils.isNotBlank(oAuthFlow.tokenUrl())) {
        oAuthFlowObject.setTokenUrl(oAuthFlow.tokenUrl());
    }
    if (oAuthFlow.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(oAuthFlow.extensions());
        if (extensions != null) {
            extensions.forEach(oAuthFlowObject::addExtension);
        }
    }
    getScopes(oAuthFlow.scopes()).ifPresent(oAuthFlowObject::setScopes);
    return Optional.of(oAuthFlowObject);
}
Also used : OAuthFlow(io.swagger.v3.oas.models.security.OAuthFlow)

Example 20 with io.swagger.v3.oas.models.media

use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.

the class SecurityParser method getSecurityScheme.

public static Optional<SecuritySchemePair> getSecurityScheme(io.swagger.v3.oas.annotations.security.SecurityScheme securityScheme) {
    if (securityScheme == null) {
        return Optional.empty();
    }
    String key = null;
    SecurityScheme securitySchemeObject = new SecurityScheme();
    if (StringUtils.isNotBlank(securityScheme.in().toString())) {
        securitySchemeObject.setIn(getIn(securityScheme.in().toString()));
    }
    if (StringUtils.isNotBlank(securityScheme.type().toString())) {
        securitySchemeObject.setType(getType(securityScheme.type().toString()));
    }
    if (StringUtils.isNotBlank(securityScheme.openIdConnectUrl())) {
        securitySchemeObject.setOpenIdConnectUrl(securityScheme.openIdConnectUrl());
    }
    if (StringUtils.isNotBlank(securityScheme.scheme())) {
        securitySchemeObject.setScheme(securityScheme.scheme());
    }
    if (StringUtils.isNotBlank(securityScheme.bearerFormat())) {
        securitySchemeObject.setBearerFormat(securityScheme.bearerFormat());
    }
    if (StringUtils.isNotBlank(securityScheme.description())) {
        securitySchemeObject.setDescription(securityScheme.description());
    }
    if (StringUtils.isNotBlank(securityScheme.paramName())) {
        securitySchemeObject.setName(securityScheme.paramName());
    }
    if (StringUtils.isNotBlank(securityScheme.ref())) {
        securitySchemeObject.set$ref(securityScheme.ref());
    }
    if (StringUtils.isNotBlank(securityScheme.name())) {
        key = securityScheme.name();
    }
    if (securityScheme.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(securityScheme.extensions());
        if (extensions != null) {
            extensions.forEach(securitySchemeObject::addExtension);
        }
    }
    getOAuthFlows(securityScheme.flows()).ifPresent(securitySchemeObject::setFlows);
    SecuritySchemePair result = new SecuritySchemePair();
    result.key = key;
    result.securityScheme = securitySchemeObject;
    return Optional.of(result);
}
Also used : SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Aggregations

Schema (io.swagger.v3.oas.models.media.Schema)13 ExampleObject (io.swagger.v3.oas.annotations.media.ExampleObject)11 OpenAPI (io.swagger.v3.oas.models.OpenAPI)10 Annotation (java.lang.annotation.Annotation)8 Test (org.testng.annotations.Test)8 ResolvedSchema (io.swagger.v3.core.converter.ResolvedSchema)7 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)7 Content (io.swagger.v3.oas.models.media.Content)7 ArrayList (java.util.ArrayList)7 PathItem (io.swagger.v3.oas.models.PathItem)6 Parameter (io.swagger.v3.oas.models.parameters.Parameter)6 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)5 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)5 Hidden (io.swagger.v3.oas.annotations.Hidden)5 MediaType (io.swagger.v3.oas.models.media.MediaType)5 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)5 Map (java.util.Map)5 JavaType (com.fasterxml.jackson.databind.JavaType)4 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)4