Search in sources :

Example 31 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class SwaggerConverter method readResult.

private SwaggerParseResult readResult(SwaggerDeserializationResult result, List<AuthorizationValue> auth, ParseOptions options) {
    SwaggerParseResult out = convert(result);
    if (out != null && options != null) {
        if (options.isResolveFully()) {
            new ResolverFully(options.isResolveCombinators()).resolveFully(out.getOpenAPI());
        }
        if (options.isFlatten()) {
            try {
                SwaggerParseResult resultV3 = new OpenAPIV3Parser().readContents(Yaml.pretty(out.getOpenAPI()), auth, options);
                out.setOpenAPI(resultV3.getOpenAPI());
                if (out.getMessages() != null) {
                    out.getMessages().addAll(resultV3.getMessages());
                    out.messages(out.getMessages().stream().distinct().collect(Collectors.toList()));
                } else {
                    out.messages(resultV3.getMessages());
                }
            } catch (Exception ignore) {
            }
        }
    }
    return out;
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) ResolverFully(io.swagger.v3.parser.util.ResolverFully)

Example 32 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class OpenAPIV3Parser method transform.

/**
 * Transform the swagger-model version of AuthorizationValue into a parser-specific one, to avoid
 * dependencies across extensions
 *
 * @param input
 * @return
 */
@Deprecated
protected List<AuthorizationValue> transform(List<AuthorizationValue> input) {
    if (input == null) {
        return null;
    }
    List<AuthorizationValue> output = new ArrayList<>();
    for (AuthorizationValue value : input) {
        AuthorizationValue v = new AuthorizationValue();
        v.setKeyName(value.getKeyName());
        v.setValue(value.getValue());
        v.setType(value.getType());
        v.setUrlMatcher(value.getUrlMatcher());
        output.add(v);
    }
    return output;
}
Also used : AuthorizationValue(io.swagger.v3.parser.core.models.AuthorizationValue) ArrayList(java.util.ArrayList)

Example 33 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class OpenAPIV3Parser method read.

public OpenAPI read(String location, List<AuthorizationValue> auths, ParseOptions resolve) {
    if (location == null) {
        return null;
    }
    final List<SwaggerParserExtension> parserExtensions = getExtensions();
    SwaggerParseResult parsed;
    for (SwaggerParserExtension extension : parserExtensions) {
        parsed = extension.readLocation(location, auths, resolve);
        for (String message : parsed.getMessages()) {
            LOGGER.info("{}: {}", extension, message);
        }
        final OpenAPI result = parsed.getOpenAPI();
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : SwaggerParserExtension(io.swagger.v3.parser.core.extensions.SwaggerParserExtension) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPI(io.swagger.v3.oas.models.OpenAPI)

Example 34 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class SwaggerConverter method convert.

public List<io.swagger.models.auth.AuthorizationValue> convert(List<AuthorizationValue> auths) {
    List<io.swagger.models.auth.AuthorizationValue> convertedAuth = new ArrayList<>();
    if (auths != null) {
        for (AuthorizationValue auth : auths) {
            io.swagger.models.auth.AuthorizationValue v = new io.swagger.models.auth.AuthorizationValue();
            v.setType(auth.getType());
            v.setValue(auth.getValue());
            v.setKeyName(auth.getKeyName());
            convertedAuth.add(v);
        }
    }
    return convertedAuth;
}
Also used : AuthorizationValue(io.swagger.v3.parser.core.models.AuthorizationValue) ArrayList(java.util.ArrayList)

Example 35 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class V2ConverterTest method testIssue785.

@Test(description = "OpenAPIParser.readLocation fails when fetching valid Swagger 2.0 resource with AuthorizationValues provided")
public void testIssue785() {
    AuthorizationValue apiKey = new AuthorizationValue("api_key", "special-key", "header");
    List<AuthorizationValue> authorizationValues = Arrays.asList(apiKey);
    SwaggerConverter converter = new SwaggerConverter();
    List<io.swagger.models.auth.AuthorizationValue> convertedAuthList = converter.convert(authorizationValues);
    assertEquals(convertedAuthList.size(), authorizationValues.size());
}
Also used : AuthorizationValue(io.swagger.v3.parser.core.models.AuthorizationValue) SwaggerConverter(io.swagger.v3.parser.converter.SwaggerConverter) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)44 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)40 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)34 OpenAPI (io.swagger.v3.oas.models.OpenAPI)31 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)21 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)18 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)18 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)17 Schema (io.swagger.v3.oas.models.media.Schema)17 StringSchema (io.swagger.v3.oas.models.media.StringSchema)17 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)16 AuthorizationValue (io.swagger.v3.parser.core.models.AuthorizationValue)13 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)8 MapSchema (io.swagger.v3.oas.models.media.MapSchema)8 HashSet (java.util.HashSet)7 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)5 DateSchema (io.swagger.v3.oas.models.media.DateSchema)5 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)5 ArrayList (java.util.ArrayList)5 Expectations (mockit.Expectations)5