Search in sources :

Example 51 with ParseOptions

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

the class OpenAPIV3ParserTest method testEmptyStrings_False.

@Test
public void testEmptyStrings_False() throws Exception {
    ParseOptions options = new ParseOptions();
    options.setAllowEmptyString(false);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/empty-strings.yaml", null, options);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
    OpenAPI openAPI = result.getOpenAPI();
    assertNull(openAPI.getInfo().getTitle());
    assertNotNull(openAPI.getInfo().getVersion());
    assertNull(openAPI.getInfo().getLicense().getName());
    assertNull(openAPI.getPaths().get("/something").getGet().getResponses().get("200").getDescription());
    assertNull(openAPI.getPaths().get("/something").getGet().getParameters().get(0).getDescription());
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 52 with ParseOptions

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

the class ResolverCacheTest method testMock.

@Test
public void testMock() throws Exception {
    final RefFormat format = RefFormat.URL;
    final String ref = "http://my.company.com/path/to/file.json";
    final String contentsOfExternalFile = "really good json";
    ParseOptions parseOptions = new ParseOptions();
    parseOptions.setResolve(true);
    parseOptions.setValidateExternalRefs(true);
    new Expectations(DeserializationUtils.class) {

        {
            RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
            times = 1;
            result = contentsOfExternalFile;
            DeserializationUtils.deserializeIntoTree(contentsOfExternalFile, ref, parseOptions, (SwaggerParseResult) any);
            times = 1;
            result = new ObjectMapper().readTree("{\"type\":  \"string\"}");
        }
    };
    ResolverCache cache = new ResolverCache(openAPI, auths, "http://my.company.com/path/parent.json", new HashSet<>(), parseOptions);
    Schema firstActualResult = cache.loadRef(ref, RefFormat.URL, Schema.class);
    assertEquals(firstActualResult.getType(), "string");
}
Also used : Expectations(mockit.Expectations) Schema(io.swagger.v3.oas.models.media.Schema) RefFormat(io.swagger.v3.parser.models.RefFormat) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) ResolverCache(io.swagger.v3.parser.ResolverCache) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 53 with ParseOptions

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

the class RelativeReferenceTest method testResolveRelativePaths.

@Test
public void testResolveRelativePaths() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("/relative-references-example/openapi.yaml", null, options);
    Assert.assertNotNull(parseResult.getOpenAPI());
    HashSet<String> validationMessages = new HashSet<>(null != parseResult.getMessages() ? parseResult.getMessages() : new ArrayList<>());
    // validationMessages.forEach(msg->System.out.println(msg));
    // OpenAPI specification = parseResult.getOpenAPI();
    Assert.assertTrue(validationMessages.isEmpty(), validationMessages.toString());
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) ArrayList(java.util.ArrayList) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 54 with ParseOptions

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

the class RelativeReferenceTest method testIssueServerUrlValidation.

@Test
public void testIssueServerUrlValidation() throws Exception {
    new Expectations() {

        {
            RemoteUrl.urlToString("http://foo.bar.com/swagger.json", Arrays.asList(new AuthorizationValue[] {}));
            times = 1;
            result = spec;
        }
    };
    SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation("http://foo.bar.com/swagger.json", null, new ParseOptions());
    assertNotNull(swaggerParseResult.getOpenAPI());
    assertTrue(swaggerParseResult.getMessages().isEmpty());
}
Also used : Expectations(mockit.Expectations) AuthorizationValue(io.swagger.v3.parser.core.models.AuthorizationValue) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 55 with ParseOptions

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

the class OpenAPIV3ParserTest method testValidateDefinition.

@Test(description = "directly parsed  definition, tested in previous method as reference relative/local ")
public void testValidateDefinition() {
    ParseOptions options = new ParseOptions();
    options.setValidateExternalRefs(false);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./swos-443/ref.yaml", null, options);
    OpenAPI openAPI = result.getOpenAPI();
    assertNotNull(openAPI);
    assertNotNull(result.getMessages());
    assertTrue(result.getMessages().contains("attribute components.schemas.ErrorModel.properties is not of type `object`"));
    assertTrue(result.getMessages().contains("attribute components.schemas.Examples.properties is not of type `object`"));
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)202 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)172 Test (org.testng.annotations.Test)166 OpenAPI (io.swagger.v3.oas.models.OpenAPI)144 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)140 Schema (io.swagger.v3.oas.models.media.Schema)52 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)51 StringSchema (io.swagger.v3.oas.models.media.StringSchema)46 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)44 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)40 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)36 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)25 MapSchema (io.swagger.v3.oas.models.media.MapSchema)23 Test (org.junit.Test)20 File (java.io.File)12 Parameter (io.swagger.v3.oas.models.parameters.Parameter)11 Expectations (mockit.Expectations)11 HashSet (java.util.HashSet)10 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)9 PathItem (io.swagger.v3.oas.models.PathItem)8