Search in sources :

Example 6 with ParseOptions

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

the class FileReferenceTest method testIssue421.

@Test
public void testIssue421() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-421.yaml", null, options);
    assertNotNull(result.getOpenAPI());
    OpenAPI swagger = result.getOpenAPI();
    assertNotNull(swagger.getPaths().get("/pet/{petId}"));
    assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet());
    assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet().getParameters());
    assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().size() == 1);
    assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().get(0).getName().equals("petId"));
    assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema);
    assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 6);
    assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost());
    assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost().getParameters());
    assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getParameters().size() == 1);
    assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody() != null);
    assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref() != null);
    assertEquals(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref(), "#/components/requestBodies/requestBody");
    assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref().equals("#/components/requestBodies/requestBody"));
    assertNotNull(swagger.getPaths().get("/store/order"));
    assertNotNull(swagger.getPaths().get("/store/order").getPost());
    assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody());
    assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema());
    assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref() != null);
    assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref().equals("#/components/schemas/Order"));
    assertTrue(swagger.getComponents().getSchemas().get("Order") instanceof Schema);
    assertTrue(swagger.getComponents().getSchemas().get("Order").getProperties().size() == 6);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) 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 7 with ParseOptions

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

the class OAIDeserializationTest method testDeserializeSimpleDefinition.

@Test
public void testDeserializeSimpleDefinition() throws Exception {
    String json = "{\n" + "  \"openapi\": \"3.0.1\",\n" + "  \"info\": {\n" + "    \"title\": \"Swagger Petstore\",\n" + "    \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\",\n" + "    \"termsOfService\": \"http://swagger.io/terms/\",\n" + "    \"contact\": {\n" + "      \"email\": \"apiteam@swagger.io\"\n" + "    },\n" + "    \"license\": {\n" + "      \"name\": \"Apache 2.0\",\n" + "      \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + "    },\n" + "    \"version\": \"1.0.0\"\n" + "  }\n" + "}";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(json, null, options);
    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) Test(org.testng.annotations.Test)

Example 8 with ParseOptions

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

the class NetworkReferenceTest method testIssue330.

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

        {
            remoteUrl.urlToString("http://server1/resources/swagger.yaml", new ArrayList<>());
            result = issue_330_yaml;
            remoteUrl.urlToString("http://server1/resources/common/paging.yaml", new ArrayList<>());
            result = issue_330_paging_yaml;
            remoteUrl.urlToString("http://server1/resources/common/users.yaml", new ArrayList<>());
            result = issue_330_users_yaml;
            remoteUrl.urlToString("http://server2/resources/common/entities.yaml", new ArrayList<>());
            result = issue_330_entities_yaml;
        }
    };
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("http://server1/resources/swagger.yaml", new ArrayList<>(), options);
    assertNotNull(result.getOpenAPI());
    OpenAPI swagger = result.getOpenAPI();
    assertNotNull(swagger.getPaths().get("/events"));
    assertNotNull(swagger.getComponents().getSchemas().get("Address"));
    assertNotNull(swagger.getComponents().getSchemas().get("Paging"));
    assertNotNull(swagger.getComponents().getSchemas().get("users"));
    assertNotNull(swagger.getComponents().getSchemas().get("Phone"));
}
Also used : Expectations(mockit.Expectations) 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 9 with ParseOptions

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

the class OpenAPIResolverTest method referringSpecWithoutComponentsTag.

@Test
public void referringSpecWithoutComponentsTag() throws Exception {
    ParseOptions resolve = new ParseOptions();
    resolve.setResolveFully(true);
    final OpenAPI openAPI = new OpenAPIV3Parser().read("./ref-without-component/a.yaml", null, resolve);
    Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
    Assert.assertEquals("Example value", schemas.get("CustomerType").getExample());
}
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) Test(org.testng.annotations.Test)

Example 10 with ParseOptions

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

the class OpenAPIResolverTest method testIssue1352.

@Test
public void testIssue1352(@Injectable final List<AuthorizationValue> auths) {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-1352.json", auths, options).getOpenAPI();
    assertNull(openAPI.getPaths().get("/responses").getPatch().getResponses().get("200").getHeaders().get("x-my-secret-header").getSchema().get$ref());
}
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)

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