@Override public Optional<Parameter> filterParameter(Parameter parameter, Operation operation, ApiDescription api, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) { if (parameter.getDescription() != null && parameter.getDescription().startsWith("secret:")) { if (headers != null) { if (headers.containsKey("super-user")) { return Optional.of(parameter); } } return Optional.empty(); } return Optional.of(parameter); } }
@Test(description = "it should filter away secret parameters") public void filterAwaySecretParameters() throws IOException { final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH); final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter(); final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null); if (filtered.getPaths() != null) { for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) { final Operation get = entry.getValue().getGet(); if (get != null) { for (Parameter param : get.getParameters()) { final String description = param.getDescription(); if (StringUtils.isNotBlank(description)) { assertFalse(description.startsWith("secret")); } } } } } else { fail("paths should not be null"); } }
isRequestBodyEmpty = false; if (StringUtils.isNotBlank(requestBodyParameter.getDescription())) { requestBody.setDescription(requestBodyParameter.getDescription()); isRequestBodyEmpty = false;
public String getDescription() { return parameter.getDescription(); }
protected String itemParameter(String title, Parameter parameter) { return this.itemParameter( title, parameter.getName(), parameter.getIn(), parameter.getDescription()); }
protected String itemParameter(ChangedParameter param) { Parameter rightParam = param.getNewParameter(); if (param.isDeprecated()) { return itemParameter( "Deprecated", rightParam.getName(), rightParam.getIn(), rightParam.getDescription()); } return itemParameter( "Changed", rightParam.getName(), rightParam.getIn(), rightParam.getDescription()); }
private ContainerTag li_addParam(Parameter param) { return li().withText("Add " + param.getName() + " in " + param.getIn()) .with( span(null == param.getDescription() ? "" : ("//" + param.getDescription())) .withClass("comment")); }
private void injectApiVersionToPaths(Paths paths, BiFunction<String, String, String> replacer) { paths.forEach((endpoint, path) -> { path.readOperations().forEach(operation -> { operation.setDescription(replacer.apply(operation.getDescription(), apiVersion.get())); operation.getParameters().forEach(param -> param.setDescription(replacer.apply(param.getDescription(), apiVersion.get()))); operation.getResponses().forEach((name, response) -> { response.setDescription(replacer.apply(response.getDescription(), apiVersion.get())); if (response.getContent() != null) { response.getContent().forEach((mediaTypeName, mediaType) -> { if (mediaType.getExample() != null) { mediaType.setExample(replacer.apply(mediaType.getExample().toString(), apiVersion.get())); } }); } }); }); }); }
} else { for (int i = 0; i < subentry.getValue().getParameters().size(); i++) { if (StringUtils.isBlank(subentry.getValue().getParameters().get(i).getDescription())) { subentry.getValue().getParameters().get(i). setDescription(javadocProvider.getMethodParameterDoc(ori, i));
static void processFormParam(Parameter formParameter, Operation operation, MethodDoc methodDoc, Components components) { Option<Method> methodOpt = ReflectionKit.loadMethod(methodDoc); if (methodOpt.isDefined()) { Method method = methodOpt.get(); Consumes methodConsumes = ReflectionUtils.getAnnotation(method, Consumes.class); Consumes classConsumes = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Consumes.class); RequestBody requestBody = operation.getRequestBody() != null ? operation.getRequestBody() : new RequestBody(); requestBody.description(formParameter.getDescription()); if (!Strings.isNullOrEmpty(formParameter.getDescription())) { requestBody.setDescription(formParameter.getDescription()); } Content content = processContent(requestBody.getContent(), formParameter.getSchema(), methodConsumes, classConsumes, true); requestBody.setContent(content); setRequestBodyExamples(formParameter, requestBody); operation.setRequestBody(requestBody); } }
} else { for (int i = 0; i < subentry.getValue().getParameters().size(); i++) { if (StringUtils.isBlank(subentry.getValue().getParameters().get(i).getDescription())) { subentry.getValue().getParameters().get(i). setDescription(javadocProvider.getMethodParameterDoc(ori, i));
private ContainerTag li_missingParam(Parameter param) { return li().withClass("missing") .with(span("Delete")) .with(del(param.getName())) .with(span("in ").withText(param.getIn())) .with( span(null == param.getDescription() ? "" : ("//" + param.getDescription())) .withClass("comment")); }
private ContainerTag li_deprecatedParam(ChangedParameter param) { return li().withClass("missing") .with(span("Deprecated")) .with(del(param.getName())) .with(span("in ").withText(param.getIn())) .with( span(null == param.getNewParameter().getDescription() ? "" : ("//" + param.getNewParameter().getDescription())) .withClass("comment")); }
if (StringUtils.isNotBlank(param.getDescription())) { param.setDescription(preserveNewlines(param.getDescription(), 2));
openApiDiff .getMetadataDiff() .diff(left.getDescription(), right.getDescription(), context) .ifPresent(changedParameter::setDescription); openApiDiff
isRequestBodyEmpty = false; if (StringUtils.isNotBlank(requestBodyParameter.getDescription())) { requestBody.setDescription(requestBodyParameter.getDescription()); isRequestBodyEmpty = false;
private ContainerTag li_changedParam(ChangedParameter changeParam) { if (changeParam.isDeprecated()) { return li_deprecatedParam(changeParam); } boolean changeRequired = changeParam.isChangeRequired(); boolean changeDescription = changeParam.getDescription().isDifferent(); Parameter rightParam = changeParam.getNewParameter(); Parameter leftParam = changeParam.getNewParameter(); ContainerTag li = li().withText(changeParam.getName() + " in " + changeParam.getIn()); if (changeRequired) { li.withText(" change into " + (rightParam.getRequired() ? "required" : "not required")); } if (changeDescription) { li.withText(" Notes ") .with(del(leftParam.getDescription()).withClass("comment")) .withText(" change into ") .with(span(rightParam.getDescription()).withClass("comment")); } return li; } }
isRequestBodyEmpty = false; if (StringUtils.isNotBlank(requestBodyParameter.getDescription())) requestBody.setDescription(requestBodyParameter.getDescription()); isRequestBodyEmpty = false;
isRequestBodyEmpty = false; if (!Strings.isNullOrEmpty(requestBodyParameter.getDescription())) { requestBody.setDescription(requestBodyParameter.getDescription()); isRequestBodyEmpty = false;
@Override public BallerinaParameter buildContext(Parameter parameter, OpenAPI openAPI) throws BallerinaOpenApiException { this.name = parameter.getName(); this.in = parameter.getIn(); this.description = parameter.getDescription(); this.required = parameter.getRequired(); this.deprecated = parameter.getDeprecated(); this.allowEmptyValue = parameter.getAllowEmptyValue(); this.ref = parameter.get$ref(); this.style = parameter.getStyle(); this.explode = parameter.getExplode(); this.allowReserved = parameter.getAllowReserved(); this.examples = parameter.getExamples(); this.example = parameter.getExample(); this.content = parameter.getContent(); this.extensions = parameter.getExtensions(); this.schema = new BallerinaSchema().buildContext(parameter.getSchema(), openAPI); return this; }