use of dev.hilla.endpointransfermapper.EndpointTransferMapper in project flow by vaadin.
the class AbstractEndpointGenerationTest method assertPath.
private void assertPath(Class<?> testEndpointClass, Method expectedEndpointMethod, PathItem actualPath, HashMap<String, Class<?>> typeArguments) {
Operation actualOperation = actualPath.getPost();
assertEquals("Unexpected tag in the OpenAPI spec", Collections.singletonList(testEndpointClass.getSimpleName()), actualOperation.getTags());
assertTrue(String.format("Unexpected OpenAPI operation id: does not contain the endpoint name of the class '%s'", testEndpointClass.getSimpleName()), actualOperation.getOperationId().contains(getEndpointName(testEndpointClass)));
assertTrue(String.format("Unexpected OpenAPI operation id: does not contain the name of the endpoint method '%s'", expectedEndpointMethod.getName()), actualOperation.getOperationId().contains(expectedEndpointMethod.getName()));
if (expectedEndpointMethod.getParameterCount() > 0) {
Schema requestSchema = extractSchema(actualOperation.getRequestBody().getContent());
Type[] genericParameterTypes = expectedEndpointMethod.getGenericParameterTypes();
Class<?>[] parameterTypes = new Class<?>[genericParameterTypes.length];
List<HashMap<String, Class<?>>> parameterTypeArguments = new ArrayList<>();
for (int i = 0; i < genericParameterTypes.length; i++) {
parameterTypes[i] = applyTypeArguments(genericParameterTypes[i], typeArguments);
parameterTypeArguments.add(i, extractTypeArguments(genericParameterTypes[i], typeArguments));
}
assertRequestSchema(requestSchema, parameterTypes, parameterTypeArguments, expectedEndpointMethod.getParameters());
} else {
assertNull(String.format("No request body should be present in path schema for endpoint method with no parameters, method: '%s'", expectedEndpointMethod), actualOperation.getRequestBody());
}
ApiResponses responses = actualOperation.getResponses();
assertEquals("Every operation is expected to have a single '200' response", 1, responses.size());
ApiResponse apiResponse = responses.get("200");
assertNotNull("Every operation is expected to have a single '200' response", apiResponse);
Type genericReturnType = expectedEndpointMethod.getGenericReturnType();
Class<?> returnType = applyTypeArguments(genericReturnType, typeArguments);
Class<?> mappedType = new EndpointTransferMapper().getTransferType(returnType);
if (mappedType != null) {
returnType = mappedType;
}
if (returnType != void.class) {
assertSchema(extractSchema(apiResponse.getContent()), returnType, extractTypeArguments(genericReturnType, typeArguments));
} else {
assertNull(String.format("No response is expected to be present for void method '%s'", expectedEndpointMethod), apiResponse.getContent());
}
assertNotNull("Non-anonymous endpoint method should have a security data defined for it in the schema", actualOperation.getSecurity());
}
Aggregations