Skip to content

Commit

Permalink
Merge branch 'topic/json_schema_fix' into 'master'
Browse files Browse the repository at this point in the history
Update to use new VSS JSON API.

See merge request eng/ide/VSS!275
  • Loading branch information
reznikmm committed Jul 25, 2023
2 parents c10eeb3 + d8b45bf commit 80674d2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 28 deletions.
13 changes: 8 additions & 5 deletions source/json/vss-json-pull_readers-json5.ads
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ package VSS.JSON.Pull_Readers.JSON5 is
(Self : in out JSON5_Pull_Reader'Class;
Stream : not null VSS.Text_Streams.Input_Text_Stream_Access);

private

type JSON5_Pull_Reader is limited new JSON_Pull_Reader with record
Parser : VSS.JSON.Implementation.Parsers.JSON5.JSON5_Parser;
end record;
-- XXX GNAT 20230626: These functions can be moved to private part,
-- however, they are not visible then due to compiler's bug.

overriding function At_End (Self : JSON5_Pull_Reader) return Boolean;

Expand Down Expand Up @@ -65,4 +62,10 @@ private
overriding function String_Value
(Self : JSON5_Pull_Reader) return VSS.Strings.Virtual_String;

private

type JSON5_Pull_Reader is limited new JSON_Pull_Reader with record
Parser : VSS.JSON.Implementation.Parsers.JSON5.JSON5_Parser;
end record;

end VSS.JSON.Pull_Readers.JSON5;
3 changes: 2 additions & 1 deletion tools/json_schema/json_schema-writers-inputs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ package body JSON_Schema.Writers.Inputs is

if not Schema.Any_Of.Is_Empty then
-- Declaration items for union type reader
Put ("use all type VSS.JSON.Pull_Readers.JSON_Event_Kind;"); New_Line;
Put ("use all type VSS.JSON.Streams.JSON_Stream_Element_Kind;");
New_Line;
New_Line;
Put ("Look_Ahead : ");
Put ("VSS.JSON.Pull_Readers.Look_Ahead.JSON_Look_Ahead_Reader");
Expand Down
79 changes: 57 additions & 22 deletions tools/json_schema/json_schema-writers-types.adb
Original file line number Diff line number Diff line change
Expand Up @@ -840,34 +840,69 @@ package body JSON_Schema.Writers.Types is
is
use type VSS.Strings.Virtual_String;

function Get_Default_Value (Field_Type : VSS.Strings.Virtual_String)
return VSS.Strings.Virtual_String;
-- Return default value for the record component

-----------------------
-- Get_Default_Value --
-----------------------

function Get_Default_Value (Field_Type : VSS.Strings.Virtual_String)
return VSS.Strings.Virtual_String is
begin
if Required then
return VSS.Strings.Empty_Virtual_String;
elsif Field_Type = "Boolean"
or else Field_Type.Starts_With ("Enum.")
then
return Field_Type & "'First";
elsif Field_Type = "Integer" then
return "0";
elsif Field_Type = "Float" then
return "0.0";
else
return VSS.Strings.Empty_Virtual_String;
end if;

end Get_Default_Value;

Fallback : constant VSS.Strings.Virtual_String :=
Ref_To_Type_Name (Name) & "_" & Property.Name;

Field_Name : constant VSS.Strings.Virtual_String :=
Escape_Keywords (Property.Name);

Field_Type : VSS.Strings.Virtual_String :=
Writers.Types.Field_Type (Map, Property.Schema, Required, Fallback);

Default : constant VSS.Strings.Virtual_String :=
Get_Default_Value (Field_Type);

begin
declare
Field_Name : constant VSS.Strings.Virtual_String :=
Escape_Keywords (Property.Name);
if Field_Type.Is_Empty then
-- Skip unneeded properties
return;
elsif Is_Holder then
Field_Type.Append ("_Holder");
elsif Field_Name.To_Lowercase = Field_Type.To_Lowercase then
Field_Type.Prepend (".");
Field_Type.Prepend (Root_Package);
end if;

Field_Type : VSS.Strings.Virtual_String :=
Writers.Types.Field_Type (Map, Property.Schema, Required, Fallback);
begin
if Field_Type.Is_Empty then
-- Skip unneeded properties
return;
elsif Is_Holder then
Field_Type.Append ("_Holder");
elsif Field_Name.To_Lowercase = Field_Type.To_Lowercase then
Field_Type.Prepend (".");
Field_Type.Prepend (Root_Package);
end if;
Put (Field_Name);
Put (" : ");
Put (Field_Type);

Put (Field_Name);
Put (" : ");
Put (Field_Type);
Put (";");
New_Line;
if not Default.Is_Empty then
Put (" := ");
Put (Default);
end if;

Write_Comment (Property.Schema.Description, 6);
end;
Put (";");
New_Line;

Write_Comment (Property.Schema.Description, 6);
end Write_Record_Component;

-----------------------
Expand Down

0 comments on commit 80674d2

Please sign in to comment.