Search in sources :

Example 66 with Operation

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

the class ArrayPropertyDeserializerTest method testArrayDeserialization.

@Test(description = "it should includes the example in the arrayproperty")
public void testArrayDeserialization() throws Exception {
    Operation operation = Yaml.mapper().readValue(yaml, Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property responseSchema = response.getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof ArrayProperty);
    ArrayProperty mp = (ArrayProperty) responseSchema;
    assertNotNull(mp.getExample());
    assertEquals(mp.getMinItems(), new Integer(3));
    assertEquals(mp.getMaxItems(), new Integer(100));
}
Also used : Response(io.swagger.models.Response) ArrayProperty(io.swagger.models.properties.ArrayProperty) Operation(io.swagger.models.Operation) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 67 with Operation

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

the class MapPropertyDeserializerTest method testMapDeserializationVendorExtensions.

@Test(description = "vendor extensions should be included with object type")
public void testMapDeserializationVendorExtensions() throws Exception {
    Operation operation = Json.mapper().readValue(json, Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property responseSchema = response.getSchema();
    assertNotNull(responseSchema);
    MapProperty mp = (MapProperty) responseSchema;
    assertTrue(mp.getVendorExtensions().size() > 0);
    assertNotNull(mp.getVendorExtensions().get("x-foo"));
    assertEquals(mp.getVendorExtensions().get("x-foo"), "vendor x");
}
Also used : Response(io.swagger.models.Response) MapProperty(io.swagger.models.properties.MapProperty) Operation(io.swagger.models.Operation) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 68 with Operation

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

the class SpecFilterTest method filterAwaySecretParameters.

@Test(description = "it should filter away secret parameters")
public void filterAwaySecretParameters() throws IOException {
    final Swagger swagger = getSwagger("specFiles/sampleSpec.json");
    final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, Path> entry : filtered.getPaths().entrySet()) {
            final Operation get = entry.getValue().getGet();
            for (Parameter param : get.getParameters()) {
                final String description = param.getDescription();
                assertNotNull(description);
                assertFalse(description.startsWith("secret"));
            }
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 69 with Operation

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

the class SimpleReaderTest method checkResponseModelsProcessing.

@Test(description = "check response models processing")
public void checkResponseModelsProcessing() {
    Swagger swagger = getSwagger(ResourceWithTypedResponses.class);
    assertEquals(swagger.getDefinitions().keySet(), Arrays.asList("Tag"));
    for (Map.Entry<String, Path> entry : swagger.getPaths().entrySet()) {
        String name = entry.getKey().substring(entry.getKey().lastIndexOf("/") + 1);
        if ("testPrimitiveResponses".equals(name)) {
            Map<String, String[]> expected = ImmutableMap.of("400", new String[] { "string", "uri" }, "401", new String[] { "string", "url" }, "402", new String[] { "string", "uuid" }, "403", new String[] { "integer", "int64" }, "404", new String[] { "string", null });
            assertEquals(entry.getValue().getGet().getResponses().size(), expected.size());
            for (Map.Entry<String, Response> responseEntry : entry.getValue().getGet().getResponses().entrySet()) {
                String[] expectedProp = expected.get(responseEntry.getKey());
                Property property = responseEntry.getValue().getSchema();
                assertEquals(property.getType(), expectedProp[0]);
                assertEquals(property.getFormat(), expectedProp[1]);
            }
        } else {
            Operation op = entry.getValue().getGet();
            Property response = op.getResponses().get("200").getSchema();
            Model model = ((BodyParameter) op.getParameters().get(0)).getSchema();
            assertEquals(op.getParameters().size(), 1);
            if ("testObjectResponse".equals(name)) {
                assertEquals(((RefProperty) response).getSimpleRef(), "Tag");
                assertEquals(((RefModel) model).getSimpleRef(), "Tag");
            } else if ("testObjectsResponse".equals(name)) {
                assertEquals(((RefProperty) ((ArrayProperty) response).getItems()).getSimpleRef(), "Tag");
                assertEquals(((RefProperty) ((ArrayModel) model).getItems()).getSimpleRef(), "Tag");
            } else if ("testStringResponse".equals(name)) {
                assertEquals(response.getClass(), StringProperty.class);
                assertEquals(((ModelImpl) model).getType(), "string");
            } else if ("testStringsResponse".equals(name)) {
                assertEquals(((ArrayProperty) response).getItems().getClass(), StringProperty.class);
                assertEquals(((ArrayModel) model).getItems().getClass(), StringProperty.class);
            } else if ("testMapResponse".equals(name)) {
                assertEquals(((RefProperty) ((MapProperty) response).getAdditionalProperties()).getSimpleRef(), "Tag");
                assertNull(model.getProperties());
                assertEquals(((RefProperty) ((ModelImpl) model).getAdditionalProperties()).getSimpleRef(), "Tag");
            } else {
                fail(String.format("Unexpected property: %s", name));
            }
        }
    }
}
Also used : Path(io.swagger.models.Path) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) RefProperty(io.swagger.models.properties.RefProperty) ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) ResourceWithEmptyModel(io.swagger.resources.ResourceWithEmptyModel) RefModel(io.swagger.models.RefModel) ArrayModel(io.swagger.models.ArrayModel) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 70 with Operation

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

the class SimpleReaderTest method scanSimpleResourceWithoutAnnotations.

@Test(description = "scan a simple resource without annotations")
public void scanSimpleResourceWithoutAnnotations() {
    DefaultReaderConfig config = new DefaultReaderConfig();
    config.setScanAllResources(true);
    Swagger swagger = new Reader(new Swagger(), config).read(SimpleResourceWithoutAnnotations.class);
    assertEquals(swagger.getPaths().size(), 2);
    Operation get = getGet(swagger, "/{id}");
    assertNotNull(get);
    assertEquals(get.getParameters().size(), 2);
    PathParameter param1 = (PathParameter) get.getParameters().get(0);
    assertEquals(param1.getIn(), "path");
    assertEquals(param1.getName(), "id");
    assertTrue(param1.getRequired());
    assertNull(param1.getDescription());
    assertEquals(param1.getDefaultValue(), "5");
    Parameter param2 = get.getParameters().get(1);
    assertEquals(param2.getIn(), "query");
    assertEquals(param2.getName(), "limit");
    assertFalse(param2.getRequired());
    assertNull(param2.getDescription());
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) DefaultReaderConfig(io.swagger.jaxrs.config.DefaultReaderConfig) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Aggregations

Operation (io.swagger.models.Operation)118 Test (org.testng.annotations.Test)80 Swagger (io.swagger.models.Swagger)45 Path (io.swagger.models.Path)39 BodyParameter (io.swagger.models.parameters.BodyParameter)27 Property (io.swagger.models.properties.Property)24 Response (io.swagger.models.Response)23 Parameter (io.swagger.models.parameters.Parameter)20 RefProperty (io.swagger.models.properties.RefProperty)16 ArrayModel (io.swagger.models.ArrayModel)15 Model (io.swagger.models.Model)14 QueryParameter (io.swagger.models.parameters.QueryParameter)13 StringProperty (io.swagger.models.properties.StringProperty)13 HashMap (java.util.HashMap)13 ArrayProperty (io.swagger.models.properties.ArrayProperty)12 ReaderContext (io.swagger.servlet.ReaderContext)12 PathParameter (io.swagger.models.parameters.PathParameter)11 ArrayList (java.util.ArrayList)11 MapProperty (io.swagger.models.properties.MapProperty)10 NicknamedOperation (io.swagger.resources.NicknamedOperation)10