Search in sources :

Example 51 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testIssue594.

@Test
public void testIssue594() {
    String yaml = "swagger: '2.0'\n" + "paths:\n" + "  /test:\n" + "    post:\n" + "      parameters:\n" + "        - name: body\n" + "          in: body\n" + "          description: Hello world\n" + "          schema:\n" + "            type: array\n" + "            minItems: 1\n" + "            maxItems: 1\n" + "            items: \n" + "              $ref: \"#/definitions/Pet\"\n" + "      responses:\n" + "        200:\n" + "          description: 'OK'\n";
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml);
    assertNotNull(result.getSwagger());
    ArrayModel schema = (ArrayModel) ((BodyParameter) result.getSwagger().getPaths().get("/test").getPost().getParameters().get(0)).getSchema();
    assertEquals(((RefProperty) schema.getItems()).get$ref(), "#/definitions/Pet");
    assertNotNull(schema.getMaxItems());
    assertNotNull(schema.getMinItems());
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 52 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testLoadNestedItemsReferences.

@Test
public void testLoadNestedItemsReferences() {
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo("src/test/resources/nested-items-references/b.yaml", null, true);
    Swagger swagger = result.getSwagger();
    Map<String, Model> definitions = swagger.getDefinitions();
    assertTrue(definitions.containsKey("z"));
    assertTrue(definitions.containsKey("w"));
}
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) Test(org.testng.annotations.Test)

Example 53 with SwaggerDeserializationResult

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

the class SwaggerParserTest method testCodegenIssue4555.

@Test
public void testCodegenIssue4555() throws Exception {
    SwaggerParser parser = new SwaggerParser();
    String yaml = "swagger: '2.0'\n" + "\n" + "info:\n" + "  title: test\n" + "  version: \"0.0.1\"\n" + "\n" + "schemes:\n" + "  - http\n" + "produces:\n" + "  - application/json\n" + "\n" + "paths:\n" + "  /contents/{id}:\n" + "    parameters:\n" + "      - name: id\n" + "        in: path\n" + "        description: test\n" + "        required: true\n" + "        type: integer\n" + "\n" + "    get:\n" + "      description: test\n" + "      responses:\n" + "        200:\n" + "          description: OK\n" + "          schema:\n" + "            $ref: '#/definitions/Content'\n" + "\n" + "definitions:\n" + "  Content:\n" + "    type: object\n" + "    title: \t\ttest";
    final SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    // can't parse with tabs!
    assertNull(result.getSwagger());
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Test(org.testng.annotations.Test)

Example 54 with SwaggerDeserializationResult

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

the class SwaggerReaderTest method testIssue206.

@Test(description = "issue 206, not supported yet")
public void testIssue206() {
    String spec = "swagger: '2.0'\n" + "paths: {}\n" + "definitions:\n" + "  Model:\n" + "    properties:\n" + "      name:\n" + "        type: string\n" + "        required: true";
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(spec);
// TODO: when 206 is resolved, enable the assertions here
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Test(org.testng.annotations.Test)

Example 55 with SwaggerDeserializationResult

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

the class SwaggerCompatConverter method readWithInfo.

@Override
public SwaggerDeserializationResult readWithInfo(String location, List<AuthorizationValue> auths) {
    SwaggerDeserializationResult result = new SwaggerDeserializationResult();
    try {
        Swagger swagger = read(location, auths);
        if (swagger != null) {
            result.setSwagger(swagger);
            JsonNode jsonNode = Json.mapper().convertValue(swagger, JsonNode.class);
            return new Swagger20Parser().readWithInfo(jsonNode);
        }
    } catch (IOException e) {
    // TODO
    }
    return result;
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

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