Skip to content

Commit

Permalink
Implement closed record with json rest fields for json-to-record-conv…
Browse files Browse the repository at this point in the history
…erter
  • Loading branch information
Shadow-Devil committed Oct 10, 2024
1 parent 2356c62 commit 100e4cb
Show file tree
Hide file tree
Showing 28 changed files with 642 additions and 493 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ private ConverterUtils() {
*/
public static String convertOpenAPITypeToBallerina(String type) {

//In the case where type is not specified return anydata by default
//In the case where type is not specified return json by default
if (type == null || type.isEmpty()) {
return "anydata";
return "json";
}

return switch (type) {
Expand All @@ -54,7 +54,7 @@ public static String convertOpenAPITypeToBallerina(String type) {
Constants.NUMBER,
Constants.DOUBLE -> "decimal";
case Constants.FLOAT -> "float";
default -> "anydata";
default -> "json";
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static Map<String, Object> generate(JsonNode json) throws JsonToRecordCon
}

if (json.getNodeType() == JsonNodeType.NULL) {
schema.put("type", "anydata");
schema.put("type", "json");
return schema;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
type NewRecord record {
type NewRecord record {|
string name;
int id;
boolean bark?;
string breed?;
};
json...;
|};

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
type City record {
type City record {|
string code;
string name;
};
|};

type Address record {
type Address record {|
string country;
City city;
string Lane;
};
|};

type NewRecord record {|
Address address;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
type Image record {
type Image record {|
int vOffset;
string src;
string name;
string alignment;
int hOffset;
};
json...;
|};

type Window record {
type Window record {|
string name;
int width;
string title;
int height;
};
json...;
|};

type Text record {
type Text record {|
int vOffset;
string data;
int size;
Expand All @@ -22,16 +24,19 @@ type Text record {
string alignment;
string onMouseUp;
int hOffset;
};
json...;
|};

type Widget record {
type Widget record {|
Image image;
string debug;
Window window;
Text text;
};
json...;
|};

type NewRecord record {
type NewRecord record {|
Widget widget;
};
json...;
|};

Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
type ColorsItem record {
type ColorsItem record {|
string name;
int id;
};
json...;
|};

type Dimensions record {
type Dimensions record {|
int width;
int height;
};
json...;
|};

type NewRecord record {
type NewRecord record {|
string name;
boolean checked;
string id;
ColorsItem[] colors;
Dimensions dimensions;
};
json...;
|};

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ type NewRecord record {|
string name;
boolean checked;
string id;
record {
record {|
string name;
int id;
}[] colors;
record {
|}[] colors;
record {|
int width;
int height;
} dimensions;
|} dimensions;
|};
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
type NewRecord record {
type NewRecord record {|
string name;
boolean checked;
string id;

record {
record {|
string name;
int id;
}[] colors;
json...;
|}[] colors;

record {
record {|
int width;
int height;
} dimensions;
};
json...;
|} dimensions;
json...;
|};
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
type Dimensions record {
type Dimensions record {|
int width;
int height;
};
json...;
|};

type NewRecord record {
type NewRecord record {|
boolean checked;
Dimensions dimensions;
int id;
string name;
};
json...;
|};

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type NewRecord record {
type NewRecord record {|
json id;
};
json...;
|};
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
type SportsItem record {
type SportsItem record {|
string question;
string answer;
string[] options;
};
json...;
|};

type MathsItem record {
type MathsItem record {|
string question;
string answer;
string[] options;
};
json...;
|};

type NewRecord record {
type NewRecord record {|
SportsItem[] sports;
MathsItem[] maths;
};
json...;
|};

Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
type BatterItem record {
type BatterItem record {|
string id;
string 'type;
};
json...;
|};

type Batters record {
type Batters record {|
BatterItem[] batter;
};
json...;
|};

type ToppingItem record {
type ToppingItem record {|
string id;
string 'type;
};
json...;
|};

type NewRecord record {
type NewRecord record {|
decimal ppu;
Batters batters;
string name;
string id;
string 'type;
ToppingItem[] topping;
};
json...;
|};

type NewRecordList record {
type NewRecordList record {|
NewRecord[] newrecordlist;
};
json...;
|};
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
type Person record {
type Person record {|

record {
record {|
decimal ppu;

record {
record {
record {|
record {|
string id;
string 'type;
}[] batter;
} batters;
json...;
|}[] batter;
json...;
|} batters;

string name;
string id;
string 'type;

record {
record {|
string id;
string 'type;
}[] topping;
}[] personlist;
};
json...;
|}[] topping;
json...;
|}[] personlist;
json...;
|};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
type NewRecord record {
record {
anydata[] donations;
any subscription;
} contributions;
type NewRecord record {|
record {|
json[] donations;
json subscription;
json...;
|} contributions;
string school;
string name;
int age;
};
json...;
|};
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
type Address record {
type Address record {|
string streetAddress;
string city;
string state;
};
json...;
|};

type PhoneNumbersItem record {
type PhoneNumbersItem record {|
string number;
string 'type;
};
json...;
|};

type NewRecord record {
type NewRecord record {|
string firstName;
string lastName;
Address address;
string gender;
int age;
PhoneNumbersItem[] phoneNumbers;
};
json...;
|};

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
type NewRecord record {
type NewRecord record {|
string color;
string value;
};
json...;
|};

type NewRecordList record {
type NewRecordList record {|
NewRecord[] newrecordlist;
};
json...;
|};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Person record {
record {
string color; string value;
}[] personlist;
};
type Person record {|
record {|
string color; string value; json...;
|}[] personlist;
json...;
|};
Loading

0 comments on commit 100e4cb

Please sign in to comment.