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

Accessing the annotation field values via AnnotationSymbol #37194

Closed
lnash94 opened this issue Aug 1, 2022 · 0 comments · Fixed by #37297
Closed

Accessing the annotation field values via AnnotationSymbol #37194

lnash94 opened this issue Aug 1, 2022 · 0 comments · Fixed by #37297
Assignees
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler Points/2 Equivalent to two days effort Team/CompilerFETools Semantic API, Formatter, Shell Type/NewFeature
Milestone

Comments

@lnash94
Copy link
Member

lnash94 commented Aug 1, 2022

Description:

import ballerina/http;
import ballerina/constraint;

@constraint:String {minLength: 5}
public type Address string;

public type Person record {
    @constraint:String {maxLength: 14}
    string name?;
    @constraint:Array {maxLength: 5, minLength: 2}
    string[] hobby?;
    @constraint:Int {maxValue: 5}
    int id;
    Address address?;
    @constraint:Float {maxValue: 100000}
    float salary?;
    @constraint:Number {minValue: 500000}
    decimal net?;
};

service /payloadV on new http:Listener(9090) {
    resource function post pet(@http:Payload Person body) returns error? {
        return;
    }
}

If there is a annotation in record field, In openAPI we reuired to access, given annotation values for generating the openAPI specification.
The current implementation is driven by accessing RecordFieldTypeSymbol in the given record field. It returns the details about recordfield and we pick annotation details via calling .getAnnotations() but it didn't content annotation current available field values.

In above example, we need to get the details in name record field's annotation field maxLength: 14

Describe your problem(s)

  1. For current openAPI tool, we tried to back track to get syntax node from typeSymbol location from calling .findNode() . But this approach I met with limitation when we are going to access type that defined in the separate model. Because our util we use only sematicModel and SyntaxTree that are not enough for getting separate module syntax node details.
  2. Due to the limitation we have to pass the full project to the util instead of the sematicModel and Syntax tree, then it cause to some API changes to whole Ballerina to OpenAPI tool. Although we passed it there still we have do some kind of process finding dependency graph for tracking dependencies to access type define in the separate package. It will cause to some kind of conflict to the current util since it may additional process to mapping. Complex can be delaying to generate openapi spec, resolving dependency issue, interminante issue etc. (This util has used in several modules http, choreo, vsCode. Therefore we required to safe method to solve this.)

Describe your solution(s)
Considering the above issue and 1, 2 points , it would be great if we can have given AnnotationSymbol with extrafield that value with Optional regarding available record fields with their values.

Related issue : ballerina-platform/ballerina-library#5109

@lnash94 lnash94 added Type/NewFeature Area/SemanticAPI Semantic API Related Issues #Compiler labels Aug 1, 2022
@dulajdilshan dulajdilshan added the Team/CompilerFETools Semantic API, Formatter, Shell label Aug 2, 2022
@dulajdilshan dulajdilshan linked a pull request Aug 8, 2022 that will close this issue
13 tasks
@sanjana sanjana added the Points/2 Equivalent to two days effort label Aug 25, 2022
@dulajdilshan dulajdilshan added this to the 2201.3.0 milestone Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler Points/2 Equivalent to two days effort Team/CompilerFETools Semantic API, Formatter, Shell Type/NewFeature
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants