Search in sources :

Example 26 with PathParameter

use of io.swagger.models.parameters.PathParameter in project java-chassis by ServiceComb.

the class TestPath method testUrlPathBuilder.

@Test
public void testUrlPathBuilder() throws Exception {
    Map<String, RestParam> paramMap = new HashMap<>();
    Parameter pathParameter = new PathParameter();
    pathParameter.setName("id");
    RestParam oRestParam = new RestParam(pathParameter, int.class);
    paramMap.put(oRestParam.getParamName(), oRestParam);
    Parameter queryParameter = new QueryParameter();
    queryParameter.setName("q");
    oRestParam = new RestParam(queryParameter, String.class);
    paramMap.put(oRestParam.getParamName(), oRestParam);
    URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("id", 100);
    parameters.put("q", "query");
    Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(parameters));
    Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(parameters));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) HashMap(java.util.HashMap) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.junit.Test)

Example 27 with PathParameter

use of io.swagger.models.parameters.PathParameter in project java-chassis by ServiceComb.

the class TestPathProcessorCreator method testCreate.

@Test
public void testCreate() {
    ParamValueProcessorCreator creator = ParamValueProcessorCreatorManager.INSTANCE.findValue(PathProcessorCreator.PARAMTYPE);
    Parameter parameter = new PathParameter();
    parameter.setName("path");
    ParamValueProcessor processor = creator.create(parameter, String.class);
    Assert.assertEquals(PathProcessor.class, processor.getClass());
}
Also used : PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.junit.Test)

Example 28 with PathParameter

use of io.swagger.models.parameters.PathParameter in project carbon-apimgt by wso2.

the class OAS2Parser method createOperation.

/**
 * Creates a new operation object using the URI template object
 *
 * @param resource API resource data
 * @return a new operation object using the URI template object
 */
private Operation createOperation(SwaggerData.Resource resource) {
    Operation operation = new Operation();
    List<String> pathParams = getPathParamNames(resource.getPath());
    for (String pathParam : pathParams) {
        PathParameter pathParameter = new PathParameter();
        pathParameter.setName(pathParam);
        pathParameter.setType("string");
        operation.addParameter(pathParameter);
    }
    updateOperationManagedInfo(resource, operation);
    Response response = new Response();
    response.setDescription("OK");
    operation.addResponse(APIConstants.SWAGGER_RESPONSE_200, response);
    return operation;
}
Also used : Response(io.swagger.models.Response) APIDefinitionValidationResponse(org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse) RefResponse(io.swagger.models.RefResponse) Operation(io.swagger.models.Operation) PathParameter(io.swagger.models.parameters.PathParameter)

Example 29 with PathParameter

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

the class ParameterProcessorTest method implicitParameterLongTypeProcessorTest.

@Test(description = "test for issue #1873 fixing.")
public void implicitParameterLongTypeProcessorTest() throws NoSuchMethodException {
    final ApiImplicitParams params = getClass().getDeclaredMethod("implicitParametrizedMethodLongType").getAnnotation(ApiImplicitParams.class);
    final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), String.class, Collections.<Annotation>singletonList(params.value()[0]));
    assertEquals(param0.getName(), "id");
    assertEquals(param0.getIn(), "path");
    assertEquals(param0.getRequired(), true);
    assertEquals(param0.getType(), "integer");
    assertEquals(param0.getFormat(), "int64");
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) PathParameter(io.swagger.models.parameters.PathParameter) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Example 30 with PathParameter

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

the class ParameterProcessorTest method implicitArrayParameterProcessorTest.

@Test(description = "parse implicit parameters from method")
public void implicitArrayParameterProcessorTest() throws NoSuchMethodException {
    final ApiImplicitParams params = getClass().getDeclaredMethod("implicitArrayParametrizedMethod").getAnnotation(ApiImplicitParams.class);
    final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), String.class, Collections.<Annotation>singletonList(params.value()[0]));
    assertEquals(param0.getType(), "array");
    assertEquals(param0.getItems().getType(), "string");
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) PathParameter(io.swagger.models.parameters.PathParameter) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Aggregations

PathParameter (io.swagger.models.parameters.PathParameter)51 QueryParameter (io.swagger.models.parameters.QueryParameter)35 Parameter (io.swagger.models.parameters.Parameter)32 Test (org.testng.annotations.Test)32 BodyParameter (io.swagger.models.parameters.BodyParameter)26 HeaderParameter (io.swagger.models.parameters.HeaderParameter)16 Swagger (io.swagger.models.Swagger)14 StringProperty (io.swagger.models.properties.StringProperty)12 FormParameter (io.swagger.models.parameters.FormParameter)11 Operation (io.swagger.models.Operation)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 Response (io.swagger.models.Response)8 IntegerProperty (io.swagger.models.properties.IntegerProperty)8 RefProperty (io.swagger.models.properties.RefProperty)8 Path (io.swagger.models.Path)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 HashMap (java.util.HashMap)6 ModelImpl (io.swagger.models.ModelImpl)5 RefModel (io.swagger.models.RefModel)5 ArrayList (java.util.ArrayList)5