Search in sources :

Example 11 with BodyParameter

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

the class SpecFilter method removeBrokenReferenceDefinitions.

private Swagger removeBrokenReferenceDefinitions(Swagger swagger) {
    if (swagger.getDefinitions() == null || swagger.getDefinitions().isEmpty())
        return swagger;
    Set<String> referencedDefinitions = new TreeSet<String>();
    if (swagger.getResponses() != null) {
        for (Response response : swagger.getResponses().values()) {
            String propertyRef = getPropertyRef(response.getSchema());
            if (propertyRef != null) {
                referencedDefinitions.add(propertyRef);
            }
        }
    }
    if (swagger.getParameters() != null) {
        for (Parameter p : swagger.getParameters().values()) {
            if (p instanceof BodyParameter) {
                BodyParameter bp = (BodyParameter) p;
                Set<String> modelRef = getModelRef(bp.getSchema());
                if (modelRef != null) {
                    referencedDefinitions.addAll(modelRef);
                }
            }
        }
    }
    if (swagger.getPaths() != null) {
        for (Path path : swagger.getPaths().values()) {
            if (path.getParameters() != null) {
                for (Parameter p : path.getParameters()) {
                    if (p instanceof BodyParameter) {
                        BodyParameter bp = (BodyParameter) p;
                        Set<String> modelRef = getModelRef(bp.getSchema());
                        if (modelRef != null) {
                            referencedDefinitions.addAll(modelRef);
                        }
                    }
                }
            }
            if (path.getOperations() != null) {
                for (Operation op : path.getOperations()) {
                    if (op.getResponses() != null) {
                        for (Response response : op.getResponses().values()) {
                            String propertyRef = getPropertyRef(response.getSchema());
                            if (propertyRef != null) {
                                referencedDefinitions.add(propertyRef);
                            }
                        }
                    }
                    if (op.getParameters() != null) {
                        for (Parameter p : op.getParameters()) {
                            if (p instanceof BodyParameter) {
                                BodyParameter bp = (BodyParameter) p;
                                Set<String> modelRef = getModelRef(bp.getSchema());
                                if (modelRef != null) {
                                    referencedDefinitions.addAll(modelRef);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (swagger.getDefinitions() != null) {
        Set<String> nestedReferencedDefinitions = new TreeSet<String>();
        for (String ref : referencedDefinitions) {
            locateReferencedDefinitions(ref, nestedReferencedDefinitions, swagger);
        }
        referencedDefinitions.addAll(nestedReferencedDefinitions);
        swagger.getDefinitions().keySet().retainAll(referencedDefinitions);
    }
    return swagger;
}
Also used : Response(io.swagger.models.Response) Path(io.swagger.models.Path) TreeSet(java.util.TreeSet) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter)

Example 12 with BodyParameter

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

the class PostParamTest method findAPostOperationWithStringsArray.

@Test(description = "find a Post operation with an array of strings")
public void findAPostOperationWithStringsArray() {
    Path petPath = getPath("arrayOfStrings");
    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 13 with BodyParameter

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

the class PostParamTest method findAPostOperationWithStringsCollection.

@Test(description = "find a Post operation with collection of strings")
public void findAPostOperationWithStringsCollection() {
    Path petPath = getPath("collectionOfStrings");
    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 14 with BodyParameter

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

the class PostParamTest method findAPostOperationWithSingleString.

@Test(description = "find a Post operation with single string")
public void findAPostOperationWithSingleString() {
    Path petPath = getPath("singleString");
    assertNotNull(petPath);
    assertNull(petPath.getGet());
    Operation petPost = petPath.getPost();
    assertNotNull(petPost);
    assertEquals(petPost.getParameters().size(), 1);
    BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
    assertEquals(petPostBodyParam.getName(), BODY);
    assertTrue(petPostBodyParam.getSchema() instanceof Model);
}
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) Test(org.testng.annotations.Test)

Example 15 with BodyParameter

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

the class PostParamTest method findAPostOperationWithObjectsArray.

@Test(description = "find a Post operation with an array of objects")
public void findAPostOperationWithObjectsArray() {
    Path petPath = getPath("arrayOfObjects");
    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)

Aggregations

BodyParameter (io.swagger.models.parameters.BodyParameter)46 Test (org.testng.annotations.Test)34 Operation (io.swagger.models.Operation)20 Parameter (io.swagger.models.parameters.Parameter)16 ArrayModel (io.swagger.models.ArrayModel)15 Model (io.swagger.models.Model)15 PathParameter (io.swagger.models.parameters.PathParameter)14 Path (io.swagger.models.Path)13 QueryParameter (io.swagger.models.parameters.QueryParameter)13 StringProperty (io.swagger.models.properties.StringProperty)13 Swagger (io.swagger.models.Swagger)11 Property (io.swagger.models.properties.Property)11 RefProperty (io.swagger.models.properties.RefProperty)11 ModelImpl (io.swagger.models.ModelImpl)7 RefModel (io.swagger.models.RefModel)7 HeaderParameter (io.swagger.models.parameters.HeaderParameter)7 SerializableParameter (io.swagger.models.parameters.SerializableParameter)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)5 PendingBodyParameter (io.servicecomb.swagger.extend.parameter.PendingBodyParameter)4 Response (io.swagger.models.Response)4