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 all 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 @@ -20,6 +20,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.wso2.ballerinalang.compiler.semantics.analyzer.Types;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols;
import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType;
import org.wso2.ballerinalang.compiler.semantics.model.types.BField;
Expand All @@ -33,6 +34,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 +183,20 @@ 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());
BTypeSymbol intersectionSymbol = intersectionType.tsymbol;
// The tsymbol name is implicitly empty
if (intersectionSymbol.name != Names.EMPTY) {
typeNode.addProperty("name", intersectionSymbol.toString().trim());
} 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