Search in sources :

Example 11 with SwaggerDeserializationResult

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

the class NetworkReferenceTests method testIssue411.

@Test
public void testIssue411() throws Exception {
    final List<AuthorizationValue> auths = new ArrayList<>();
    AuthorizationValue auth = new AuthorizationValue("Authorization", "OMG_SO_SEKR3T", "header");
    auths.add(auth);
    new Expectations() {

        {
            remoteUrl.urlToString("http://remote1/resources/swagger.json", auths);
            result = issue_411_server;
            remoteUrl.urlToString("http://remote2/resources/foo", auths);
            result = issue_411_components;
        }
    };
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo("http://remote1/resources/swagger.json", auths, true);
    Json.prettyPrint(result);
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPath("/health"));
    Path health = swagger.getPath("/health");
    assertTrue(health.getGet().getParameters().size() == 0);
    Object responseRef = health.getGet().getResponses().get("200").getSchema();
    assertTrue(responseRef instanceof RefProperty);
    RefProperty refProperty = (RefProperty) responseRef;
    assertEquals(refProperty.get$ref(), "#/definitions/Success");
    assertNotNull(swagger.getDefinitions().get("Success"));
    Parameter param = swagger.getPath("/stuff").getGet().getParameters().get(0);
    assertEquals(param.getIn(), "query");
    assertEquals(param.getName(), "skip");
    Response response = swagger.getPath("/stuff").getGet().getResponses().get("200");
    assertNotNull(response);
    assertTrue(response.getSchema() instanceof StringProperty);
    Response error = swagger.getPath("/stuff").getGet().getResponses().get("400");
    assertNotNull(error);
    Property errorProp = error.getSchema();
    assertNotNull(errorProp);
    assertTrue(errorProp instanceof RefProperty);
    RefProperty errorProperty = (RefProperty) errorProp;
    assertEquals(errorProperty.get$ref(), "#/definitions/Error");
    assertTrue(swagger.getDefinitions().get("Error") instanceof ModelImpl);
}
Also used : Expectations(mockit.Expectations) Path(io.swagger.models.Path) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) ArrayList(java.util.ArrayList) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 12 with SwaggerDeserializationResult

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

the class NetworkReferenceTests method testIssue323.

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

        {
            remoteUrl.urlToString("http://localhost:8080/nested-file-references/issue-323.yaml", new ArrayList<AuthorizationValue>());
            result = issue_323_yaml;
            remoteUrl.urlToString("http://localhost:8080/nested-file-references/eventsCase9.yaml", new ArrayList<AuthorizationValue>());
            result = issue_323_events_yaml;
            remoteUrl.urlToString("http://localhost:8080/nested-file-references/common/pagingWithFolderRef.yaml", new ArrayList<AuthorizationValue>());
            result = issue_323_paging_yaml;
            remoteUrl.urlToString("http://localhost:8080/nested-file-references/common/common2/bar.yaml", new ArrayList<AuthorizationValue>());
            result = issue_323_bar_yaml;
        }
    };
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("http://localhost:8080/nested-file-references/issue-323.yaml", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPath("/events"));
    assertNotNull(swagger.getDefinitions().get("StatusResponse"));
    assertNotNull(swagger.getDefinitions().get("Paging"));
    assertNotNull(swagger.getDefinitions().get("Foobar"));
}
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 13 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testIssue450.

@Test
public void testIssue450() {
    String desc = "An array of Pets";
    String xTag = "x-my-tag";
    String xVal = "An extension tag";
    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" + "definitions:\n" + "  PetArray:\n" + "    type: array\n" + "    items:\n" + "      $ref: \"#/definitions/Pet\"\n" + "    description: " + desc + "\n" + "    " + xTag + ": " + xVal + "\n" + "  Pet:\n" + "    type: object\n" + "    properties:\n" + "      id:\n" + "        type: string";
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml);
    assertNotNull(result.getSwagger());
    final Swagger swagger = result.getSwagger();
    Model petArray = swagger.getDefinitions().get("PetArray");
    assertNotNull(petArray);
    assertTrue(petArray instanceof ArrayModel);
    assertEquals(petArray.getDescription(), desc);
    assertNotNull(petArray.getVendorExtensions());
    assertNotNull(petArray.getVendorExtensions().get(xTag));
    assertEquals(petArray.getVendorExtensions().get(xTag), xVal);
}
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) Test(org.testng.annotations.Test)

Example 14 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testIssue292WithCSVCollectionFormat.

@Test
public void testIssue292WithCSVCollectionFormat() {
    String yaml = "swagger: '2.0'\n" + "info:\n" + "  version: '0.0.0'\n" + "  title: nada\n" + "paths:\n" + "  /persons:\n" + "    get:\n" + "      parameters:\n" + "      - name: testParam\n" + "        in: query\n" + "        type: array\n" + "        items:\n" + "          type: string\n" + "        collectionFormat: csv\n" + "      responses:\n" + "        200:\n" + "          description: Successful response";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Swagger swagger = result.getSwagger();
    Parameter param = swagger.getPaths().get("/persons").getGet().getParameters().get(0);
    QueryParameter qp = (QueryParameter) param;
    assertEquals(qp.getCollectionFormat(), "csv");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) FormParameter(io.swagger.models.parameters.FormParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.testng.annotations.Test)

Example 15 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testConverterIssue17.

@Test
public void testConverterIssue17() throws Exception {
    String yaml = "swagger: '2.0'\n" + "info:\n" + "  version: '0.0.0'\n" + "  title: nada\n" + "paths:\n" + "  /persons:\n" + "    get:\n" + "      parameters:\n" + "      - name: testParam\n" + "        in: query\n" + "        type: array\n" + "        items:\n" + "          type: string\n" + "        collectionFormat: csv\n" + "      responses:\n" + "        200:\n" + "          description: Successful response\n" + "          schema:\n" + "            $ref: '#/definitions/Content'\n" + "definitions:\n" + "  Content:\n" + "    type: object";
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml, Boolean.FALSE);
    assertNotNull(result.getSwagger());
    assertEquals(((RefProperty) result.getSwagger().getPaths().get("/persons").getGet().getResponses().get("200").getSchema()).get$ref(), "#/definitions/Content");
}
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