Search in sources :

Example 6 with ExternalDocs

use of io.swagger.models.ExternalDocs in project candlepin by candlepin.

the class CandlepinSwaggerConfig method afterScan.

@Override
public void afterScan(Reader reader, Swagger swagger) {
    swagger.setExternalDocs(new ExternalDocs("Project website: ", "http://candlepinproject.org/"));
    BasicAuthDefinition basic = new BasicAuthDefinition();
    basic.setDescription("Candlepin requires HTTP Basic authentication of an owner");
    swagger.addSecurityDefinition(BASIC_AUTH, basic);
    SecurityRequirement req = new SecurityRequirement();
    req.setRequirements(BASIC_AUTH, new ArrayList<>());
    swagger.addSecurity(req);
}
Also used : BasicAuthDefinition(io.swagger.models.auth.BasicAuthDefinition) ExternalDocs(io.swagger.models.ExternalDocs) SecurityRequirement(io.swagger.models.SecurityRequirement)

Example 7 with ExternalDocs

use of io.swagger.models.ExternalDocs in project ballerina by ballerina-lang.

the class SwaggerServiceMapper method createExternalDocModel.

/**
 * Creates external docs swagger definition.
 * @param annotationAttributeValue The ballerina annotation attribute value for external docs.
 * @param swagger The swagger definition which the external docs needs to be build on.
 */
private void createExternalDocModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Swagger swagger) {
    if (null != annotationAttributeValue) {
        AnnotationAttachmentNode externalDocAnnotationAttachment = (AnnotationAttachmentNode) annotationAttributeValue.getValue();
        Map<String, AnnotationAttachmentAttributeValueNode> externalDocAttributes = this.listToMap(externalDocAnnotationAttachment);
        ExternalDocs externalDocs = new ExternalDocs();
        if (externalDocAttributes.containsKey("description")) {
            externalDocs.setDescription(this.getStringLiteralValue(externalDocAttributes.get("description")));
        }
        if (externalDocAttributes.containsKey("url")) {
            externalDocs.setUrl(this.getStringLiteralValue(externalDocAttributes.get("url")));
        }
        swagger.setExternalDocs(externalDocs);
    }
}
Also used : AnnotationAttachmentAttributeValueNode(org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode) ExternalDocs(io.swagger.models.ExternalDocs) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 8 with ExternalDocs

use of io.swagger.models.ExternalDocs in project ballerina by ballerina-lang.

the class SwaggerResourceMapper method createExternalDocsModel.

/**
 * Creates external docs swagger definitions.
 *
 * @param annotationAttributeValue The annotation attribute value for external docs.
 * @param operation                The swagger operation.
 */
private void createExternalDocsModel(AnnAttributeValue annotationAttributeValue, Operation operation) {
    if (null != annotationAttributeValue) {
        AnnAttachmentInfo externalDocAnnotationAttachment = annotationAttributeValue.getAnnotationAttachmentValue();
        ExternalDocs externalDocs = new ExternalDocs();
        Map<String, AnnAttributeValue> externalDocsAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(externalDocAnnotationAttachment);
        if (null != externalDocsAnnAttributeValueMap.get("description")) {
            externalDocs.setDescription(externalDocsAnnAttributeValueMap.get("description").getStringValue());
        }
        if (null != externalDocsAnnAttributeValueMap.get("url")) {
            externalDocs.setUrl(externalDocsAnnAttributeValueMap.get("url").getStringValue());
        }
        operation.setExternalDocs(externalDocs);
    }
}
Also used : ParamAnnAttachmentInfo(org.ballerinalang.util.codegen.ParamAnnAttachmentInfo) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue) ExternalDocs(io.swagger.models.ExternalDocs)

Example 9 with ExternalDocs

use of io.swagger.models.ExternalDocs in project swagger-core by swagger-api.

the class Reader method readSwaggerConfig.

