diff --git a/source/json/vss-json-pull_readers-json5.ads b/source/json/vss-json-pull_readers-json5.ads index da8b97da..e98a3208 100644 --- a/source/json/vss-json-pull_readers-json5.ads +++ b/source/json/vss-json-pull_readers-json5.ads @@ -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; @@ -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; diff --git a/tools/json_schema/json_schema-writers-inputs.adb b/tools/json_schema/json_schema-writers-inputs.adb index 2c3fa211..45bf2591 100644 --- a/tools/json_schema/json_schema-writers-inputs.adb +++ b/tools/json_schema/json_schema-writers-inputs.adb @@ -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"); diff --git a/tools/json_schema/json_schema-writers-types.adb b/tools/json_schema/json_schema-writers-types.adb index 3a80bf47..5ed03271 100644 --- a/tools/json_schema/json_schema-writers-types.adb +++ b/tools/json_schema/json_schema-writers-types.adb @@ -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; -----------------------