Search in sources :

Example 16 with AuthorizationValue

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

the class OpenAPIV3ParserTest method testResolveEmpty.

@Test
public void testResolveEmpty(@Injectable final List<AuthorizationValue> auths) throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/empty-oas.yaml"));
    ParseOptions options = new ParseOptions();
    options.setResolveFully(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) Test(org.testng.annotations.Test)

Example 17 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue 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 18 with AuthorizationValue

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

the class OpenAPIV3ParserTest method testInlineModelResolver.

@Test
public void testInlineModelResolver(@Injectable final List<AuthorizationValue> auths) throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/flatten.json"));
    pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
    ParseOptions options = new ParseOptions();
    options.setFlatten(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options);
    Assert.assertNotNull(result);
    OpenAPI openAPI = result.getOpenAPI();
    Assert.assertNotNull(openAPI);
    Schema user = openAPI.getComponents().getSchemas().get("User");
    assertNotNull(user);
    Schema address = (Schema) user.getProperties().get("address");
    assertTrue((address.get$ref() != null));
    Schema userAddress = openAPI.getComponents().getSchemas().get("User_address");
    assertNotNull(userAddress);
    assertNotNull(userAddress.getProperties().get("city"));
    assertNotNull(userAddress.getProperties().get("street"));
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) 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) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 19 with AuthorizationValue

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

the class OpenAPIV3ParserTest method testRemotePathItemIssue1103.

@Test
public void testRemotePathItemIssue1103(@Injectable final List<AuthorizationValue> auths) throws Exception {
    OpenAPI result = new OpenAPIV3Parser().read("issue-1103/remote-pathItem-swagger.yaml");
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getPaths().get("/Translation/{lang}"));
    Assert.assertEquals(result.getPaths().get("/Translation/{lang}").getPut().getParameters().get(0).getName(), "lang");
}
Also used : OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 20 with AuthorizationValue

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

the class OpenAPIV3ParserTest method testComposedSchemaAdjacent.

@Test
public void testComposedSchemaAdjacent(@Injectable final List<AuthorizationValue> auths) throws Exception {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/composedSchemaRef.yaml", auths, options);
    Assert.assertNotNull(openAPI);
    Assert.assertTrue(openAPI.getComponents().getSchemas().size() == 5);
    Schema schema = openAPI.getPaths().get("/path").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
    Assert.assertTrue(schema instanceof ComposedSchema);
    ComposedSchema composedSchema = (ComposedSchema) schema;
    Assert.assertTrue(composedSchema.getOneOf().size() == 2);
    Assert.assertTrue(composedSchema.getAllOf().size() == 1);
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) 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) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) 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