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

Add name for readonly records in config schema generation #41914

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangNumericLiteral;
import org.wso2.ballerinalang.compiler.util.Names;
import org.wso2.ballerinalang.compiler.util.TypeTags;

import java.util.HashMap;
Expand Down Expand Up @@ -181,14 +182,19 @@ private JsonObject generateRecordType(BRecordType effectiveType, BIntersectionTy
if (!requiredFields.isEmpty()) {
typeNode.add("required", requiredFields);
}
// Get record type and set the type name as a property
for (BType bType : intersectionType.getConstituentTypes()) {
// Does not consider anonymous records
if (bType.tag == TypeTags.TYPEREFDESC) {
typeNode.addProperty("name", bType.toString().trim());
// The tsymbol name is empty for anon intersection type created due to inferred readonly
Dilhasha marked this conversation as resolved.
Show resolved Hide resolved
if (intersectionType.tsymbol.name != Names.EMPTY) {
typeNode.addProperty("name", intersectionType.tsymbol.toString().trim());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be tsymbol.name.value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsymbol.name.value doesn't return the fully qualified name.

Dilhasha marked this conversation as resolved.
Show resolved Hide resolved
} else {
// Get record type and set the type name as a property
for (BType bType : intersectionType.getConstituentTypes()) {
// Does not consider anonymous records
if (bType.tag == TypeTags.TYPEREFDESC) {
// Revisit with https://github.com/ballerina-platform/ballerina-lang/issues/24078
typeNode.addProperty("name", bType.toString().trim());
}
}
}

return typeNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,31 @@
}
},
"description": ""
},
"employeeReadOnly": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"salary": {
"type": "integer"
}
},
"additionalProperties": false,
"required": [
"name",
"salary"
],
"name": "dilhashanazeer/complexconfigs2:0.1.0:EmployeeReadOnly",
"description": ""
}
},
"additionalProperties": false,
"required": [
"employeeArray",
"empMapArray"
"empMapArray",
"employeeReadOnly"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ type Employee record {
int salary;
};

type EmployeeReadOnly readonly & record {
string name;
int salary;
};

configurable table<Employee> key(name) t = table [
{ name: "John", salary: 100 },
{ name: "Jane", salary: 200 }
Expand All @@ -22,6 +27,7 @@ configurable map<int>[] myArray = [{"val1" : 22}, {"val2" : 32}];
configurable Employee[] employeeArray = ?;
configurable map<Employee> employeeMap = {"emp1": {name: "user1", salary: 1200}};
configurable map<Employee>[] empMapArray = ?;
configurable EmployeeReadOnly employeeReadOnly = ?;

public function main() {
}
Loading