@Override public void apply(Swagger swagger) { Map<String, Object> extensions = defaultExtensions(); for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { operation.setVendorExtension("x-amazon-apigateway-integration", extensions); } } }
@Override public void apply(Swagger swagger) { ApiKeyAuthDefinition authorization = new ApiKeyAuthDefinition("Authorization", In.HEADER); authorization.setVendorExtension("x-amazon-apigateway-authtype", authType); swagger.securityDefinition(SECURITY_SCHEME_NAME, authorization); for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { operation.addSecurity(SECURITY_SCHEME_NAME, Collections.emptyList()); } } } }
public List<Parameter> findSwaggerParameter(String methodName) { for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { if (methodName.equals(operation.getOperationId())) { return operation.getParameters(); } } } throw new Error("method not found, name=" + methodName); }
public static void correctResponses(Swagger swagger) { if (swagger.getPaths() == null) { return; } for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { correctResponses(operation); } } } }
protected void convertResponses() { if (swagger.getPaths() == null) { return; } for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { for (Response response : operation.getResponses().values()) { convert(response.getSchema()); Map<String, Property> headers = response.getHeaders(); if (headers == null) { continue; } for (Property header : headers.values()) { convert(header); } } } } }
protected void convertToInterface() { if (interfaceCls != null) { return; } ClassConfig classConfig = new ClassConfig(); classConfig.setClassName(interfaceName); classConfig.setIntf(true); if (swagger.getPaths() != null) { for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { Response result = operation.getResponses().get(SwaggerConst.SUCCESS_KEY); JavaType resultJavaType = swaggerObjectMap.get(result.getSchema()); MethodConfig methodConfig = new MethodConfig(); methodConfig.setName(operation.getOperationId()); methodConfig.setResult(resultJavaType); for (Parameter parameter : operation.getParameters()) { String paramName = parameter.getName(); paramName = ClassUtils.correctMethodParameterName(paramName); JavaType paramJavaType = ConverterMgr.findJavaType(this, parameter); methodConfig.addParameter(paramName, paramJavaType); } classConfig.addMethod(methodConfig); } } } interfaceCls = JavassistUtils.createClass(classLoader, classConfig); }
@Override @JSONField(serialize = false) public List<Operation> getOperations() { return super.getOperations(); }
private void moveOperationsToSingleClient(Swagger swagger) { swagger.getPaths().values().forEach(path -> path.getOperations().forEach(operation -> operation.setTags(Collections.singletonList("client")) ) ); }
public static OperationDescription operationDescriptionOf(final Swagger swagger, final Operation operation) { final Entry<String, Path> pathEntry = swagger.getPaths().entrySet().stream() .filter(e -> e.getValue().getOperations().contains(operation)).findFirst().get(); final String path = pathEntry.getKey(); final Entry<HttpMethod, Operation> operationEntry = pathEntry.getValue().getOperationMap().entrySet().stream() .filter(e -> e.getValue().equals(operation)).findFirst().get(); final HttpMethod method = operationEntry.getKey(); final String specifiedSummary = trimToNull(operation.getSummary()); final String specifiedDescription = trimToNull(operation.getDescription()); final String name = ofNullable(specifiedSummary).orElseGet(() -> method + " " + path); final String description = ofNullable(specifiedDescription).orElseGet(() -> "Send " + method + " request to " + path); return new OperationDescription(name, description); }
private static void hoistInPath(Path path) { List<Parameter> parameters = path.getParameters(); if (parameters != null) { for (Parameter parameter : parameters) { hoistParameter(parameter, path.getOperations()); } parameters.clear(); } }
public List<Parameter> findSwaggerParameter(String methodName) { for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { if (methodName.equals(operation.getOperationId())) { return operation.getParameters(); } } } throw new Error("method not found, name=" + methodName); }
private void addIndividualPath(String resourceParentName, String resourceName, Path path, String pathSuffix) { if (!path.getOperations().isEmpty()) { if (resourceParentName == null) { swagger.path("/" + resourceName + pathSuffix, path); } else { swagger.path("/" + resourceParentName + "/{parent-uuid}/" + resourceName + pathSuffix, path); } } }
@Override public void afterScan(Reader reader, Swagger swagger) { swagger.addSecurityDefinition(TOKEN_AUTH_SCHEME, new BasicAuthDefinition()); swagger.getPaths().values() .stream() .forEach( path -> path.getOperations() .stream() .forEach( operation -> operation.addSecurity(GraviteeApiDefinition.TOKEN_AUTH_SCHEME, null))); } }
public static OperationDescription operationDescriptionOf(final Swagger swagger, final Operation operation, final BiFunction<String, String, String> consumer) { final Entry<String, Path> pathEntry = swagger.getPaths().entrySet().stream() .filter(e -> e.getValue().getOperations().contains(operation)).findFirst().get(); final String path = pathEntry.getKey(); final Entry<HttpMethod, Operation> operationEntry = pathEntry.getValue().getOperationMap().entrySet().stream() .filter(e -> e.getValue().equals(operation)).findFirst().get(); final HttpMethod method = operationEntry.getKey(); final String specifiedSummary = trimToNull(operation.getSummary()); final String specifiedDescription = trimToNull(operation.getDescription()); final String name = ofNullable(toLiteralNull(specifiedSummary)).orElseGet(() -> method + " " + path); final String description = ofNullable(toLiteralNull(specifiedDescription)) .orElseGet(() -> consumer.apply(method.name(), path)); return new OperationDescription(name, description); }
@Override public void afterScan(Reader reader, Swagger swagger) { swagger.addSecurityDefinition(TOKEN_AUTH_SCHEME, new BasicAuthDefinition()); swagger.getPaths().values() .stream() .forEach( path -> path.getOperations() .stream() .forEach( operation -> operation.addSecurity(GraviteeApiDefinition.TOKEN_AUTH_SCHEME, null))); } }
@Override public void path(String name, Path path) { fillList(path.getOperations()); path.setParameters(fillList(path.getParameters())); }
public void removeListAfterAndLimit(Swagger swagger) { swagger.getPaths().forEach((pathName, path) -> path.getOperations().forEach(operation -> operation.getParameters().removeIf(param -> !param.getRequired() && ("limit".equals(param.getName()) || "after".equals(param.getName()))) ) ); }
public static void correctResponses(Swagger swagger) { if (swagger.getPaths() == null) { return; } for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { correctResponses(operation); } } } }
private void validatePath(String pathName, Path actualPath, Path expectedPath) { if (expectedPath != null) { softAssertions.assertThat(actualPath.getOperations().size()).as("Checking number of operations of path '%s'", pathName).isGreaterThanOrEqualTo(expectedPath.getOperations().size()); validateOperation(actualPath.getGet(), expectedPath.getGet(), pathName, "GET"); validateOperation(actualPath.getDelete(), expectedPath.getDelete(), pathName, "DELETE"); validateOperation(actualPath.getPost(), expectedPath.getPost(), pathName, "POST"); validateOperation(actualPath.getPut(), expectedPath.getPut(), pathName, "PUT"); validateOperation(actualPath.getPatch(), expectedPath.getPatch(), pathName, "PATCH"); validateOperation(actualPath.getOptions(), expectedPath.getOptions(), pathName, "OPTIONS"); } }
private void validatePath(String pathName, Path actualPath, Path expectedPath) { if (expectedPath != null) { softAssertions.assertThat(actualPath.getOperations()).as("Checking number of operations of path '%s'", pathName).hasSameSizeAs(actualPath.getOperations()); validateOperation(actualPath.getGet(), expectedPath.getGet(), pathName, "GET"); validateOperation(actualPath.getDelete(), expectedPath.getDelete(), pathName, "DELETE"); validateOperation(actualPath.getPost(), expectedPath.getPost(), pathName, "POST"); validateOperation(actualPath.getPut(), expectedPath.getPut(), pathName, "PUT"); validateOperation(actualPath.getPatch(), expectedPath.getPatch(), pathName, "PATCH"); validateOperation(actualPath.getOptions(), expectedPath.getOptions(), pathName, "OPTIONS"); } }