Skip to content
Open
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 @@ -36,6 +36,8 @@
import java.util.StringJoiner;
import java.util.stream.Collectors;

import static io.ballerina.flowmodelgenerator.core.converters.utils.DataMappingModelConverterUtils.escapeIdentifier;

/**
* Code snippet generator.
*
Expand Down Expand Up @@ -487,7 +489,14 @@ private String generateMember(Member member, boolean withDefaultValue) {

String template = "%s %s%s"; // <type descriptor> <identifier> [= <default value>]

String fieldName = CommonUtil.escapeReservedKeyword(member.name());
String rawName = member.name();
String fieldName;
if (rawName != null && (rawName.startsWith("'") || rawName.startsWith("\\"))) {
fieldName = rawName;
} else {
assert rawName != null;
fieldName = escapeIdentifier(rawName);
}
if (member.optional()) {
fieldName = fieldName + "?";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"filePath": "test_pack1/types.bal",
"description": "Create a new record type",
"type": {
"name": "MyType",
"editable": true,
"metadata": {
"label": "MyType",
"description": ""
},
"codedata": {
"node": "RECORD"
},
"properties": {
"name": {
"metadata": {
"label": "Type name",
"description": "Unique name to identify the type"
},
"types": [
{
"fieldType": "IDENTIFIER",
"selected": true
}
],
"value": "MyType",
"optional": false,
"editable": false,
"advanced": false,
"hidden": false
},
"isPublic": {
"metadata": {
"label": "public",
"description": "Make visible across the workspace"
},
"types": [
{
"fieldType": "FLAG",
"selected": true
}
],
"value": true,
"optional": true,
"editable": true,
"advanced": false,
"hidden": false
},
"description": {
"metadata": {
"label": "Type description",
"description": "Detailed description about the type"
},
"types": [
{
"fieldType": "TEXT",
"selected": true
}
],
"value": "",
"optional": true,
"editable": false,
"advanced": false,
"hidden": false
},
"isArray": {
"metadata": {
"label": "Is array type",
"description": "Is this type an array or list value"
},
"types": [
{
"fieldType": "FLAG",
"selected": true
}
],
"value": "false",
"optional": true,
"editable": false,
"advanced": false,
"hidden": false
},
"arraySize": {
"metadata": {
"label": "Size of the array",
"description": "Array dimensions"
},
"types": [
{
"fieldType": "TEXT",
"selected": true
}
],
"value": "",
"optional": true,
"editable": true,
"advanced": true,
"hidden": false
}
},
"members": [
{
"kind": "FIELD",
"refs": [],
"type": "int",
"typeName": "int",
"name": "total_count",
"optional": false,
"readonly": false,
"isGraphqlId": false,
"selected": false
},
{
"kind": "FIELD",
"refs": [],
"type": "int",
"typeName": "int",
"name": "+1",
"optional": false,
"readonly": false,
"isGraphqlId": false,
"selected": false
},
{
"kind": "FIELD",
"refs": [],
"type": "int",
"typeName": "int",
"name": "-1",
"optional": false,
"readonly": false,
"isGraphqlId": false,
"selected": false
}
],
"includes": [],
"allowAdditionalFields": false
},
"output": {
"test_pack1/types.bal": [
{
"range": {
"start": {
"line": 37,
"character": 0
},
"end": {
"line": 37,
"character": 0
}
},
"newText": "\npublic type MyType record {|\n\tint total_count;\n\tint \\+1;\n\tint \\-1;\n|};"
}
]
}
}
Loading