protected void readSwaggerConfig(Class<?> cls, SwaggerDefinition config) {
    if (!config.basePath().isEmpty()) {
        swagger.setBasePath(config.basePath());
    }
    if (!config.host().isEmpty()) {
        swagger.setHost(config.host());
    }
    readInfoConfig(config);
    for (String consume : config.consumes()) {
        if (StringUtils.isNotEmpty(consume)) {
            swagger.addConsumes(consume);
        }
    }
    for (String produce : config.produces()) {
        if (StringUtils.isNotEmpty(produce)) {
            swagger.addProduces(produce);
        }
    }
    for (OAuth2Definition oAuth2Config : config.securityDefinition().oAuth2Definitions()) {
        io.swagger.models.auth.OAuth2Definition oAuth2Definition = new io.swagger.models.auth.OAuth2Definition();
        OAuth2Definition.Flow flow = oAuth2Config.flow();
        if (flow.equals(OAuth2Definition.Flow.ACCESS_CODE)) {
            oAuth2Definition = oAuth2Definition.accessCode(oAuth2Config.authorizationUrl(), oAuth2Config.tokenUrl());
        } else if (flow.equals(OAuth2Definition.Flow.APPLICATION)) {
            oAuth2Definition = oAuth2Definition.application(oAuth2Config.tokenUrl());
        } else if (flow.equals(OAuth2Definition.Flow.IMPLICIT)) {
            oAuth2Definition = oAuth2Definition.implicit(oAuth2Config.authorizationUrl());
        } else {
            oAuth2Definition = oAuth2Definition.password(oAuth2Config.tokenUrl());
        }
        for (Scope scope : oAuth2Config.scopes()) {
            oAuth2Definition.addScope(scope.name(), scope.description());
        }
        oAuth2Definition.setDescription(oAuth2Config.description());
        swagger.addSecurityDefinition(oAuth2Config.key(), oAuth2Definition);
    }
    for (ApiKeyAuthDefinition[] apiKeyAuthConfigs : new ApiKeyAuthDefinition[][] { config.securityDefinition().apiKeyAuthDefintions(), config.securityDefinition().apiKeyAuthDefinitions() }) {
        for (ApiKeyAuthDefinition apiKeyAuthConfig : apiKeyAuthConfigs) {
            io.swagger.models.auth.ApiKeyAuthDefinition apiKeyAuthDefinition = new io.swagger.models.auth.ApiKeyAuthDefinition();
            apiKeyAuthDefinition.setName(apiKeyAuthConfig.name());
            apiKeyAuthDefinition.setIn(In.forValue(apiKeyAuthConfig.in().toValue()));
            apiKeyAuthDefinition.setDescription(apiKeyAuthConfig.description());
            swagger.addSecurityDefinition(apiKeyAuthConfig.key(), apiKeyAuthDefinition);
        }
    }
    for (BasicAuthDefinition[] basicAuthConfigs : new BasicAuthDefinition[][] { config.securityDefinition().basicAuthDefinions(), config.securityDefinition().basicAuthDefinitions() }) {
        for (BasicAuthDefinition basicAuthConfig : basicAuthConfigs) {
            io.swagger.models.auth.BasicAuthDefinition basicAuthDefinition = new io.swagger.models.auth.BasicAuthDefinition();
            basicAuthDefinition.setDescription(basicAuthConfig.description());
            swagger.addSecurityDefinition(basicAuthConfig.key(), basicAuthDefinition);
        }
    }
    if (!config.externalDocs().value().isEmpty()) {
        ExternalDocs externalDocs = swagger.getExternalDocs();
        if (externalDocs == null) {
            externalDocs = new ExternalDocs();
            swagger.setExternalDocs(externalDocs);
        }
        externalDocs.setDescription(config.externalDocs().value());
        if (!config.externalDocs().url().isEmpty()) {
            externalDocs.setUrl(config.externalDocs().url());
        }
    }
    for (io.swagger.annotations.Tag tagConfig : config.tags()) {
        if (!tagConfig.name().isEmpty()) {
            Tag tag = new Tag();
            tag.setName(tagConfig.name());
            tag.setDescription(tagConfig.description());
            if (!tagConfig.externalDocs().value().isEmpty()) {
                tag.setExternalDocs(new ExternalDocs(tagConfig.externalDocs().value(), tagConfig.externalDocs().url()));
            }
            tag.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(tagConfig.extensions()));
            swagger.addTag(tag);
        }
    }
    for (SwaggerDefinition.Scheme scheme : config.schemes()) {
        if (scheme != SwaggerDefinition.Scheme.DEFAULT) {
            swagger.addScheme(Scheme.forValue(scheme.name()));
        }
    }
}
Also used : OAuth2Definition(io.swagger.annotations.OAuth2Definition) BasicAuthDefinition(io.swagger.annotations.BasicAuthDefinition) ExternalDocs(io.swagger.models.ExternalDocs) ApiKeyAuthDefinition(io.swagger.annotations.ApiKeyAuthDefinition) AuthorizationScope(io.swagger.annotations.AuthorizationScope) Scope(io.swagger.annotations.Scope) Tag(io.swagger.models.Tag) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition)

