Search in sources :

Example 6 with SwaggerDeserializationResult

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

the class FileReferenceTests method testIssue316.

@Test
public void testIssue316() {
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-316.yaml", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPath("/events"));
    Path path = swagger.getPath("/events");
    assertNotNull(path.getGet());
    Operation get = path.getGet();
    assertEquals(get.getOperationId(), "getEvents");
    assertTrue(swagger.getDefinitions().size() == 3);
    assertTrue(swagger.getDefinitions().get("Foobar").getProperties().size() == 1);
    assertTrue(swagger.getDefinitions().get("StatusResponse").getProperties().size() == 1);
    assertTrue(swagger.getDefinitions().get("Paging2").getProperties().size() == 2);
    Model model = swagger.getDefinitions().get("Paging2");
    Property property = model.getProperties().get("foobar");
    assertTrue(property instanceof RefProperty);
    RefProperty ref = (RefProperty) property;
    assertEquals(ref.get$ref(), "#/definitions/Foobar");
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 7 with SwaggerDeserializationResult

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

the class FileReferenceTests method testRelativeRefIssue421.

@Test
public void testRelativeRefIssue421() {
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/main.yaml", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger);
    assertNotNull(swagger.getPath("pets"));
    assertNotNull(swagger.getPath("pets").getGet());
    assertNotNull(swagger.getPath("pets").getGet().getResponses());
    assertNotNull(swagger.getPath("pets").getGet().getResponses().get("200"));
    assertNotNull(swagger.getPath("pets").getGet().getResponses().get("200").getSchema());
    assertTrue(swagger.getPath("pets").getGet().getResponses().get("200").getSchema() instanceof RefProperty);
    assertEquals(((RefProperty) swagger.getPath("pets").getGet().getResponses().get("200").getSchema()).get$ref(), "#/definitions/Pet");
    assertTrue(swagger.getDefinitions().get("Pet") instanceof ModelImpl);
    assertTrue(swagger.getDefinitions().get("Pet").getProperties().size() == 2);
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 8 with SwaggerDeserializationResult

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

the class FileReferenceTests method testIssue336.

@Test
public void testIssue336() {
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-336.json", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPaths());
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Test(org.testng.annotations.Test)

Example 9 with SwaggerDeserializationResult

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

the class NetworkReferenceTests method testIssue335.

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

        {
            remoteUrl.urlToString("http://server1/resources/swagger.json", new ArrayList<AuthorizationValue>());
            result = issue_335_json;
            remoteUrl.urlToString("http://server1/resources/Bar.json", new ArrayList<AuthorizationValue>());
            result = issue_335_bar_json;
        }
    };
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("http://server1/resources/swagger.json", null, true);
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger);
    assertNotNull(swagger.getDefinitions());
    assertNotNull(swagger.getDefinitions().get("BarData"));
    assertNotNull(swagger.getDefinitions().get("BarSettingsRequest"));
}
Also used : Expectations(mockit.Expectations) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 10 with SwaggerDeserializationResult

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

the class NetworkReferenceTests method testPathReference.

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

        {
            remoteUrl.urlToString("http://petstore.swagger.io/v2/swagger.json", new ArrayList<AuthorizationValue>());
            result = issue_407_json;
        }
    };
    SwaggerParser parser = new SwaggerParser();
    String yaml = "swagger: '2.0'\n" + "info:\n" + "  description: |\n" + "  version: 1.0.0\n" + "  title: testing\n" + "paths:\n" + "   /foo:\n" + "     $ref: 'http://petstore.swagger.io/v2/swagger.json#/paths/~1pet'\n" + "   /bar:\n" + "     $ref: 'http://petstore.swagger.io/v2/swagger.json#/paths/~1pet'\n" + "schemes:\n" + " - https\n" + " - http";
    final SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Assert.assertNotNull(result.getSwagger());
    assertTrue(result.getMessages().size() == 0);
    assertTrue(result.getSwagger().getDefinitions().size() == 3);
}
Also used : Expectations(mockit.Expectations) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Test(org.testng.annotations.Test)

Aggregations

SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)56 Test (org.testng.annotations.Test)44 Swagger (io.swagger.models.Swagger)21 AuthorizationValue (io.swagger.models.auth.AuthorizationValue)10 SwaggerParser (io.swagger.parser.SwaggerParser)8 Expectations (mockit.Expectations)8 Parameter (io.swagger.models.parameters.Parameter)7 PathParameter (io.swagger.models.parameters.PathParameter)7 QueryParameter (io.swagger.models.parameters.QueryParameter)7 RefProperty (io.swagger.models.properties.RefProperty)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayModel (io.swagger.models.ArrayModel)5 Model (io.swagger.models.Model)5 RefModel (io.swagger.models.RefModel)5 BodyParameter (io.swagger.models.parameters.BodyParameter)5 ComposedModel (io.swagger.models.ComposedModel)4 Path (io.swagger.models.Path)4 ArrayProperty (io.swagger.models.properties.ArrayProperty)4 Property (io.swagger.models.properties.Property)4 IOException (java.io.IOException)4