Skip to content

Commit

Permalink
Merge pull request #41963 from Dilhasha/2201.8.x
Browse files Browse the repository at this point in the history
[2201.8.x] Add name for readonly records during config schema generation
  • Loading branch information
Dilhasha authored Jan 11, 2024
2 parents a955730 + 3563e7b commit a277fc2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
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() {
}

0 comments on commit a277fc2

Please sign in to comment.