Example 10 with ExternalDocs

use of io.swagger.models.ExternalDocs in project swagger-core by swagger-api.

the class Reader method readSwaggerConfig.

private void readSwaggerConfig(SwaggerDefinition config) {
    readInfoConfig(config);
    if (StringUtils.isNotBlank(config.basePath())) {
        swagger.setBasePath(config.basePath());
    }
    if (StringUtils.isNotBlank(config.host())) {
        swagger.setHost(config.host());
    }
    for (String consume : config.consumes()) {
        if (StringUtils.isNotBlank(consume)) {
            swagger.addConsumes(consume);
        }
    }
    for (String produce : config.produces()) {
        if (StringUtils.isNotBlank(produce)) {
            swagger.addProduces(produce);
        }
    }
    if (StringUtils.isNotBlank(config.externalDocs().value())) {
        ExternalDocs externalDocs = swagger.getExternalDocs();
        if (externalDocs == null) {
            externalDocs = new ExternalDocs();
            swagger.setExternalDocs(externalDocs);
        }
        externalDocs.setDescription(config.externalDocs().value());
        if (StringUtils.isNotBlank(config.externalDocs().url())) {
            externalDocs.setUrl(config.externalDocs().url());
        }
    }
    for (OAuth2Definition oAuth2Config : config.securityDefinition().oAuth2Definitions()) {
        io.swagger.models.auth.OAuth2Definition oAuth2Definition = new io.swagger.models.auth.OAuth2Definition();
        OAuth2Definition.Flow flow = oAuth2Config.flow();
        if (flow.equals(OAuth2Definition.Flow.ACCESS_CODE)) {
            oAuth2Definition = oAuth2Definition.accessCode(oAuth2Config.authorizationUrl(), oAuth2Config.tokenUrl());
        } else if (flow.equals(OAuth2Definition.Flow.APPLICATION)) {
            oAuth2Definition = oAuth2Definition.application(oAuth2Config.tokenUrl());
        } else if (flow.equals(OAuth2Definition.Flow.IMPLICIT)) {
            oAuth2Definition = oAuth2Definition.implicit(oAuth2Config.authorizationUrl());
        } else {
            oAuth2Definition = oAuth2Definition.password(oAuth2Config.tokenUrl());
        }
        for (Scope scope : oAuth2Config.scopes()) {
            oAuth2Definition.addScope(scope.name(), scope.description());
        }
        oAuth2Definition.setDescription(oAuth2Config.description());
        swagger.addSecurityDefinition(oAuth2Config.key(), oAuth2Definition);
    }
    for (ApiKeyAuthDefinition[] apiKeyAuthConfigs : new ApiKeyAuthDefinition[][] { config.securityDefinition().apiKeyAuthDefintions(), config.securityDefinition().apiKeyAuthDefinitions() }) {
        for (ApiKeyAuthDefinition apiKeyAuthConfig : apiKeyAuthConfigs) {
            io.swagger.models.auth.ApiKeyAuthDefinition apiKeyAuthDefinition = new io.swagger.models.auth.ApiKeyAuthDefinition();
            apiKeyAuthDefinition.setName(apiKeyAuthConfig.name());
            apiKeyAuthDefinition.setIn(In.forValue(apiKeyAuthConfig.in().toValue()));
            apiKeyAuthDefinition.setDescription(apiKeyAuthConfig.description());
            swagger.addSecurityDefinition(apiKeyAuthConfig.key(), apiKeyAuthDefinition);
        }
    }
    for (BasicAuthDefinition[] basicAuthConfigs : new BasicAuthDefinition[][] { config.securityDefinition().basicAuthDefinions(), config.securityDefinition().basicAuthDefinitions() }) {
        for (BasicAuthDefinition basicAuthConfig : basicAuthConfigs) {
            io.swagger.models.auth.BasicAuthDefinition basicAuthDefinition = new io.swagger.models.auth.BasicAuthDefinition();
            basicAuthDefinition.setDescription(basicAuthConfig.description());
            swagger.addSecurityDefinition(basicAuthConfig.key(), basicAuthDefinition);
        }
    }
    for (io.swagger.annotations.Tag tagConfig : config.tags()) {
        if (StringUtils.isNotBlank(tagConfig.name())) {
            final Tag tag = new Tag();
            tag.setName(tagConfig.name());
            tag.setDescription(tagConfig.description());
            if (StringUtils.isNotBlank(tagConfig.externalDocs().value())) {
                tag.setExternalDocs(new ExternalDocs(tagConfig.externalDocs().value(), tagConfig.externalDocs().url()));
            }
            tag.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(tagConfig.extensions()));
            swagger.addTag(tag);
        }
    }
    for (SwaggerDefinition.Scheme scheme : config.schemes()) {
        if (scheme != SwaggerDefinition.Scheme.DEFAULT) {
            swagger.addScheme(Scheme.forValue(scheme.name()));
        }
    }
}
Also used : OAuth2Definition(io.swagger.annotations.OAuth2Definition) BasicAuthDefinition(io.swagger.annotations.BasicAuthDefinition) ExternalDocs(io.swagger.models.ExternalDocs) ApiKeyAuthDefinition(io.swagger.annotations.ApiKeyAuthDefinition) Scope(io.swagger.annotations.Scope) Tag(io.swagger.models.Tag) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition)

