/** * Returns the display title for an operation * * @return the operation title */ public String getTitle() { String operationName = operation.getSummary(); if (isBlank(operationName)) { operationName = getMethod().toString() + " " + getPath(); } return operationName; }
/** * Returns an unique id for the operation.<br> * Use {@code <operation id>}, then {@code <operation path> lowercase(<operation method>)} if operation id is not set. * * @return operation unique id */ public String getId() { String id = operation.getOperationId(); if (id == null) id = getPath() + " " + getMethod().toString().toLowerCase(); return id; }
/** * Returns whether an HTTP operation with provided verb can contain a body or not. * * @param verb HTTP verb * @return whether an HTTP operation with provided verb can contain a body or not. */ public static boolean canContainBody(String verb) { return verb.equalsIgnoreCase(HttpMethod.POST.toString()) || verb.equalsIgnoreCase(HttpMethod.PUT.toString()) || verb.equalsIgnoreCase(HttpMethod.PATCH.toString()); }
/** * Returns whether an HTTP operation with provided verb can contain a body or not. * * @param verb HTTP verb * @return whether an HTTP operation with provided verb can contain a body or not. */ public static boolean canContainBody(String verb) { return verb.equalsIgnoreCase(HttpMethod.POST.toString()) || verb.equalsIgnoreCase(HttpMethod.PUT.toString()) || verb.equalsIgnoreCase(HttpMethod.PATCH.toString()); }
private String ol_missingEndpoint(List<Endpoint> endpoints) { if (null == endpoints) return ""; StringBuffer sb = new StringBuffer(); for (Endpoint endpoint : endpoints) { sb.append(li_newEndpoint(endpoint.getMethod().toString(), endpoint.getPathUrl(), endpoint.getSummary())); } return sb.toString(); }
/** * Returns the display title for an operation * * @return the operation title */ public String getTitle() { String operationName = operation.getSummary(); if (isBlank(operationName)) { operationName = getMethod().toString() + " " + getPath(); } return operationName; }
private String ol_newEndpoint(List<Endpoint> endpoints) { if (null == endpoints) return ""; StringBuffer sb = new StringBuffer(); for (Endpoint endpoint : endpoints) { sb.append(li_newEndpoint(endpoint.getMethod().toString(), endpoint.getPathUrl(), endpoint.getSummary())); } return sb.toString(); }
/** * Returns an unique id for the operation.<br> * Use {@code <operation id>}, then {@code <operation path> lowercase(<operation method>)} if operation id is not set. * * @return operation unique id */ public String getId() { String id = operation.getOperationId(); if (id == null) id = getPath() + " " + getMethod().toString().toLowerCase(); return id; }
/** * Returns the display title for an operation * * @return the operation title */ public String getTitle() { String operationName = operation.getSummary(); if (isBlank(operationName)) { operationName = getMethod().toString() + " " + getPath(); } return operationName; }
/** * Returns an unique id for the operation.<br> * Use {@code <operation id>}, then {@code <operation path> lowercase(<operation method>)} if operation id is not set. * * @return operation unique id */ public String getId() { String id = operation.getOperationId(); if (id == null) id = getPath() + " " + getMethod().toString().toLowerCase(); return id; }
private List<String> buildHeaders( Swagger swagger, Map.Entry<String, Path> path, Map.Entry<HttpMethod, Operation> operation ) { List<String> headers = new ArrayList<>(); headers.add( operation.getKey().toString() + " " + swagger.getBasePath() + path.getKey() + " HTTP/1.1"); headers.add("Host: " + swagger.getHost().split(":")[0]); if (CollectionUtils.isNotEmpty(operation.getValue().getProduces())) { headers.add("Accept: " + String.join(",", operation.getValue().getProduces())); } else if (CollectionUtils.isNotEmpty(swagger.getProduces())) { headers.add("Accept: " + String.join(",", swagger.getProduces())); } if (CollectionUtils.isNotEmpty(operation.getValue().getConsumes())) { headers.add("Content-Type: " + String.join(",", operation.getValue().getConsumes())); } else if (CollectionUtils.isNotEmpty(swagger.getConsumes())) { headers.add("Content-Type: " + String.join(",", swagger.getConsumes())); } return headers; }
private String ol_changed(List<ChangedEndpoint> changedEndpoints) { if (null == changedEndpoints) return ""; StringBuffer sb = new StringBuffer(); for (ChangedEndpoint changedEndpoint : changedEndpoints) { String pathUrl = changedEndpoint.getPathUrl(); Map<HttpMethod, ChangedOperation> changedOperations = changedEndpoint .getChangedOperations(); for (Entry<HttpMethod, ChangedOperation> entry : changedOperations .entrySet()) { String method = entry.getKey().toString(); ChangedOperation changedOperation = entry.getValue(); String desc = changedOperation.getSummary(); StringBuffer ul_detail = new StringBuffer(); if (changedOperation.isDiffParam()) { ul_detail.append(PRE_LI).append("Parameters") .append(ul_param(changedOperation)); } if (changedOperation.isDiffProp()) { ul_detail.append(PRE_LI).append("Return Type") .append(ul_response(changedOperation)); } sb.append(CODE).append(method).append(CODE) .append(" " + pathUrl).append(" " + desc + " \n") .append(ul_detail); } } return sb.toString(); }
/** * Generates default URI templates to be assigned to an API * @return Map of URI Templates */ public static Map<String, UriTemplate> getDefaultUriTemplates() { Map<String, UriTemplate> uriTemplateMap = new HashMap<>(); UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(); uriTemplateBuilder.uriTemplate("/"); for (String httpVerb : APIMgtConstants.SUPPORTED_HTTP_VERBS.split(",")) { if (!HttpMethod.OPTIONS.toString().equals(httpVerb)) { uriTemplateBuilder.httpVerb(httpVerb); uriTemplateBuilder.policy(APIUtils.getDefaultAPIPolicy()); uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(uriTemplateBuilder.getUriTemplate (), httpVerb)); uriTemplateMap.put(uriTemplateBuilder.getTemplateId(), uriTemplateBuilder.build()); } } return uriTemplateMap; }
/** * Generates default URI templates to be assigned to an API * @return Map of URI Templates */ public static Map<String, UriTemplate> getDefaultUriTemplates() { Map<String, UriTemplate> uriTemplateMap = new HashMap<>(); UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(); uriTemplateBuilder.uriTemplate("/"); for (String httpVerb : APIMgtConstants.SUPPORTED_HTTP_VERBS.split(",")) { if (!HttpMethod.OPTIONS.toString().equals(httpVerb)) { uriTemplateBuilder.httpVerb(httpVerb); uriTemplateBuilder.policy(APIUtils.getDefaultAPIPolicy()); uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(uriTemplateBuilder.getUriTemplate (), httpVerb)); uriTemplateMap.put(uriTemplateBuilder.getTemplateId(), uriTemplateBuilder.build()); } } return uriTemplateMap; }
String uriTemplateString = uriTemplate.getUriTemplate(); List<Parameter> parameterList = getParameters(uriTemplateString); if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString ().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase (uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate .getHttpVerb())) { parameterList.add(getDefaultBodyParameter());
String uriTemplateString = uriTemplate.getUriTemplate(); List<Parameter> parameterList = getParameters(uriTemplateString); if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString ().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase (uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate .getHttpVerb())) { parameterList.add(getDefaultBodyParameter());
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final NormalisedPath requestPath = new ApiNormalisedPath(exchange.getRequestURI()); final Optional<NormalisedPath> maybeApiPath = SwaggerHelper.findMatchingApiPath(requestPath); if (!maybeApiPath.isPresent()) { setExchangeStatus(exchange, STATUS_INVALID_REQUEST_PATH, requestPath.normalised()); return; } final NormalisedPath swaggerPathString = maybeApiPath.get(); final Path swaggerPath = SwaggerHelper.swagger.getPath(swaggerPathString.original()); final HttpMethod httpMethod = HttpMethod.valueOf(exchange.getRequestMethod().toString()); final Operation operation = swaggerPath.getOperationMap().get(httpMethod); if (operation == null) { setExchangeStatus(exchange, STATUS_METHOD_NOT_ALLOWED); return; } // This handler can identify the swaggerOperation and endpoint only. Other info will be added by JwtVerifyHandler. final SwaggerOperation swaggerOperation = new SwaggerOperation(swaggerPathString, swaggerPath, httpMethod, operation); String endpoint = swaggerPathString.normalised() + "@" + httpMethod.toString().toLowerCase(); Map<String, Object> auditInfo = new HashMap<>(); auditInfo.put(Constants.ENDPOINT_STRING, endpoint); auditInfo.put(Constants.SWAGGER_OPERATION_STRING, swaggerOperation); exchange.putAttachment(AuditHandler.AUDIT_INFO, auditInfo); Handler.next(exchange, next); }
private ContainerTag ol_newEndpoint(List<Endpoint> endpoints) { if (null == endpoints) return ol().withId("new"); ContainerTag ol = ol().withId("new"); for (Endpoint endpoint : endpoints) { ol.with(li_newEndpoint(endpoint.getMethod().toString(), endpoint.getPathUrl(), endpoint.getSummary())); } return ol; }
private ContainerTag ol_missingEndpoint(List<Endpoint> endpoints) { if (null == endpoints) return ol().withId("deprecated"); ContainerTag ol = ol().withId("deprecated"); for (Endpoint endpoint : endpoints) { ol.with(li_missingEndpoint(endpoint.getMethod().toString(), endpoint.getPathUrl(), endpoint.getSummary())); } return ol; }
private ContainerTag ol_changed(List<ChangedEndpoint> changedEndpoints) { if (null == changedEndpoints) return ol().withId("changed"); ContainerTag ol = ol().withId("changed"); for (ChangedEndpoint changedEndpoint : changedEndpoints) { String pathUrl = changedEndpoint.getPathUrl(); Map<HttpMethod, ChangedOperation> changedOperations = changedEndpoint.getChangedOperations(); for (Entry<HttpMethod, ChangedOperation> entry : changedOperations.entrySet()) { String method = entry.getKey().toString(); ChangedOperation changedOperation = entry.getValue(); String desc = changedOperation.getSummary(); ContainerTag ul_detail = ul().withClass("detail"); if (changedOperation.isDiffParam()) { ul_detail.with(li().with(h3("Parameter")).with(ul_param(changedOperation))); } if (changedOperation.isDiffProp()) { ul_detail.with(li().with(h3("Return Type")).with(ul_response(changedOperation))); } ol.with(li().with(span(method).withClass(method)).withText(pathUrl + " ").with(span(null == desc ? "" : desc)) .with(ul_detail)); } } return ol; }