Search in sources :

Example 11 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams 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)

Example 12 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project swagger-core by swagger-api.

the class ParameterProcessorTest method implicitParameterProcessorTest.

@Test(description = "parse implicit parameters from method")
public void implicitParameterProcessorTest() throws NoSuchMethodException {
    final ApiImplicitParams params = getClass().getDeclaredMethod("implicitParametrizedMethod").getAnnotation(ApiImplicitParams.class);
    final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), String.class, Collections.<Annotation>singletonList(params.value()[0]));
    assertNotNull(param0);
    assertEquals(param0.getIn(), "path");
    assertEquals(param0.getName(), "paramName1");
    assertEquals(param0.getDescription(), "paramValue1");
    assertNull(param0.getEnum());
    assertNotNull(param0.getItems());
    final BodyParameter param1 = (BodyParameter) ParameterProcessor.applyAnnotations(null, new BodyParameter(), String.class, Collections.<Annotation>singletonList(params.value()[1]));
    assertNotNull(param1);
    assertEquals(param1.getIn(), "body");
    assertEquals(param1.getName(), "body");
    assertEquals(param1.getDescription(), "paramValue2");
    assertEquals(param1.getAccess(), "test");
    final ModelImpl model = (ModelImpl) param1.getSchema();
    assertNotNull(model);
    assertEquals(model.getDefaultValue(), "10");
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) PathParameter(io.swagger.models.parameters.PathParameter) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Example 13 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project indy by Commonjava.

the class AutoProxCatalogResource method createRule.

@ApiOperation(value = "Create an AutoProx rule", response = RuleDTO.class)
@ApiResponse(code = 201, message = "Rule created", responseHeaders = @ResponseHeader(name = "Location", description = "Resource location of the new rule"))
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.autoprox.rest.dto.RuleDTO", value = "The rule definition JSON") })
@POST
@Consumes(ApplicationContent.application_json)
public Response createRule(@Context final HttpServletRequest request, @Context final UriInfo uriInfo, @Context SecurityContext securityContext) {
    Response response = checkEnabled();
    if (response != null) {
        return response;
    }
    RuleDTO dto = null;
    try {
        dto = serializer.readValue(request.getInputStream(), RuleDTO.class);
    } catch (final IOException e) {
        final String message = "Failed to read " + RuleDTO.class.getSimpleName() + " from request body.";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    try {
        String user = securityManager.getUser(securityContext, request);
        dto = controller.storeRule(dto, user);
        final URI uri = uriInfo.getBaseUriBuilder().path(getClass()).path(dto.getName()).build();
        response = formatCreatedResponseWithJsonEntity(uri, dto, serializer);
    } catch (final AutoProxRuleException e) {
        final String message = "Failed to store rule: " + dto.getName() + ".";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) IOException(java.io.IOException) URI(java.net.URI) AutoProxRuleException(org.commonjava.indy.autoprox.data.AutoProxRuleException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 14 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project indy by Commonjava.

the class AutoProxCatalogResource method updateRule.

@ApiOperation(value = "Update an AutoProx rule", response = RuleDTO.class)
@ApiResponses({ @ApiResponse(code = 201, message = "Rule created", responseHeaders = @ResponseHeader(name = "Location", description = "Resource location of the new rule")), @ApiResponse(code = 200, message = "Existing rule updated") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.autoprox.rest.dto.RuleDTO", value = "The rule definition JSON (NOTE: Name will over OVERRIDDEN with value from storage path.)") })
@PUT
@Path("{name}")
@Consumes(ApplicationContent.application_json)
public Response updateRule(@PathParam("name") final String name, @Context final HttpServletRequest request, @Context final UriInfo uriInfo, @Context final SecurityContext securityContext) {
    Response response = checkEnabled();
    if (response != null) {
        return response;
    }
    RuleDTO dto = controller.getRule(name);
    boolean updating = true;
    if (dto == null) {
        updating = false;
    }
    try {
        dto = serializer.readValue(request.getInputStream(), RuleDTO.class);
        dto.setName(name);
    } catch (final IOException e) {
        final String message = "Failed to read " + RuleDTO.class.getSimpleName() + " from request body.";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    try {
        String user = securityManager.getUser(securityContext, request);
        dto = controller.storeRule(dto, user);
        if (updating) {
            response = ok().build();
        } else {
            final URI uri = uriInfo.getBaseUriBuilder().path(getClass()).path(dto.getName()).build();
            response = created(uri).build();
        }
    } catch (final AutoProxRuleException e) {
        final String message = "Failed to store rule: " + dto.getName() + ".";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) IOException(java.io.IOException) URI(java.net.URI) AutoProxRuleException(org.commonjava.indy.autoprox.data.AutoProxRuleException) Path(javax.ws.rs.Path) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 15 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project java-chassis by ServiceComb.

the class ApiImplicitParamsClassProcessor method process.

@Override
public void process(Object annotation, SwaggerGenerator swaggerGenerator) {
    ApiImplicitParams apiImplicitParamsAnnotation = (ApiImplicitParams) annotation;
    ClassAnnotationProcessor processor = swaggerGenerator.getContext().findClassAnnotationProcessor(ApiImplicitParam.class);
    for (ApiImplicitParam paramAnnotation : apiImplicitParamsAnnotation.value()) {
        processor.process(paramAnnotation, swaggerGenerator);
    }
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ClassAnnotationProcessor(io.servicecomb.swagger.generator.core.ClassAnnotationProcessor) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam)

Aggregations

ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)29 ApiOperation (io.swagger.annotations.ApiOperation)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 IOException (java.io.IOException)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Response (javax.ws.rs.core.Response)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 ApiResponse (io.swagger.annotations.ApiResponse)6 URI (java.net.URI)6 POST (javax.ws.rs.POST)6 Produces (javax.ws.rs.Produces)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 PathParameter (io.swagger.models.parameters.PathParameter)3