Aggregations

ExternalDocs (io.swagger.models.ExternalDocs)12 ApiKeyAuthDefinition (io.swagger.annotations.ApiKeyAuthDefinition)3 BasicAuthDefinition (io.swagger.annotations.BasicAuthDefinition)3 OAuth2Definition (io.swagger.annotations.OAuth2Definition)3 Scope (io.swagger.annotations.Scope)3 SwaggerDefinition (io.swagger.annotations.SwaggerDefinition)3 Tag (io.swagger.models.Tag)3 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)2 AnnotationAttachmentAttributeValueNode (org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode)2 AnnAttachmentInfo (org.ballerinalang.util.codegen.AnnAttachmentInfo)2 Test (org.testng.annotations.Test)2 AuthorizationScope (io.swagger.annotations.AuthorizationScope)1 RefModel (io.swagger.models.RefModel)1 SecurityRequirement (io.swagger.models.SecurityRequirement)1 Swagger (io.swagger.models.Swagger)1 BasicAuthDefinition (io.swagger.models.auth.BasicAuthDefinition)1 ResourceWithExternalDocs (io.swagger.resources.ResourceWithExternalDocs)1 AnnAttributeKeyValuePair (org.ballerinalang.util.codegen.AnnAttributeKeyValuePair)1 AnnAttributeValue (org.ballerinalang.util.codegen.AnnAttributeValue)1 ParamAnnAttachmentInfo (org.ballerinalang.util.codegen.ParamAnnAttachmentInfo)1