Search in sources :

Example 1 with ApiImplicitParams

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

the class ApiImplicitParamsMethodProcessor method process.

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

Example 2 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project vertx-swagger by bobxwang.

the class RestApiVerticle method handle.

@BBRouter(path = "/catalogue/products/:producttype/:productid", httpMethod = HttpMethod.GET)
@ApiImplicitParams({ @ApiImplicitParam(name = "producttype", value = "产品类型", required = true, dataType = "string", paramType = "path"), @ApiImplicitParam(name = "productid", value = "产品标识", dataType = "string", paramType = "path") })
private void handle(RoutingContext ctx) {
    String productType = ctx.request().getParam("producttype");
    String productID = ctx.request().getParam("productid");
    ctx.response().putHeader("content-type", "application/json;charset=UTF-8").end(new JsonObject().put("now", new Date().toString()).put("producttype", productType).put("productid", productID).encodePrettily());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Date(java.util.Date) BBRouter(com.bob.vertx.swagger.BBRouter) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams)

Example 3 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project nifi by apache.

the class ProcessGroupResource method uploadTemplate.

/**
 * Imports the specified template.
 *
 * @param httpServletRequest request
 * @param in                 The template stream
 * @return A templateEntity or an errorResponse XML snippet.
 * @throws InterruptedException if interrupted
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_XML)
@Path("{id}/templates/upload")
@ApiOperation(value = "Uploads a template", response = TemplateEntity.class, authorizations = { @Authorization(value = "Write - /process-groups/{uuid}") })
@ApiImplicitParams(value = { @ApiImplicitParam(name = "template", value = "The binary content of the template file being uploaded.", required = true, type = "file", paramType = "formData") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response uploadTemplate(@Context final HttpServletRequest httpServletRequest, @Context final UriInfo uriInfo, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId, @FormDataParam("template") final InputStream in) throws InterruptedException {
    // unmarshal the template
    final TemplateDTO template;
    try {
        JAXBContext context = JAXBContext.newInstance(TemplateDTO.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        XMLStreamReader xsr = XmlUtils.createSafeReader(in);
        JAXBElement<TemplateDTO> templateElement = unmarshaller.unmarshal(xsr, TemplateDTO.class);
        template = templateElement.getValue();
    } catch (JAXBException jaxbe) {
        logger.warn("An error occurred while parsing a template.", jaxbe);
        String responseXml = String.format("<errorResponse status=\"%s\" statusText=\"The specified template is not in a valid format.\"/>", Response.Status.BAD_REQUEST.getStatusCode());
        return Response.status(Response.Status.OK).entity(responseXml).type("application/xml").build();
    } catch (IllegalArgumentException iae) {
        logger.warn("Unable to import template.", iae);
        String responseXml = String.format("<errorResponse status=\"%s\" statusText=\"%s\"/>", Response.Status.BAD_REQUEST.getStatusCode(), iae.getMessage());
        return Response.status(Response.Status.OK).entity(responseXml).type("application/xml").build();
    } catch (Exception e) {
        logger.warn("An error occurred while importing a template.", e);
        String responseXml = String.format("<errorResponse status=\"%s\" statusText=\"Unable to import the specified template: %s\"/>", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
        return Response.status(Response.Status.OK).entity(responseXml).type("application/xml").build();
    }
    // build the response entity
    TemplateEntity entity = new TemplateEntity();
    entity.setTemplate(template);
    if (isReplicateRequest()) {
        // convert request accordingly
        final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.segment("process-groups", groupId, "templates", "import");
        final URI importUri = uriBuilder.build();
        final Map<String, String> headersToOverride = new HashMap<>();
        headersToOverride.put("content-type", MediaType.APPLICATION_XML);
        // to the cluster nodes themselves.
        if (getReplicationTarget() == ReplicationTarget.CLUSTER_NODES) {
            return getRequestReplicator().replicate(HttpMethod.POST, importUri, entity, getHeaders(headersToOverride)).awaitMergedResponse().getResponse();
        } else {
            return getRequestReplicator().forwardToCoordinator(getClusterCoordinatorNode(), HttpMethod.POST, importUri, entity, getHeaders(headersToOverride)).awaitMergedResponse().getResponse();
        }
    }
    // otherwise import the template locally
    return importTemplate(httpServletRequest, groupId, entity);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) URI(java.net.URI) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException) TemplateEntity(org.apache.nifi.web.api.entity.TemplateEntity) Unmarshaller(javax.xml.bind.Unmarshaller) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project CzechIdMng by bcvsolutions.

the class SchedulerController method find.

/**
 * Finds scheduled tasks
 *
 * @return all tasks
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@ResponseBody
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.SCHEDULER_READ + "')")
@ApiOperation(value = "Search scheduled tasks", nickname = "searchSchedulerTasks", tags = { SchedulerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }) })
@ApiImplicitParams({ @ApiImplicitParam(name = "page", dataType = "string", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "string", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") })
public Resources<Task> find(@RequestParam(required = false) MultiValueMap<String, Object> parameters, @PageableDefault Pageable pageable) {
    String text = getParameterConverter().toString(parameters, DataFilter.PARAMETER_TEXT);
    List<Task> tasks = schedulerService.getAllTasks().stream().filter(task -> {
        // filter - like name or description only
        return StringUtils.isEmpty(text) || task.getTaskType().getSimpleName().toLowerCase().contains(text.toLowerCase()) || (task.getDescription() != null && task.getDescription().toLowerCase().contains(text.toLowerCase()));
    }).sorted((taskOne, taskTwo) -> {
        Sort sort = pageable.getSort();
        if (pageable.getSort() == null) {
            return 0;
        }
        int compareAscValue = 0;
        boolean asc = true;
        // "naive" sort implementation
        if (sort.getOrderFor(PROPERTY_TASK_TYPE) != null) {
            asc = sort.getOrderFor(PROPERTY_TASK_TYPE).isAscending();
            compareAscValue = taskOne.getTaskType().getSimpleName().compareTo(taskTwo.getTaskType().getSimpleName());
        }
        if (sort.getOrderFor(PROPERTY_DESCRIPTION) != null) {
            asc = sort.getOrderFor(PROPERTY_DESCRIPTION).isAscending();
            compareAscValue = taskOne.getDescription().compareTo(taskTwo.getDescription());
        }
        if (sort.getOrderFor(PROPERTY_INSTANCE_ID) != null) {
            asc = sort.getOrderFor(PROPERTY_INSTANCE_ID).isAscending();
            compareAscValue = taskOne.getInstanceId().compareTo(taskTwo.getInstanceId());
        }
        return asc ? compareAscValue : compareAscValue * -1;
    }).collect(Collectors.toList());
    // "naive" pagination
    int first = pageable.getPageNumber() * pageable.getPageSize();
    int last = pageable.getPageSize() + first;
    List<Task> taskPage = tasks.subList(first < tasks.size() ? first : tasks.size() > 0 ? tasks.size() - 1 : 0, last < tasks.size() ? last : tasks.size());
    // 
    return pageToResources(new PageImpl(taskPage, pageable, tasks.size()), Task.class);
}
Also used : PagedResourcesAssembler(org.springframework.data.web.PagedResourcesAssembler) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiParam(io.swagger.annotations.ApiParam) StringUtils(org.apache.commons.lang3.StringUtils) Valid(javax.validation.Valid) RequestBody(org.springframework.web.bind.annotation.RequestBody) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) ApiOperation(io.swagger.annotations.ApiOperation) DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SwaggerConfig(eu.bcvsolutions.idm.core.api.config.swagger.SwaggerConfig) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) AuthorizationScope(io.swagger.annotations.AuthorizationScope) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) Api(io.swagger.annotations.Api) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) MultiValueMap(org.springframework.util.MultiValueMap) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) Page(org.springframework.data.domain.Page) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ParameterConverter(eu.bcvsolutions.idm.core.api.utils.ParameterConverter) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) AbstractTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) PageableDefault(org.springframework.data.web.PageableDefault) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) PageImpl(org.springframework.data.domain.PageImpl) Authorization(io.swagger.annotations.Authorization) PageImpl(org.springframework.data.domain.PageImpl) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) Sort(org.springframework.data.domain.Sort) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ApiImplicitParams

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

the class ReplicationHandler method replicate.

@ApiOperation("Replicate the stores of a remote Indy")
@ApiImplicitParams({ @ApiImplicitParam(paramType = "body", name = "body", dataType = "org.commonjava.indy.model.core.dto.ReplicationDTO", required = true, value = "The configuration determining how replication should be handled, and what remote site to replicate.") })
@POST
@Produces(ApplicationContent.application_json)
public Response replicate(@Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
    Response response;
    try {
        String user = securityManager.getUser(securityContext, request);
        ReplicationDTO dto = serializer.readValue(request.getInputStream(), ReplicationDTO.class);
        final Set<StoreKey> replicated = controller.replicate(dto, user);
        final Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("replicationCount", replicated.size());
        params.put("items", replicated);
        response = responseHelper.formatOkResponseWithJsonEntity(params);
    } catch (final IndyWorkflowException | IOException e) {
        logger.error(String.format("Replication failed: %s", e.getMessage()), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ReplicationDTO(org.commonjava.indy.model.core.dto.ReplicationDTO) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey) LinkedHashMap(java.util.LinkedHashMap) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

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