Search in sources :

Example 46 with SwaggerDeserializationResult

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

the class NetworkReferenceTests method testIssue330.

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

        {
            remoteUrl.urlToString("http://server1/resources/swagger.yaml", new ArrayList<AuthorizationValue>());
            result = issue_330_yaml;
            remoteUrl.urlToString("http://server1/resources/common/paging.yaml", new ArrayList<AuthorizationValue>());
            result = issue_330_paging_yaml;
            remoteUrl.urlToString("http://server1/resources/common/users.yaml", new ArrayList<AuthorizationValue>());
            result = issue_330_users_yaml;
            remoteUrl.urlToString("http://server2/resources/common/entities.yaml", new ArrayList<AuthorizationValue>());
            result = issue_330_entities_yaml;
        }
    };
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("http://server1/resources/swagger.yaml", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPath("/events"));
    assertNotNull(swagger.getDefinitions().get("Address"));
    assertNotNull(swagger.getDefinitions().get("Paging"));
    assertNotNull(swagger.getDefinitions().get("users"));
    assertNotNull(swagger.getDefinitions().get("Phone"));
}
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 47 with SwaggerDeserializationResult

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

the class ResponseResolverTest method testIssue211.

@Test
public void testIssue211() throws Exception {
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(spec);
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger);
    assertNotNull(swagger.getPath("/persons").getGet().getResponses().get("200"));
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 48 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testPetstore.

@Test
public void testPetstore() throws Exception {
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo("src/test/resources/petstore.json", null, true);
    assertNotNull(result);
    assertTrue(result.getMessages().isEmpty());
    Swagger swagger = result.getSwagger();
    Map<String, Model> definitions = swagger.getDefinitions();
    Set<String> expectedDefinitions = new HashSet<String>();
    expectedDefinitions.add("User");
    expectedDefinitions.add("Category");
    expectedDefinitions.add("Pet");
    expectedDefinitions.add("Tag");
    expectedDefinitions.add("Order");
    expectedDefinitions.add("PetArray");
    assertEquals(definitions.keySet(), expectedDefinitions);
    Model petModel = definitions.get("Pet");
    Set<String> expectedPetProps = new HashSet<String>();
    expectedPetProps.add("id");
    expectedPetProps.add("category");
    expectedPetProps.add("name");
    expectedPetProps.add("photoUrls");
    expectedPetProps.add("tags");
    expectedPetProps.add("status");
    assertEquals(petModel.getProperties().keySet(), expectedPetProps);
    ArrayModel petArrayModel = (ArrayModel) definitions.get("PetArray");
    assertEquals(petArrayModel.getType(), "array");
    RefProperty refProp = (RefProperty) petArrayModel.getItems();
    assertEquals(refProp.get$ref(), "#/definitions/Pet");
    assertNull(petArrayModel.getProperties());
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) ArrayModel(io.swagger.models.ArrayModel) ArrayModel(io.swagger.models.ArrayModel) HashSet(java.util.HashSet) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 49 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testIssue.

@Test
public void testIssue() {
    String yaml = "swagger: '2.0'\n" + "info:\n" + "  description: 'No description provided.'\n" + "  version: '2.0'\n" + "  title: 'My web service'\n" + "  x-endpoint-name: 'default'\n" + "paths:\n" + "  x-nothing: 'sorry not supported'\n" + "  /foo:\n" + "    x-something: 'yes, it is supported'\n" + "    get:\n" + "      parameters: []\n" + "      responses:\n" + "        200:\n" + "          description: 'Swagger API document for this service'\n" + "x-some-vendor:\n" + "  sometesting: 'bye!'";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Swagger swagger = result.getSwagger();
    assertEquals(((Map) swagger.getVendorExtensions().get("x-some-vendor")).get("sometesting"), "bye!");
    assertEquals(swagger.getPath("/foo").getVendorExtensions().get("x-something"), "yes, it is supported");
    assertTrue(result.getMessages().size() == 1);
    assertEquals(result.getMessages().get(0), "attribute paths.x-nothing is unsupported");
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 50 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testIssue243.

@Test
public void testIssue243() {
    String yaml = "swagger: \"2.0\"\n" + "info:\n" + "  version: 0.0.0\n" + "  title: Simple API\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "          schema:\n" + "            $ref: \"#/definitions/Simple\"\n" + "definitions:\n" + "  Simple:\n" + "    type: string";
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml);
    assertNotNull(result.getSwagger());
}
Also used : 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