Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ballerina to OAS] Refactor HATEOAS Support #5978

Open
SachinAkash01 opened this issue Jan 24, 2024 · 0 comments
Open

[Ballerina to OAS] Refactor HATEOAS Support #5978

SachinAkash01 opened this issue Jan 24, 2024 · 0 comments

Comments

@SachinAkash01
Copy link
Member

Description:

private Map<String, Link> mapHateoasLinksToOpenApiLinks(String packageId, int serviceId,
                                                            FunctionDefinitionNode resourceFunction) {
        Optional<String> linkedTo = getResourceConfigAnnotation(resourceFunction)
                .flatMap(resourceConfig -> getValueForAnnotationFields(resourceConfig, BALLERINA_LINKEDTO_KEYWORD));

Rather than getting the string value of the node HateoasMapperImpl.java#L139, we can get as a
ExpressionNode value. Since IIRC syntax tree already parses the values and create them with proper structure. If we use that type, then we do not need to write our own parser logic like in here.. HateoasMapperImpl.java#L170

public static Optional<String> getValueForAnnotationFields(AnnotationNode resourceConfigAnnotation,
                                                               String fieldName) {
        return resourceConfigAnnotation
                .annotValue()
                .map(MappingConstructorExpressionNode::fields)
                .flatMap(fields ->
                        fields.stream()
                                .filter(fld -> fld instanceof SpecificFieldNode)
                                .map(fld -> (SpecificFieldNode) fld)
                                .filter(fld -> fieldName.equals(fld.fieldName().toString().trim()))
                                .findFirst()
                ).flatMap(SpecificFieldNode::valueExpr)
                .map(en -> en.toString().trim());
    }

In above code segment, instead of converting the expression node to a string, we can directly return the expression node to do this change. MapperCommonUtils.java#L481

Then in HateoasMapperImpl we need to visit the nodes accordingly in order to get the values of linkedTo field in the http:ResourceConfig annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant