Search in sources :

Example 36 with AuthorizationValue

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

the class NetworkReferenceTest method testIssue742.

@Test
public void testIssue742() throws Exception {
    final List<AuthorizationValue> auths = new ArrayList<>();
    new Expectations() {

        {
            remoteUrl.urlToString("http://www.example.io/one/two/swagger.json", auths);
            result = issue_742_json;
        }
    };
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = parser.readLocation("http://www.example.io/one/two/swagger.json", auths, options);
    Assert.assertNotNull(result.getOpenAPI());
    Assert.assertNotNull(result.getOpenAPI().getServers());
    Assert.assertEquals(result.getOpenAPI().getServers().size(), 4);
    Assert.assertEquals(result.getOpenAPI().getServers().get(0).getDescription(), "An absolute path");
    Assert.assertEquals(result.getOpenAPI().getServers().get(0).getUrl(), "https://api.absolute.org/v2");
    Assert.assertEquals(result.getOpenAPI().getServers().get(1).getDescription(), "Server relative to root path");
    Assert.assertEquals(result.getOpenAPI().getServers().get(1).getUrl(), "http://www.example.io/api/v2");
    Assert.assertEquals(result.getOpenAPI().getServers().get(2).getDescription(), "Server relative path 1");
    Assert.assertEquals(result.getOpenAPI().getServers().get(2).getUrl(), "http://www.example.io/one/two/path/v2");
    Assert.assertEquals(result.getOpenAPI().getServers().get(3).getDescription(), "Server relative path 2");
    Assert.assertEquals(result.getOpenAPI().getServers().get(3).getUrl(), "http://www.example.io/one/v2");
}
Also used : Expectations(mockit.Expectations) AuthorizationValue(io.swagger.v3.parser.core.models.AuthorizationValue) ArrayList(java.util.ArrayList) 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 37 with AuthorizationValue

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

the class OpenAPIResolverTest method allOfExampleGeneration.

@Test
public void allOfExampleGeneration(@Injectable final List<AuthorizationValue> auths) throws JsonProcessingException {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/simpleAllOf.yaml", null, options);
    Assert.assertNotNull(openAPI);
    Object withoutExample = openAPI.getPaths().get("/foo").getGet().getResponses().get("200").getContent().get("application/json").getSchema().getExample();
    Assert.assertNull(withoutExample);
    Object withExample = openAPI.getPaths().get("/bar").getGet().getResponses().get("200").getContent().get("application/json").getSchema().getExample();
    Assert.assertEquals("{\"someProperty\":\"ABC\",\"someOtherProperty\":42}", Json.mapper().writeValueAsString(withExample));
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 38 with AuthorizationValue

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

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

the class OpenAPIResolverTest method testIssue1161.

@Test
public void testIssue1161(@Injectable final List<AuthorizationValue> auths) {
    String path = "/issue-1161/swagger.yaml";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readLocation(path, auths, options).getOpenAPI();
    Schema petsSchema = openAPI.getComponents().getSchemas().get("Pets");
    Schema colouringsSchema = openAPI.getComponents().getSchemas().get("Colouring");
    assertNotNull(petsSchema);
    assertNotNull(colouringsSchema);
    assertTrue(petsSchema instanceof ComposedSchema);
    assertTrue(petsSchema.getProperties() != null);
    assertTrue(((ComposedSchema) petsSchema).getOneOf() != null);
    Schema petsColouringProperty = (Schema) petsSchema.getProperties().get("colouring");
    assertTrue(petsColouringProperty.get$ref() == null);
    assertTrue(petsColouringProperty == colouringsSchema);
}
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) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 40 with AuthorizationValue

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

the class OpenAPIV3ParserTest method test30NoOptions.

@Test
public void test30NoOptions(@Injectable final List<AuthorizationValue> auths) throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
    pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, null);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
    assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
    assertEquals(result.getOpenAPI().getComponents().getSchemas().get("OrderRef").getType(), "object");
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) 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