Search in sources :

Example 66 with Parameter

use of io.swagger.models.parameters.Parameter 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)

Example 67 with Parameter

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

the class SubResourceReaderTest method readAnotherResourceWithSubresources.

@Test(description = "scan another resource with subresources")
public void readAnotherResourceWithSubresources() {
    final Swagger swagger = getSwagger(TestResource.class);
    final Operation get = getGet(swagger, "/test/more/otherStatus");
    assertEquals(get.getOperationId(), "otherStatus");
    final Parameter qp = get.getParameters().get(0);
    assertEquals(qp.getIn(), "query");
    assertEquals(qp.getName(), "qp");
    assertTrue(get.getProduces().containsAll(Arrays.asList("application/json", "application/xml")));
    assertEquals(swagger.getPaths().keySet().size(), 2);
}
Also used : Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 68 with Parameter

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

the class ReaderTest method scanParametersFromBaseResource.

@Test(description = "it should scan parameters from base resource class")
public void scanParametersFromBaseResource() {
    Swagger swagger = getSwagger(BookResource.class);
    assertNotNull(swagger);
    List<Parameter> parameters = getGet(swagger, "/{id}/v1/books/{name}").getParameters();
    assertEquals(parameters.size(), 4);
    Parameter description = parameters.get(0);
    assertTrue(description instanceof PathParameter);
    assertEquals(description.getName(), "description");
    assertEquals(description.getDescription(), "Overridden description");
    Parameter id = parameters.get(1);
    assertTrue(id instanceof PathParameter);
    assertEquals(id.getName(), "id");
    assertEquals(id.getDescription(), "The Identifier of entity");
    Parameter test = parameters.get(2);
    assertTrue(test instanceof QueryParameter);
    assertEquals(test.getName(), "test");
    assertEquals(test.getDescription(), "Test Query Param");
    Parameter name = parameters.get(3);
    assertTrue(name instanceof PathParameter);
    assertEquals(name.getName(), "name");
    assertEquals(name.getDescription(), "The books name");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 69 with Parameter

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

the class RegexPathParamTest method scanSimpleResource.

@Test(description = "scan a simple resource")
public void scanSimpleResource() {
    Swagger swagger = new Reader(new Swagger()).read(RegexPathParamResource.class);
    Operation get = swagger.getPaths().get("/{report_type}").getGet();
    Parameter param = get.getParameters().get(0);
    assertEquals(param.getName(), "report_type");
    assertEquals(param.getPattern(), "[aA-zZ]+");
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 70 with Parameter

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

the class SimpleReaderTest method scanClassWithReadOnlyAndEmptyValueParams.

@Test(description = "scan a resource with read-only and empty value parameters")
public void scanClassWithReadOnlyAndEmptyValueParams() {
    Swagger swagger = getSwagger(Issue1979Resource.class);
    Parameter readOnlyParam = swagger.getPath("/fun/readOnly").getGet().getParameters().get(0);
    assertTrue(readOnlyParam.isReadOnly());
    Parameter allowEmptyParam = swagger.getPath("/fun/allowEmpty").getGet().getParameters().get(0);
    assertTrue(allowEmptyParam.getAllowEmptyValue());
}
Also used : Swagger(io.swagger.models.Swagger) 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) Test(org.testng.annotations.Test)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)92 BodyParameter (io.swagger.models.parameters.BodyParameter)54 QueryParameter (io.swagger.models.parameters.QueryParameter)53 PathParameter (io.swagger.models.parameters.PathParameter)51 Test (org.testng.annotations.Test)51 HeaderParameter (io.swagger.models.parameters.HeaderParameter)38 Swagger (io.swagger.models.Swagger)33 FormParameter (io.swagger.models.parameters.FormParameter)27 Operation (io.swagger.models.Operation)20 SerializableParameter (io.swagger.models.parameters.SerializableParameter)15 Type (java.lang.reflect.Type)14 ArrayList (java.util.ArrayList)14 Annotation (java.lang.annotation.Annotation)10 Path (io.swagger.models.Path)9 Method (java.lang.reflect.Method)9 JavaType (com.fasterxml.jackson.databind.JavaType)7 ContextParameter (io.servicecomb.swagger.extend.parameter.ContextParameter)6 Property (io.swagger.models.properties.Property)6 HashMap (java.util.HashMap)6 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)5