Search in sources :

Example 1 with ResolverFully

use of io.swagger.v3.parser.util.ResolverFully in project swagger-parser by swagger-api.

the class OpenAPIV3Parser method resolve.

private SwaggerParseResult resolve(SwaggerParseResult result, List<AuthorizationValue> auth, ParseOptions options, String location) {
    try {
        if (options != null) {
            if (options.isResolve() || options.isResolveFully()) {
                OpenAPIResolver resolver = new OpenAPIResolver(result.getOpenAPI(), emptyListIfNull(auth), location, null, options);
                resolver.resolve(result);
                if (options.isResolveFully()) {
                    new ResolverFully(options.isResolveCombinators()).resolveFully(result.getOpenAPI());
                }
            }
            if (options.isFlatten()) {
                final InlineModelResolver inlineModelResolver = new InlineModelResolver(options.isFlattenComposedSchemas(), options.isCamelCaseFlattenNaming(), options.isSkipMatches());
                if (result.getOpenAPI() != null) {
                    inlineModelResolver.flatten(result.getOpenAPI());
                }
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Exception while resolving:", e);
        // TODO verify if this change makes sense (adding resolve messages instead of replacing)
        result.getMessages().add(e.getMessage());
    // result.setMessages(Collections.singletonList(e.getMessage()));
    }
    return result;
}
Also used : InlineModelResolver(io.swagger.v3.parser.util.InlineModelResolver) ReadContentException(io.swagger.v3.parser.exception.ReadContentException) EncodingNotSupportedException(io.swagger.v3.parser.exception.EncodingNotSupportedException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ResolverFully(io.swagger.v3.parser.util.ResolverFully)

Example 2 with ResolverFully

use of io.swagger.v3.parser.util.ResolverFully 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 3 with ResolverFully

use of io.swagger.v3.parser.util.ResolverFully in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testIssue85.

@Test
public void testIssue85(@Injectable final List<AuthorizationValue> auths) {
    String yaml = "openapi: '3.0.1'\n" + "paths: \n" + "  /test/method: \n" + "    post: \n" + "      parameters: \n" + "        - \n" + "          in: \"path\"\n" + "          name: \"body\"\n" + "          required: false\n" + "          schema: \n" + "            $ref: '#/components/Schemas/StructureA'\n" + "components: \n" + "   schemas:\n" + "       StructureA: \n" + "           type: object\n" + "           properties: \n" + "               someProperty: \n" + "                   type: string\n" + "               arrayOfOtherType: \n" + "                   type: array\n" + "                   items: \n" + "                       $ref: '#/definitions/StructureB'\n" + "       StructureB: \n" + "           type: object\n" + "           properties: \n" + "               someProperty: \n" + "                   type: string\n";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
    ResolverFully resolverUtil = new ResolverFully();
    resolverUtil.resolveFully(openAPI);
    Parameter param = openAPI.getPaths().get("/test/method").getPost().getParameters().get(0);
    Schema schema = param.getSchema();
    assertNotNull(schema.getProperties().get("someProperty"));
    ArraySchema am = (ArraySchema) schema.getProperties().get("arrayOfOtherType");
    assertNotNull(am);
    Schema prop = am.getItems();
    assertTrue(prop instanceof Schema);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ResolverFully(io.swagger.v3.parser.util.ResolverFully) Test(org.testng.annotations.Test)

Example 4 with ResolverFully

use of io.swagger.v3.parser.util.ResolverFully in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testSelfReferenceResolution.

@Test
public void testSelfReferenceResolution(@Injectable final List<AuthorizationValue> auths) throws Exception {
    String yaml = "" + "openapi: 3.0.1\n" + "paths:\n" + "  \"/selfRefB\":\n" + "    get:\n" + "      requestBody:\n" + "        description: user to add to the system\\n\"+\n" + "        content:\n" + "         'application/json':\n" + "             schema:\n" + "                $ref: '#/components/schemas/SchemaB'\n" + "components:\n" + "  schemas:\n" + "    SchemaA:\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "        modelB:\n" + "          $ref: '#/components/schemas/SchemaB'\n" + "    SchemaB:\n" + "      properties:\n" + "        modelB:\n" + "          $ref: '#/components/schemas/SchemaB'";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
    ResolverFully resolverUtil = new ResolverFully();
    resolverUtil.resolveFully(openAPI);
    RequestBody body = openAPI.getPaths().get("/selfRefB").getGet().getRequestBody();
    Schema schema = body.getContent().get("application/json").getSchema();
    assertEquals(schema, openAPI.getComponents().getSchemas().get("SchemaB"));
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ResolverFully(io.swagger.v3.parser.util.ResolverFully) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Aggregations

ResolverFully (io.swagger.v3.parser.util.ResolverFully)4 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)3 OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)2 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)2 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)2 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)2 Schema (io.swagger.v3.oas.models.media.Schema)2 StringSchema (io.swagger.v3.oas.models.media.StringSchema)2 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)2 Test (org.testng.annotations.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Parameter (io.swagger.v3.oas.models.parameters.Parameter)1 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)1 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)1 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)1 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)1 EncodingNotSupportedException (io.swagger.v3.parser.exception.EncodingNotSupportedException)1 ReadContentException (io.swagger.v3.parser.exception.ReadContentException)1 InlineModelResolver (io.swagger.v3.parser.util.InlineModelResolver)1