Search in sources :

Example 21 with ArrayModel

use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.

the class PostParamTest method findPostOperationWithObjectsCollection.

@Test(description = "find a Post operation with collection of objects")
public void findPostOperationWithObjectsCollection() {
    Path petPath = getPath("collectionOfObjects");
    assertNotNull(petPath);
    Operation petPost = petPath.getPost();
    assertNotNull(petPost);
    assertEquals(petPost.getParameters().size(), 1);
    BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
    assertEquals(petPostBodyParam.getName(), BODY);
    Model inputModel = petPostBodyParam.getSchema();
    assertTrue(inputModel instanceof ArrayModel);
    ArrayModel ap = (ArrayModel) inputModel;
    Property inputSchema = ap.getItems();
    assertTrue(inputSchema instanceof RefProperty);
    RefProperty rm = (RefProperty) inputSchema;
    assertEquals(rm.getSimpleRef(), PET);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 22 with ArrayModel

use of io.swagger.models.ArrayModel in project swagger-core by swagger-api.

the class PostParamTest method findAPostOperationWithStringsList.

@Test(description = "find a Post operation with list of strings")
public void findAPostOperationWithStringsList() {
    Path petPath = getPath("listOfStrings");
    assertNotNull(petPath);
    Operation petPost = petPath.getPost();
    assertNotNull(petPost);
    assertEquals(petPost.getParameters().size(), 1);
    BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
    assertEquals(petPostBodyParam.getName(), BODY);
    Model inputModel = petPostBodyParam.getSchema();
    assertTrue(inputModel instanceof ArrayModel);
    ArrayModel ap = (ArrayModel) inputModel;
    Property inputSchema = ap.getItems();
    assertTrue(inputSchema instanceof StringProperty);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 23 with ArrayModel

use of io.swagger.models.ArrayModel 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 24 with ArrayModel

use of io.swagger.models.ArrayModel 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 25 with ArrayModel

use of io.swagger.models.ArrayModel in project swagger-parser by swagger-api.

the class SwaggerCompatConverter method modelFromExtendedTypedObject.

public Model modelFromExtendedTypedObject(ExtendedTypedObject obj) {
    String type = obj.getType() == null ? null : obj.getType().toString();
    String format = obj.getFormat() == null ? null : obj.getFormat().toString();
    Model output = null;
    if (obj.getRef() != null) {
        output = new RefModel().asDefault(obj.getRef());
    } else {
        if ("array".equals(type)) {
            ArrayModel am = new ArrayModel();
            Items items = obj.getItems();
            type = items.getType() == null ? null : items.getType().toString();
            format = items.getFormat() == null ? null : items.getFormat().toString();
            Property innerType = PropertyBuilder.build(type, format, null);
            if (innerType != null) {
                am.setItems(innerType);
            }
            if (items.getRef() != null) {
                am.setItems(new RefProperty(items.getRef()));
            } else {
                am.setItems(new RefProperty(type));
            }
            output = am;
        } else {
            Property input = PropertyBuilder.build(type, format, null);
            if (input != null) {
                output = PropertyBuilder.toModel(input);
            } else if (!"void".equals(type)) {
                // use ref model
                output = new RefModel().asDefault(type);
            }
        }
    }
    return output;
}
Also used : RefModel(io.swagger.models.RefModel) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ArrayModel(io.swagger.models.ArrayModel) Items(io.swagger.models.apideclaration.Items) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelProperty(io.swagger.models.apideclaration.ModelProperty) RefProperty(io.swagger.models.properties.RefProperty) UntypedProperty(io.swagger.models.properties.UntypedProperty) RefProperty(io.swagger.models.properties.RefProperty)

Aggregations

ArrayModel (io.swagger.models.ArrayModel)27 Test (org.testng.annotations.Test)21 Model (io.swagger.models.Model)17 BodyParameter (io.swagger.models.parameters.BodyParameter)17 Operation (io.swagger.models.Operation)15 RefProperty (io.swagger.models.properties.RefProperty)14 Property (io.swagger.models.properties.Property)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 StringProperty (io.swagger.models.properties.StringProperty)9 Swagger (io.swagger.models.Swagger)7 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 ComposedModel (io.swagger.models.ComposedModel)4 ModelImpl (io.swagger.models.ModelImpl)4 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)4 Response (io.swagger.models.Response)3 ApiOperation (io.swagger.annotations.ApiOperation)2 FormParameter (io.swagger.models.parameters.FormParameter)2 HeaderParameter (io.swagger.models.parameters.HeaderParameter)2 Parameter (io.swagger.models.parameters.Parameter)2