diff --git a/.editorconfig b/.editorconfig index 86fce5ad0..952c68855 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,201 @@ +root = true + +[*] +indent_style = space +indent_size = 4 + [*.cs] + +#### 1. Layout & wrapping — Rider: WRAP_LIMIT, WRAP_LINES, LINE_FEED_AT_FILE_END, PLACE_COMMENTS_AT_FIRST_COLUMN, MAX_ENUM_MEMBERS_ON_LINE +indent_style = space +indent_size = 4 +tab_width = 4 +insert_final_newline = true +trim_trailing_whitespace = true +max_line_length = 180 +resharper_wrap_lines = false +resharper_place_comments_at_first_column = true +resharper_max_enum_members_on_line = 1 +resharper_place_accessorholder_attribute_on_same_line = never + +#### 2. Braces — Allman, and required on every control statement (Rider: BRACES_FOR_IFELSE/_FOR/_FOREACH/_WHILE = Required) +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true +csharp_prefer_braces = true:warning +resharper_braces_for_ifelse = required +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_while = required +resharper_enforce_if_statement_braces_highlighting = warning +resharper_enforce_for_statement_braces_highlighting = warning +resharper_enforce_foreach_statement_braces_highlighting = warning +resharper_enforce_while_statement_braces_highlighting = warning +resharper_enforce_do_while_statement_braces_highlighting = warning +resharper_enforce_using_statement_braces_highlighting = warning +resharper_enforce_lock_statement_braces_highlighting = warning +resharper_enforce_fixed_statement_braces_highlighting = warning +resharper_remove_redundant_braces_highlighting = warning + +#### 3. Blank lines — DEVELOPMENT_STANDARDS.md §1.3 (blank line on both sides of every braced block) +resharper_blank_lines_before_block_statements = 1 +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_before_multiline_statements = 1 +resharper_blank_lines_after_multiline_statements = 1 +resharper_blank_lines_before_single_line_comment = 1 +resharper_blank_lines_around_single_line_invocable = 1 +resharper_blank_lines_around_single_line_local_method = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_between_using_groups = 1 +resharper_keep_blank_lines_in_code = 1 +resharper_keep_blank_lines_in_declarations = 1 + +#### 4. Namespaces & usings — DEVELOPMENT_STANDARDS.md §1.10; Rider: NAMESPACE_BODY = BlockScoped, AddImportsToDeepestScope = True +csharp_style_namespace_declarations = block_scoped:warning +csharp_using_directive_placement = inside_namespace:warning +dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups = true +resharper_arrange_namespace_body_highlighting = warning +resharper_qualified_using_at_nested_scope = true +resharper_can_use_global_alias = false + +#### 5. `this.` qualification — Rider: INSTANCE_MEMBERS_QUALIFY_MEMBERS = Field, Property, Event, Method +dotnet_style_qualification_for_field = true:warning +dotnet_style_qualification_for_property = true:warning +dotnet_style_qualification_for_method = true:warning +dotnet_style_qualification_for_event = true:warning +resharper_arrange_this_qualifier_highlighting = warning + +#### 6. `var` — house rule: `var` wherever it is applicable +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion +resharper_suggest_var_or_type_built_in_types_highlighting = warning +resharper_suggest_var_or_type_simple_types_highlighting = warning +resharper_suggest_var_or_type_elsewhere_highlighting = warning + +#### 7. Expressions, patterns & members — DEVELOPMENT_STANDARDS.md §1.1, §1.2, §1.5, §1.6, §2 +dotnet_style_prefer_auto_properties = true:warning +dotnet_style_prefer_collection_expression = true:warning +dotnet_style_collection_initializer = true:warning +dotnet_style_object_initializer = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_readonly_field = true:suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning +csharp_style_prefer_switch_expression = true:warning +csharp_style_prefer_pattern_matching = true:warning +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_pattern_matching_over_as_with_null_check = true:warning +csharp_style_prefer_not_pattern = true:warning +csharp_style_prefer_extended_property_pattern = true:warning +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion +csharp_style_prefer_static_local_function = true:suggestion +csharp_style_expression_bodied_methods = when_on_single_line:suggestion +csharp_style_expression_bodied_properties = when_on_single_line:suggestion +csharp_style_expression_bodied_indexers = when_on_single_line:suggestion +csharp_style_expression_bodied_accessors = when_on_single_line:suggestion +csharp_style_expression_bodied_operators = when_on_single_line:suggestion +csharp_style_expression_bodied_lambdas = when_on_single_line:suggestion +csharp_style_expression_bodied_local_functions = when_on_single_line:suggestion +csharp_style_expression_bodied_constructors = false:suggestion +csharp_style_prefer_primary_constructors = false:none + +#### 8. XML documentation formatting — Rider: XmlDocFormatter +resharper_xmldoc_indent_size = 1 +resharper_xmldoc_tab_width = 1 +resharper_xmldoc_indent_tag_content = ZeroIndent +resharper_xmldoc_wrap_inside_text = false + +#### 9. Inspection severities — mirrors the Rider inspection profile +resharper_inconsistent_naming_highlighting = hint +resharper_arrange_accessor_owner_body_highlighting = hint +resharper_field_can_be_made_read_only_local_highlighting = hint +resharper_bad_control_braces_line_breaks_highlighting = hint +resharper_bad_declaration_braces_line_breaks_highlighting = hint +resharper_bad_empty_braces_line_breaks_highlighting = hint +resharper_bad_expression_braces_line_breaks_highlighting = hint +resharper_bad_linq_line_breaks_highlighting = hint +resharper_bad_list_line_breaks_highlighting = hint +resharper_bad_parens_line_breaks_highlighting = hint +resharper_incorrect_blank_lines_near_braces_highlighting = hint +resharper_missing_blank_lines_highlighting = hint +resharper_missing_linebreak_highlighting = hint +resharper_multiple_statements_on_one_line_highlighting = hint +resharper_multiple_type_members_on_one_line_highlighting = hint +resharper_redundant_blank_lines_highlighting = hint +resharper_redundant_linebreak_highlighting = hint +resharper_auto_property_can_be_made_get_only_local_highlighting = none +resharper_non_readonly_member_in_get_hash_code_highlighting = none +resharper_redundant_name_qualifier_highlighting = none +resharper_convert_to_primary_constructor_highlighting = none +resharper_replace_with_primary_constructor_parameter_highlighting = none +resharper_comment_typo_highlighting = none +resharper_identifier_typo_highlighting = none +resharper_string_literal_typo_highlighting = none + +#### 10. Naming — mirrors the Rider naming rules; Roslyn applies the first matching rule, so specific ones come first +dotnet_naming_style.pascal_case_style.capitalization = pascal_case +dotnet_naming_style.camel_case_style.capitalization = camel_case +dotnet_naming_style.interface_style.capitalization = pascal_case +dotnet_naming_style.interface_style.required_prefix = I +dotnet_naming_style.type_parameter_style.capitalization = pascal_case +dotnet_naming_style.type_parameter_style.required_prefix = T + +dotnet_naming_symbols.private_const_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_const_fields_symbols.applicable_accessibilities = private, private_protected +dotnet_naming_symbols.private_const_fields_symbols.required_modifiers = const +dotnet_naming_symbols.private_static_readonly_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_fields_symbols.applicable_accessibilities = private, private_protected +dotnet_naming_symbols.private_static_readonly_fields_symbols.required_modifiers = static, readonly +dotnet_naming_symbols.private_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_fields_symbols.applicable_accessibilities = private, private_protected +dotnet_naming_symbols.non_private_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_fields_symbols.applicable_accessibilities = public, internal, protected, protected_internal +dotnet_naming_symbols.interfaces_symbols.applicable_kinds = interface +dotnet_naming_symbols.interfaces_symbols.applicable_accessibilities = * +dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter +dotnet_naming_symbols.type_parameters_symbols.applicable_accessibilities = * +dotnet_naming_symbols.types_and_members_symbols.applicable_kinds = namespace, class, struct, enum, delegate, method, property, event, local_function +dotnet_naming_symbols.types_and_members_symbols.applicable_accessibilities = * +dotnet_naming_symbols.parameters_and_locals_symbols.applicable_kinds = parameter, local +dotnet_naming_symbols.parameters_and_locals_symbols.applicable_accessibilities = * + +dotnet_naming_rule.private_const_fields_are_pascal_case.symbols = private_const_fields_symbols +dotnet_naming_rule.private_const_fields_are_pascal_case.style = pascal_case_style +dotnet_naming_rule.private_const_fields_are_pascal_case.severity = suggestion +dotnet_naming_rule.private_static_readonly_fields_are_pascal_case.symbols = private_static_readonly_fields_symbols +dotnet_naming_rule.private_static_readonly_fields_are_pascal_case.style = pascal_case_style +dotnet_naming_rule.private_static_readonly_fields_are_pascal_case.severity = suggestion +dotnet_naming_rule.private_fields_are_camel_case.symbols = private_fields_symbols +dotnet_naming_rule.private_fields_are_camel_case.style = camel_case_style +dotnet_naming_rule.private_fields_are_camel_case.severity = suggestion +dotnet_naming_rule.non_private_fields_are_pascal_case.symbols = non_private_fields_symbols +dotnet_naming_rule.non_private_fields_are_pascal_case.style = pascal_case_style +dotnet_naming_rule.non_private_fields_are_pascal_case.severity = suggestion +dotnet_naming_rule.interfaces_are_prefixed.symbols = interfaces_symbols +dotnet_naming_rule.interfaces_are_prefixed.style = interface_style +dotnet_naming_rule.interfaces_are_prefixed.severity = suggestion +dotnet_naming_rule.type_parameters_are_prefixed.symbols = type_parameters_symbols +dotnet_naming_rule.type_parameters_are_prefixed.style = type_parameter_style +dotnet_naming_rule.type_parameters_are_prefixed.severity = suggestion +dotnet_naming_rule.types_and_members_are_pascal_case.symbols = types_and_members_symbols +dotnet_naming_rule.types_and_members_are_pascal_case.style = pascal_case_style +dotnet_naming_rule.types_and_members_are_pascal_case.severity = suggestion +dotnet_naming_rule.parameters_and_locals_are_camel_case.symbols = parameters_and_locals_symbols +dotnet_naming_rule.parameters_and_locals_are_camel_case.style = camel_case_style +dotnet_naming_rule.parameters_and_locals_are_camel_case.severity = suggestion + +#### 11. Analyzers # Disable S3776: Cognitive Complexity Warning dotnet_diagnostic.S3776.severity = none @@ -8,4 +205,4 @@ dotnet_diagnostic.CS1570.severity = none dotnet_diagnostic.CS1584.severity = none dotnet_diagnostic.CS1658.severity = none # Disable CA1815: generated value types carry data only; equality semantics are not part of their contract -dotnet_diagnostic.CA1815.severity = none \ No newline at end of file +dotnet_diagnostic.CA1815.severity = none diff --git a/DEVELOPMENT_STANDARDS.md b/DEVELOPMENT_STANDARDS.md index 444d1ef7e..992a263c8 100644 --- a/DEVELOPMENT_STANDARDS.md +++ b/DEVELOPMENT_STANDARDS.md @@ -141,19 +141,29 @@ Each repository should reference this file from its own `CLAUDE.md` / ### 1.7 `var` for local variables -- Use `var` for local variable declarations when the type is unambiguous from - the right-hand side (constructor call, cast, or literal initialiser). +- Use `var` for every local variable declaration where the compiler accepts + it — including built-in types, `foreach` iteration variables and `out var` + declarations. ```csharp var person = new Person("Alice", 30); - var names = new List(); + var count = 0; var typed = (IFoo)source; + + foreach (var element in elements) + { + if (cache.TryGetValue(element.Id, out var cached)) + { + … + } + } ``` -- Spell out the type explicitly when `var` would hide it — e.g. return - values from opaque method calls, LINQ chains where the element type is - not obvious to the reader, or local variables whose declared type matters - for overload resolution downstream. +- Spell out the type only where `var` cannot express the declaration: no + initialiser, a `const`, a `null` / lambda / method-group / + collection-expression initialiser, or a declared type that must be wider + than the constructed one (`IFoo foo = new Foo();`). +- Enforced by `.editorconfig` (`csharp_style_var_*`) — see §0. ### 1.8 Member ordering diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/DataVersion.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/DataVersion.cs index f6e78f54e..2bc89db5d 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/DataVersion.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/DataVersion.cs @@ -69,7 +69,7 @@ public partial class DataVersion : IResponse, SysML2.NET.Common.IIdentified /// /// Gets or sets the payload of the DataVersion /// - public IData Payload { get; set; } + public SysML2.NET.Common.IData Payload { get; set; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/ExternalData.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/ExternalData.cs index 504b48c9a..23e29048b 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/ExternalData.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenDto/ExternalData.cs @@ -34,7 +34,7 @@ namespace SysML2.NET.PSM.DTO /// Data transfer object that represents the ExternalData schema of the Systems Modeling API and Services /// [GeneratedCode("SysML2.NET", "latest")] - public partial class ExternalData : IData, IResponse, SysML2.NET.Common.IIdentified + public partial class ExternalData : IResponse, SysML2.NET.Common.IData, SysML2.NET.Common.IIdentified { /// /// The value of the type discriminator of the ExternalData schema diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/BranchSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/BranchSerializer.cs new file mode 100644 index 000000000..704b4d2e3 --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/BranchSerializer.cs @@ -0,0 +1,132 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class BranchSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Branch branch) + { + throw new ArgumentException("The object shall be a Branch", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Branch"); + + writer.WriteString("@id"u8, branch.Id); + + writer.WriteStartArray("alias"u8); + + if (branch.Alias != null) + { + foreach (var item in branch.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("created"u8, branch.Created); + + if (branch.Deleted.HasValue) + { + writer.WriteString("deleted"u8, branch.Deleted.Value); + } + else + { + writer.WriteNull("deleted"u8); + } + + writer.WriteString("description"u8, branch.Description); + + if (branch.Head.HasValue) + { + writer.WriteStartObject("head"u8); + writer.WriteString("@id"u8, branch.Head.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("head"u8); + } + + writer.WriteString("name"u8, branch.Name); + + writer.WriteStartObject("owningProject"u8); + writer.WriteString("@id"u8, branch.OwningProject); + writer.WriteEndObject(); + + writer.WriteStartObject("referencedCommit"u8); + writer.WriteString("@id"u8, branch.ReferencedCommit); + writer.WriteEndObject(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CommitRequestSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CommitRequestSerializer.cs new file mode 100644 index 000000000..844f0fa99 --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CommitRequestSerializer.cs @@ -0,0 +1,112 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class CommitRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not CommitRequest commitRequest) + { + throw new ArgumentException("The object shall be a CommitRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Commit"); + + writer.WriteStartArray("alias"u8); + + if (commitRequest.Alias != null) + { + foreach (var item in commitRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteStartArray("change"u8); + + if (commitRequest.Change != null) + { + foreach (var item in commitRequest.Change) + { + DataVersionRequestSerializer.Serialize(item, writer, serializationModeKind, includeDerivedProperties); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, commitRequest.Description); + + writer.WriteString("name"u8, commitRequest.Name); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CommitSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CommitSerializer.cs new file mode 100644 index 000000000..7a1246f76 --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CommitSerializer.cs @@ -0,0 +1,122 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class CommitSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Commit commit) + { + throw new ArgumentException("The object shall be a Commit", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Commit"); + + writer.WriteString("@id"u8, commit.Id); + + writer.WriteStartArray("alias"u8); + + if (commit.Alias != null) + { + foreach (var item in commit.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("created"u8, commit.Created); + + writer.WriteString("description"u8, commit.Description); + + writer.WriteString("name"u8, commit.Name); + + writer.WriteStartObject("owningProject"u8); + writer.WriteString("@id"u8, commit.OwningProject); + writer.WriteEndObject(); + + writer.WriteStartArray("previousCommit"u8); + + if (commit.PreviousCommit != null) + { + foreach (var item in commit.PreviousCommit) + { + writer.WriteStartObject(); + writer.WriteString("@id"u8, item); + writer.WriteEndObject(); + } + } + + writer.WriteEndArray(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CompositeConstraintSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CompositeConstraintSerializer.cs new file mode 100644 index 000000000..324e9a164 --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/CompositeConstraintSerializer.cs @@ -0,0 +1,98 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class CompositeConstraintSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not CompositeConstraint compositeConstraint) + { + throw new ArgumentException("The object shall be a CompositeConstraint", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "CompositeConstraint"); + + writer.WriteStartArray("constraint"u8); + + if (compositeConstraint.Constraint != null) + { + foreach (var item in compositeConstraint.Constraint) + { + PsmSerializationDispatcher.Provide(item.GetType())(item, writer, serializationModeKind, includeDerivedProperties); + } + } + + writer.WriteEndArray(); + + writer.WriteString("operator"u8, compositeConstraint.Operator.ToWireValue()); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/DataVersionSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/DataVersionSerializer.cs new file mode 100644 index 000000000..d6626e911 --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/DataVersionSerializer.cs @@ -0,0 +1,122 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class DataVersionSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not DataVersion dataVersion) + { + throw new ArgumentException("The object shall be a DataVersion", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "DataVersion"); + + writer.WriteString("@id"u8, dataVersion.Id); + + writer.WriteStartArray("alias"u8); + + if (dataVersion.Alias != null) + { + foreach (var item in dataVersion.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, dataVersion.Description); + + if (dataVersion.Identity != null) + { + writer.WritePropertyName("identity"u8); + DataIdentitySerializer.Serialize(dataVersion.Identity, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("identity"u8); + } + + writer.WriteString("name"u8, dataVersion.Name); + + if (dataVersion.Payload != null) + { + writer.WritePropertyName("payload"u8); + PsmSerializationDispatcher.Provide(dataVersion.Payload.GetType())(dataVersion.Payload, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("payload"u8); + } + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/ExternalDataSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/ExternalDataSerializer.cs new file mode 100644 index 000000000..f08509d33 --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/ExternalDataSerializer.cs @@ -0,0 +1,88 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ExternalDataSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ExternalData externalData) + { + throw new ArgumentException("The object shall be a ExternalData", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "ExternalData"); + + writer.WriteString("@id"u8, externalData.Id); + + writer.WriteString("resourceIdentifier"u8, externalData.ResourceIdentifier?.ToString()); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/PrimitiveConstraintRequestSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/PrimitiveConstraintRequestSerializer.cs new file mode 100644 index 000000000..527ae31bc --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/PrimitiveConstraintRequestSerializer.cs @@ -0,0 +1,109 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class PrimitiveConstraintRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not PrimitiveConstraintRequest primitiveConstraintRequest) + { + throw new ArgumentException("The object shall be a PrimitiveConstraintRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "PrimitiveConstraint"); + + if (primitiveConstraintRequest.Inverse.HasValue) + { + writer.WriteBoolean("inverse"u8, primitiveConstraintRequest.Inverse.Value); + } + else + { + writer.WriteNull("inverse"u8); + } + + writer.WriteString("operator"u8, primitiveConstraintRequest.Operator.ToWireValue()); + + writer.WriteString("property"u8, primitiveConstraintRequest.Property); + + writer.WriteStartArray("value"u8); + + if (primitiveConstraintRequest.Value != null) + { + foreach (var item in primitiveConstraintRequest.Value) + { + ConstraintValueWriter.Write(item, writer); + } + } + + writer.WriteEndArray(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/PrimitiveConstraintSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/PrimitiveConstraintSerializer.cs new file mode 100644 index 000000000..951412f28 --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Expected/OpenAPI/PSM/AutoGenSerializer/PrimitiveConstraintSerializer.cs @@ -0,0 +1,102 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class PrimitiveConstraintSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not PrimitiveConstraint primitiveConstraint) + { + throw new ArgumentException("The object shall be a PrimitiveConstraint", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "PrimitiveConstraint"); + + writer.WriteBoolean("inverse"u8, primitiveConstraint.Inverse); + + writer.WriteString("operator"u8, primitiveConstraint.Operator.ToWireValue()); + + writer.WriteString("property"u8, primitiveConstraint.Property); + + writer.WriteStartArray("value"u8); + + if (primitiveConstraint.Value != null) + { + foreach (var item in primitiveConstraint.Value) + { + ConstraintValueWriter.Write(item, writer); + } + } + + writer.WriteEndArray(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator.Tests/Generators/OpenApiHandleBarsGenerators/OpenApiJsonSerializerGeneratorTestFixture.cs b/SysML2.NET.CodeGenerator.Tests/Generators/OpenApiHandleBarsGenerators/OpenApiJsonSerializerGeneratorTestFixture.cs new file mode 100644 index 000000000..ae8fd57bd --- /dev/null +++ b/SysML2.NET.CodeGenerator.Tests/Generators/OpenApiHandleBarsGenerators/OpenApiJsonSerializerGeneratorTestFixture.cs @@ -0,0 +1,98 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.CodeGenerator.Tests.Generators.OpenApiHandleBarsGenerators +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Threading.Tasks; + + using Microsoft.OpenApi; + + using NUnit.Framework; + + using SysML2.NET.CodeGenerator.Extensions; + using SysML2.NET.CodeGenerator.Generators.OpenApiHandleBarsGenerators; + + [TestFixture] + public class OpenApiJsonSerializerGeneratorTestFixture + { + private OpenApiDocument openApiDocument; + private DirectoryInfo outputDirectory; + private OpenApiJsonSerializerGenerator openApiJsonSerializerGenerator; + + [OneTimeSetUp] + public async Task SetUp() + { + this.openApiDocument = await OpenApiDocumentLoader.LoadAsync(); + + var directoryInfo = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); + + this.outputDirectory = directoryInfo.CreateSubdirectory(Path.Combine("OpenAPI", "_SysML2.NET.PSM.AutoGenSerializer")); + this.openApiJsonSerializerGenerator = new OpenApiJsonSerializerGenerator(); + } + + private static IEnumerable InterestingSchemas() + { + var openApiDocument = OpenApiDocumentLoader.LoadAsync().GetAwaiter().GetResult(); + + var serializableSchemas = OpenApiJsonSerializerGenerator.QuerySerializableSchemas(openApiDocument) + .Select(schema => schema.Key) + .ToHashSet(StringComparer.Ordinal); + + return OpenApiSchemaInspector.QueryInterestingSchemas(OpenApiHandleBarsGenerator.QuerySchemas(openApiDocument)) + .Where(serializableSchemas.Contains); + } + + [Test] + public async Task VerifyGenerateAsync() + { + await Assert.ThatAsync(() => this.openApiJsonSerializerGenerator.GenerateAsync(null, this.outputDirectory), Throws.TypeOf()); + await Assert.ThatAsync(() => this.openApiJsonSerializerGenerator.GenerateAsync(this.openApiDocument, null), Throws.TypeOf()); + Assert.That(() => OpenApiJsonSerializerGenerator.QuerySerializableSchemas(null), Throws.TypeOf()); + + await Assert.ThatAsync(() => this.openApiJsonSerializerGenerator.GenerateAsync(this.openApiDocument, this.outputDirectory), Throws.Nothing); + + var serializableSchemas = OpenApiJsonSerializerGenerator.QuerySerializableSchemas(this.openApiDocument); + + using (Assert.EnterMultipleScope()) + { + Assert.That(serializableSchemas.Select(schema => schema.Key), Does.Not.Contain("Data")); + Assert.That(serializableSchemas.Select(schema => schema.Key), Does.Contain("PrimitiveConstraint")); + Assert.That(this.outputDirectory.GetFiles("SerializationProvider.cs"), Has.Length.EqualTo(1)); + } + } + + [Test] + [TestCaseSource(nameof(InterestingSchemas))] + [Category("Expected")] + public async Task VerifyGenerateSerializerAsync(string schemaName) + { + var generatedCode = await this.openApiJsonSerializerGenerator.GenerateSerializerAsync(this.openApiDocument, this.outputDirectory, schemaName); + + var expected = await File.ReadAllTextAsync(Path.Combine(TestContext.CurrentContext.TestDirectory, + $"Expected/OpenAPI/PSM/AutoGenSerializer/{schemaName}Serializer.cs")); + + Assert.That(generatedCode, Is.EqualTo(expected)); + } + } +} diff --git a/SysML2.NET.CodeGenerator/Extensions/OpenApiSchemaExtensions.cs b/SysML2.NET.CodeGenerator/Extensions/OpenApiSchemaExtensions.cs index aa523dd00..480a3f097 100644 --- a/SysML2.NET.CodeGenerator/Extensions/OpenApiSchemaExtensions.cs +++ b/SysML2.NET.CodeGenerator/Extensions/OpenApiSchemaExtensions.cs @@ -101,6 +101,58 @@ public static string QueryTypeDiscriminator(this IOpenApiSchema schema) : null; } + /// + /// Queries whether the schema resolves to a reference that stands for the identifier of another element + /// + /// The subject . + /// True when the schema resolves to a reference to . + public static bool QueryIsIdentifiedReference(this IOpenApiSchema schema) + { + ArgumentNullException.ThrowIfNull(schema); + + return schema.QueryTerminalReferenceInternal()?.Reference?.Id == IdentifiedSchemaName; + } + + /// + /// Queries whether the schema resolves to a reference to another generated class + /// + /// The subject . + /// True when the schema resolves to a reference that is neither an identifier nor a union. + public static bool QueryIsCompositeReference(this IOpenApiSchema schema) + { + ArgumentNullException.ThrowIfNull(schema); + + var terminalReference = schema.QueryTerminalReferenceInternal(); + + return terminalReference is not null && terminalReference.Reference?.Id != IdentifiedSchemaName && !terminalReference.QueryIsUnion(); + } + + /// + /// Queries whether the schema resolves to a reference to a union, whose runtime type decides the serializer + /// + /// The subject . + /// True when the schema resolves to a reference to a union. + public static bool QueryIsPolymorphicReference(this IOpenApiSchema schema) + { + ArgumentNullException.ThrowIfNull(schema); + + var terminalReference = schema.QueryTerminalReferenceInternal(); + + return terminalReference is not null && terminalReference.QueryIsUnion(); + } + + /// + /// Queries the name of the schema that the reference resolves to + /// + /// The subject . + /// The referenced schema name, or null when the schema does not resolve to a reference. + public static string QueryTerminalReferenceName(this IOpenApiSchema schema) + { + ArgumentNullException.ThrowIfNull(schema); + + return schema.QueryTerminalReferenceInternal()?.Reference?.Id; + } + /// /// Queries whether the schema declares an identifier that it lists as required /// @@ -334,7 +386,7 @@ public static string QueryReferencedSchemaName(this IOpenApiSchema schema) { ArgumentNullException.ThrowIfNull(schema); - var annotated = schema.QueryAnnotatedReference(); + var annotated = schema.QueryTerminalReferenceInternal(); if (string.IsNullOrWhiteSpace(annotated?.Comment)) { @@ -401,11 +453,23 @@ public static string QueryEnumerationLiteralName(string enumerationValue) } /// - /// Queries the reference that carries the schema's annotation, looking through a nullable or list wrapper + /// Queries the reference that the schema resolves to, looking through a nullable or list wrapper + /// + /// The subject . + /// The terminal reference, or null when the schema does not resolve to one. + public static OpenApiSchemaReference QueryTerminalReference(this IOpenApiSchema schema) + { + ArgumentNullException.ThrowIfNull(schema); + + return schema.QueryTerminalReferenceInternal(); + } + + /// + /// Queries the reference that the schema resolves to, looking through a nullable or list wrapper /// /// The subject . - /// The annotated reference, or null when the schema does not resolve to one. - private static OpenApiSchemaReference QueryAnnotatedReference(this IOpenApiSchema schema) + /// The terminal reference, or null when the schema does not resolve to one. + private static OpenApiSchemaReference QueryTerminalReferenceInternal(this IOpenApiSchema schema) { if (schema is OpenApiSchemaReference reference) { @@ -420,7 +484,7 @@ private static OpenApiSchemaReference QueryAnnotatedReference(this IOpenApiSchem } return unwrapped?.Type?.HasFlag(JsonSchemaType.Array) == true - ? unwrapped.Items?.QueryAnnotatedReference() + ? unwrapped.Items?.QueryTerminalReferenceInternal() : null; } diff --git a/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiDtoGenerator.cs b/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiDtoGenerator.cs index d91eab924..fadab6074 100644 --- a/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiDtoGenerator.cs +++ b/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiDtoGenerator.cs @@ -54,8 +54,12 @@ public class OpenApiDtoGenerator : OpenApiHandleBarsGenerator /// /// The interfaces that the interface generated for a union schema extends /// - private static readonly Dictionary BaseInterfaceNames = - new(StringComparer.Ordinal) { ["Data"] = "SysML2.NET.Common.IData" }; + private static readonly Dictionary SuppressedUnionInterfaces = + new(StringComparer.Ordinal) + { + ["Data"] = "SysML2.NET.Common.IData", + ["DataRequest"] = "SysML2.NET.Common.IDataRequest" + }; /// /// The declared types of the properties whose schema has no C# equivalent, keyed by class and property name @@ -67,6 +71,21 @@ public class OpenApiDtoGenerator : OpenApiHandleBarsGenerator [("PrimitiveConstraintRequest", "value")] = "List" }; + /// + /// The declared types of the properties that reference a union whose alternatives are not all generated + /// + private static readonly Dictionary UnionTypeOverrides = + new(StringComparer.Ordinal) + { + ["Data"] = "SysML2.NET.Common.IData", + ["DataRequest"] = "SysML2.NET.Common.IDataRequest" + }; + + /// + /// The declared types of the properties that reference a mapped union, scoped to the current generation run + /// + private Dictionary<(string ClassName, string PropertyName), string> unionPropertyTypes = []; + /// /// The interfaces implemented by the class generated for a schema name, scoped to the current generation run /// @@ -147,9 +166,9 @@ protected override void RegisterHelpers() { this.Handlebars.RegisterSchemaHelper( schemaName => this.implementedInterfaces[schemaName], - schemaName => BaseInterfaceNames.TryGetValue(schemaName, out var baseInterfaceName) ? [baseInterfaceName] : [], - QueryPropertyTypeOverride); - this.Handlebars.RegisterPropertyHelper(QueryPropertyTypeOverride); + this.QueryPropertyTypeOverride); + + this.Handlebars.RegisterPropertyHelper(this.QueryPropertyTypeOverride); this.Handlebars.RegisterDocumentationHelper(); this.Handlebars.RegisterEnumerationHelper(); } @@ -180,7 +199,8 @@ private static ILookup QueryImplementedInterfaces(IReadOnlyList< .Where(schema => schema.Value.QueryIsUnion()) .SelectMany(union => union.Value.QueryUnionAlternativeNames() .Where(schemaNames.Contains) - .Select(alternativeName => (Alternative: alternativeName, Interface: OpenApiSchemaExtensions.QueryInterfaceName(union.Key)))); + .Select(alternativeName => (Alternative: alternativeName, Interface: QueryUnionInterfaceName(union.Key)))) + .Where(pair => pair.Interface is not null); var familyMemberships = schemas .Where(schema => !schema.Value.QueryIsUnion()) @@ -192,6 +212,38 @@ private static ILookup QueryImplementedInterfaces(IReadOnlyList< .ToLookup(pair => pair.Alternative, pair => pair.Interface, StringComparer.Ordinal); } + /// + /// Queries the interface that the alternatives of a union implement + /// + /// + /// The name of the union schema + /// + /// + /// The generated interface, the type that replaces it, or null when the alternatives implement nothing + /// + private static string QueryUnionInterfaceName(string unionName) + { + return SuppressedUnionInterfaces.TryGetValue(unionName, out var replacementName) + ? replacementName + : OpenApiSchemaExtensions.QueryInterfaceName(unionName); + } + + /// + /// Queries the union schemas that an interface is generated for + /// + /// + /// The in-scope schemas + /// + /// + /// The union schemas whose interface is not suppressed + /// + private static IReadOnlyList> QueryGeneratedInterfaceSchemas(IReadOnlyList> schemas) + { + return schemas + .Where(schema => schema.Value.QueryIsUnion() && !SuppressedUnionInterfaces.ContainsKey(schema.Key)) + .ToList(); + } + /// /// Queries the family interfaces that the class generated for a schema implements /// @@ -226,9 +278,49 @@ private static IEnumerable QueryFamilyInterfaces(string schemaName, IOpe /// /// The declared type, or null when the property is resolved from its schema /// - private static string QueryPropertyTypeOverride(string className, string propertyName) + private string QueryPropertyTypeOverride(string className, string propertyName) { - return PropertyTypeOverrides.TryGetValue((className, propertyName), out var typeName) ? typeName : null; + if (PropertyTypeOverrides.TryGetValue((className, propertyName), out var typeName)) + { + return typeName; + } + + return this.unionPropertyTypes.TryGetValue((className, propertyName), out var unionTypeName) ? unionTypeName : null; + } + + /// + /// Queries the declared types of the properties that reference a union listed in + /// + /// + /// The in-scope schemas + /// + /// + /// The declared type of each such property, keyed by class and property name + /// + private static Dictionary<(string ClassName, string PropertyName), string> QueryUnionPropertyTypes(IReadOnlyList> schemas) + { + return schemas + .Where(schema => !schema.Value.QueryIsUnion() && schema.Value.Properties is not null) + .SelectMany(schema => schema.Value.Properties + .Select(property => (Key: (schema.Key, property.Key), TypeName: QueryUnionTypeOverride(property.Value)))) + .Where(entry => entry.TypeName is not null) + .ToDictionary(entry => entry.Key, entry => entry.TypeName); + } + + /// + /// Queries the declared type that the union referenced by the property schema is mapped to + /// + /// + /// The that defines the property + /// + /// + /// The declared type, or null when the property does not reference a mapped union + /// + private static string QueryUnionTypeOverride(IOpenApiSchema propertySchema) + { + var referencedName = propertySchema.QueryTerminalReferenceName(); + + return referencedName is not null && UnionTypeOverrides.TryGetValue(referencedName, out var typeName) ? typeName : null; } /// @@ -247,15 +339,13 @@ private async Task GenerateInternalAsync(OpenApiDocument openApiDocument, Direct { var schemas = this.AssignGenerationScope(openApiDocument); - foreach (var schema in schemas) + foreach (var schema in QueryGeneratedInterfaceSchemas(schemas)) { - if (schema.Value.QueryIsUnion()) - { - await this.WriteInterfaceAsync(schema, outputDirectory); - - continue; - } + await this.WriteInterfaceAsync(schema, outputDirectory); + } + foreach (var schema in schemas.Where(schema => !schema.Value.QueryIsUnion())) + { await this.WriteClassAsync(schema, outputDirectory); } } @@ -301,7 +391,7 @@ private async Task GenerateDataTransferObjectInterfaceInternalAsync(Open { var schemas = this.AssignGenerationScope(openApiDocument); - return await this.WriteInterfaceAsync(schemas.Single(schema => schema.Key == name), outputDirectory); + return await this.WriteInterfaceAsync(QueryGeneratedInterfaceSchemas(schemas).Single(schema => schema.Key == name), outputDirectory); } /// @@ -318,6 +408,7 @@ private IReadOnlyList> AssignGenerationScop var schemas = QuerySchemas(openApiDocument); this.implementedInterfaces = QueryImplementedInterfaces(schemas); + this.unionPropertyTypes = QueryUnionPropertyTypes(schemas); return schemas; } diff --git a/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiEnumGenerator.cs b/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiEnumGenerator.cs index cc569b96e..a0c7866a3 100644 --- a/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiEnumGenerator.cs +++ b/SysML2.NET.CodeGenerator/Generators/OpenApiHandleBarsGenerators/OpenApiEnumGenerator.cs @@ -41,6 +41,11 @@ public class OpenApiEnumGenerator : OpenApiHandleBarsGenerator /// private const string EnumerationTemplateName = "psm-enumeration-openapi-template"; + /// + /// The name of the template that generates the extension methods of an enumeration + /// + private const string EnumerationExtensionsTemplateName = "psm-enumeration-extensions-openapi-template"; + /// /// Generates the enumerations declared inline by the schemas of the OpenAPI document /// @@ -119,6 +124,7 @@ protected override void RegisterHelpers() protected override void RegisterTemplates() { this.RegisterTemplate(EnumerationTemplateName); + this.RegisterTemplate(EnumerationExtensionsTemplateName); } /// @@ -181,6 +187,10 @@ private async Task WriteEnumerationAsync(KeyValuePair +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.CodeGenerator.Generators.OpenApiHandleBarsGenerators +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Threading.Tasks; + + using Microsoft.OpenApi; + + using SysML2.NET.CodeGenerator.Extensions; + using SysML2.NET.CodeGenerator.OpenApiHandleBarHelpers; + + /// + /// OpenAPI based handlebars generator for the JSON serializers + /// + public class OpenApiJsonSerializerGenerator : OpenApiHandleBarsGenerator + { + /// + /// The name of the template that generates the serializer of a class + /// + private const string SerializerTemplateName = "psm-json-serializer-openapi-template"; + + /// + /// The name of the template that generates the serialization provider + /// + private const string ProviderTemplateName = "psm-json-serialization-provider-openapi-template"; + + /// + /// The writers that emit the items of the properties whose schema has no C# equivalent + /// + private static readonly Dictionary<(string ClassName, string PropertyName), string> ElementWriterOverrides = + new() + { + [("PrimitiveConstraint", "value")] = "ConstraintValueWriter.Write", + [("PrimitiveConstraintRequest", "value")] = "ConstraintValueWriter.Write" + }; + + /// + /// Generates the JSON serializers of the schemas of the OpenAPI document + /// + /// + /// the that contains the OpenAPI model to generate from + /// + /// + /// The target + /// + /// + /// an awaitable + /// + public override Task GenerateAsync(OpenApiDocument openApiDocument, DirectoryInfo outputDirectory) + { + ArgumentNullException.ThrowIfNull(openApiDocument); + ArgumentNullException.ThrowIfNull(outputDirectory); + + return this.GenerateInternalAsync(openApiDocument, outputDirectory); + } + + /// + /// Generates the JSON serializer of the specified schema + /// + /// + /// the that contains the OpenAPI model to generate from + /// + /// + /// The target + /// + /// + /// The name of the schema to generate the serializer for + /// + /// + /// The generated code + /// + public Task GenerateSerializerAsync(OpenApiDocument openApiDocument, DirectoryInfo outputDirectory, string name) + { + ArgumentNullException.ThrowIfNull(openApiDocument); + ArgumentNullException.ThrowIfNull(outputDirectory); + ArgumentException.ThrowIfNullOrWhiteSpace(name); + + return this.GenerateSerializerInternalAsync(openApiDocument, outputDirectory, name); + } + + /// + /// Queries the schemas that a serializer is generated for + /// + /// + /// the that contains the OpenAPI model to generate from + /// + /// + /// The in-scope schemas that are not unions, ordered by name + /// + public static IReadOnlyList> QuerySerializableSchemas(OpenApiDocument openApiDocument) + { + ArgumentNullException.ThrowIfNull(openApiDocument); + + return QuerySchemas(openApiDocument).Where(schema => !schema.Value.QueryIsUnion()).ToList(); + } + + /// + /// Register the custom helpers + /// + protected override void RegisterHelpers() + { + this.Handlebars.RegisterSchemaHelper( + _ => [], + QueryElementWriterOverride); + this.Handlebars.RegisterJsonSerializerHelper(QueryElementWriterOverride); + } + + /// + /// Register the code templates + /// + protected override void RegisterTemplates() + { + this.RegisterTemplate(SerializerTemplateName); + this.RegisterTemplate(ProviderTemplateName); + } + + /// + /// Queries the writer that emits the items of a property whose schema has no C# equivalent + /// + /// + /// The name of the class that declares the property + /// + /// + /// The name of the property as it appears in the schema + /// + /// + /// The writer, or null when the property is serialized from its schema + /// + private static string QueryElementWriterOverride(string className, string propertyName) + { + return ElementWriterOverrides.TryGetValue((className, propertyName), out var writerName) ? writerName : null; + } + + /// + /// Generates the JSON serializers of the schemas of the OpenAPI document + /// + /// + /// the that contains the OpenAPI model to generate from + /// + /// + /// The target + /// + /// + /// an awaitable + /// + private async Task GenerateInternalAsync(OpenApiDocument openApiDocument, DirectoryInfo outputDirectory) + { + var schemas = QuerySerializableSchemas(openApiDocument); + + foreach (var schema in schemas) + { + await this.WriteSerializerAsync(schema, outputDirectory); + } + + var generatedProvider = this.CodeCleanup(this.Templates[ProviderTemplateName](schemas.Select(schema => schema.Key).ToList())); + + await WriteAsync(generatedProvider, outputDirectory, "SerializationProvider.cs"); + } + + /// + /// Generates the JSON serializer of the specified schema + /// + /// + /// the that contains the OpenAPI model to generate from + /// + /// + /// The target + /// + /// + /// The name of the schema to generate the serializer for + /// + /// + /// The generated code + /// + private async Task GenerateSerializerInternalAsync(OpenApiDocument openApiDocument, DirectoryInfo outputDirectory, string name) + { + var schema = QuerySerializableSchemas(openApiDocument).Single(candidate => candidate.Key == name); + + return await this.WriteSerializerAsync(schema, outputDirectory); + } + + /// + /// Applies the serializer template to the schema and writes the result to disk + /// + /// + /// The schema to generate the serializer for + /// + /// + /// The target + /// + /// + /// The generated code + /// + private async Task WriteSerializerAsync(KeyValuePair schema, DirectoryInfo outputDirectory) + { + var generatedCode = this.CodeCleanup(this.Templates[SerializerTemplateName](schema)); + + await WriteAsync(generatedCode, outputDirectory, $"{schema.Key}Serializer.cs"); + + return generatedCode; + } + } +} diff --git a/SysML2.NET.CodeGenerator/OpenApiHandleBarHelpers/JsonSerializerHelper.cs b/SysML2.NET.CodeGenerator/OpenApiHandleBarHelpers/JsonSerializerHelper.cs new file mode 100644 index 000000000..333ab4f42 --- /dev/null +++ b/SysML2.NET.CodeGenerator/OpenApiHandleBarHelpers/JsonSerializerHelper.cs @@ -0,0 +1,168 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.CodeGenerator.OpenApiHandleBarHelpers +{ + using System; + + using HandlebarsDotNet; + + using Microsoft.OpenApi; + + using SysML2.NET.CodeGenerator.Extensions; + + /// + /// A handlebars block helper that supports the generation of the JSON serializers + /// + public static class JsonSerializerHelper + { + /// + /// Registers the + /// + /// + /// The context with which the helper needs to be registered + /// + /// + /// A function that returns the writer that emits the items of a property whose schema has no C# equivalent + /// + public static void RegisterJsonSerializerHelper(this IHandlebars handlebars, Func queryElementWriterOverride) + { + ArgumentNullException.ThrowIfNull(handlebars); + ArgumentNullException.ThrowIfNull(queryElementWriterOverride); + + handlebars.RegisterHelper("Serializer.WriteInstanceName", (writer, _, arguments) => + writer.WriteSafeString(QueryInstanceName(QuerySchemaName(arguments, 0)))); + + handlebars.RegisterHelper("Property.WriteName", (writer, _, arguments) => + writer.WriteSafeString(OpenApiSchemaExtensions.QueryPropertyName(QuerySchemaName(arguments, 0)))); + + handlebars.RegisterHelper("Property.WriteAccessor", (writer, _, arguments) => + writer.WriteSafeString($"{QueryInstanceName(QuerySchemaName(arguments, 1))}.{OpenApiSchemaExtensions.QueryPropertyName(QuerySchemaName(arguments, 0))}")); + + handlebars.RegisterHelper("Property.WriteReferencedSerializer", (writer, _, arguments) => + writer.WriteSafeString($"{QueryPropertySchema(arguments).QueryTerminalReferenceName()}Serializer")); + + handlebars.RegisterHelper("Property.WriteElementWriter", (writer, _, arguments) => + writer.WriteSafeString(queryElementWriterOverride(QuerySchemaName(arguments, 1), QuerySchemaName(arguments, 0)))); + + handlebars.RegisterHelper("Property.QueryIsOverridden", (_, arguments) => + queryElementWriterOverride(QuerySchemaName(arguments, 1), QuerySchemaName(arguments, 0)) is not null); + + handlebars.RegisterHelper("Property.QueryIsCollection", (_, arguments) => + QueryPropertySchema(arguments).QueryIsCollection()); + + handlebars.RegisterHelper("Property.QueryIsIdentifiedReference", (_, arguments) => + QueryPropertySchema(arguments).QueryIsIdentifiedReference()); + + handlebars.RegisterHelper("Property.QueryIsComposite", (_, arguments) => + QueryPropertySchema(arguments).QueryIsCompositeReference()); + + handlebars.RegisterHelper("Property.QueryIsPolymorphic", (_, arguments) => + QueryPropertySchema(arguments).QueryIsPolymorphicReference()); + + handlebars.RegisterHelper("Property.QueryIsEnumeration", (_, arguments) => + QueryCoreTypeName(arguments) == OpenApiSchemaExtensions.QueryEnumerationTypeName(QuerySchemaName(arguments, 1), QuerySchemaName(arguments, 0))); + + handlebars.RegisterHelper("Property.QueryIsBoolean", (_, arguments) => QueryCoreTypeName(arguments) == "bool"); + + handlebars.RegisterHelper("Property.QueryIsNumeric", (_, arguments) => QueryCoreTypeName(arguments) is "double" or "int"); + + handlebars.RegisterHelper("Property.QueryIsUri", (_, arguments) => QueryCoreTypeName(arguments) == "Uri"); + + handlebars.RegisterHelper("Property.QueryIsNullableValue", (_, arguments) => + { + var propertySchema = QueryPropertySchema(arguments); + + return propertySchema.QueryIsValueType() && propertySchema.QueryIsNullable(QueryIsRequired(arguments)); + }); + } + + /// + /// Queries the name of the local variable that holds the instance being serialized + /// + /// The name of the class that is serialized. + /// The name of the local variable. + private static string QueryInstanceName(string className) + { + return char.ToLowerInvariant(className[0]) + className[1..]; + } + + /// + /// Queries a name from the helper arguments + /// + /// The helper arguments, being the property name, the class name and the class schema. + /// The index of the argument. + /// The name. + private static string QuerySchemaName(Arguments arguments, int index) + { + if (arguments.Length < index + 1) + { + throw new HandlebarsException("the helper is missing arguments"); + } + + return arguments[index] as string ?? throw new ArgumentException("supposed to be a name"); + } + + /// + /// Queries the schema of the property that the helper arguments identify + /// + /// The helper arguments, being the property name, the class name and the class schema. + /// The of the property. + private static IOpenApiSchema QueryPropertySchema(Arguments arguments) + { + return QueryClassSchema(arguments).Properties[QuerySchemaName(arguments, 0)]; + } + + /// + /// Queries the schema of the class that the helper arguments identify + /// + /// The helper arguments, being the property name, the class name and the class schema. + /// The of the class. + private static IOpenApiSchema QueryClassSchema(Arguments arguments) + { + if (arguments.Length != 3) + { + throw new HandlebarsException("the helper must have exactly three arguments"); + } + + return arguments[2] as IOpenApiSchema ?? throw new ArgumentException("supposed to be IOpenApiSchema"); + } + + /// + /// Queries whether the class lists the property as required + /// + /// The helper arguments, being the property name, the class name and the class schema. + /// True when the property is required. + private static bool QueryIsRequired(Arguments arguments) + { + return QueryClassSchema(arguments).Required?.Contains(QuerySchemaName(arguments, 0)) == true; + } + + /// + /// Queries the C# type of the property that the helper arguments identify + /// + /// The helper arguments, being the property name, the class name and the class schema. + /// The C# type without its list wrapper or nullable annotation. + private static string QueryCoreTypeName(Arguments arguments) + { + return QueryPropertySchema(arguments).QueryCoreTypeName(QuerySchemaName(arguments, 1), QuerySchemaName(arguments, 0)); + } + } +} diff --git a/SysML2.NET.CodeGenerator/OpenApiHandleBarHelpers/SchemaHelper.cs b/SysML2.NET.CodeGenerator/OpenApiHandleBarHelpers/SchemaHelper.cs index 51fa1d7fe..3cd407c0d 100644 --- a/SysML2.NET.CodeGenerator/OpenApiHandleBarHelpers/SchemaHelper.cs +++ b/SysML2.NET.CodeGenerator/OpenApiHandleBarHelpers/SchemaHelper.cs @@ -44,38 +44,15 @@ public static class SchemaHelper /// /// A function that returns the interfaces implemented by the class generated for a schema name /// - /// - /// A function that returns the interfaces extended by the interface generated for a union schema name - /// /// /// A function that returns the declared type of a property whose schema has no C# equivalent /// - public static void RegisterSchemaHelper(this IHandlebars handlebars, Func> queryImplementedInterfaces, Func> queryBaseInterfaces, Func queryTypeOverride) + public static void RegisterSchemaHelper(this IHandlebars handlebars, Func> queryImplementedInterfaces, Func queryTypeOverride) { ArgumentNullException.ThrowIfNull(handlebars); ArgumentNullException.ThrowIfNull(queryImplementedInterfaces); - ArgumentNullException.ThrowIfNull(queryBaseInterfaces); ArgumentNullException.ThrowIfNull(queryTypeOverride); - handlebars.RegisterHelper("Schema.WriteBaseInterfaces", (writer, _, arguments) => - { - if (arguments.Length != 1) - { - throw new HandlebarsException("{{#Schema.WriteBaseInterfaces}} helper must have exactly one argument"); - } - - var schemaName = arguments[0] as string ?? throw new ArgumentException("supposed to be a schema name"); - - var baseInterfaces = queryBaseInterfaces(schemaName) - .OrderBy(interfaceName => interfaceName, StringComparer.Ordinal) - .ToList(); - - if (baseInterfaces.Count > 0) - { - writer.WriteSafeString($" : {string.Join(", ", baseInterfaces)}"); - } - }); - handlebars.RegisterHelper("Schema.WriteImplementedInterfaces", (writer, _, arguments) => { if (arguments.Length != 1) diff --git a/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj b/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj index 99e31eb9c..05a4be5e4 100644 --- a/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj +++ b/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj @@ -263,6 +263,15 @@ Always + + Always + + + Always + + + Always + diff --git a/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-dto-interface-openapi-template.hbs b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-dto-interface-openapi-template.hbs index 81be67c38..ede53bac6 100644 --- a/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-dto-interface-openapi-template.hbs +++ b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-dto-interface-openapi-template.hbs @@ -33,7 +33,7 @@ namespace SysML2.NET.PSM.DTO /// The {{this.Key}} schema admits {{#Schema.WriteUnionAlternatives this.Value}} /// [GeneratedCode("SysML2.NET", "latest")] - public partial interface I{{this.Key}}{{#Schema.WriteBaseInterfaces this.Key}} + public partial interface I{{this.Key}} { } } diff --git a/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-enumeration-extensions-openapi-template.hbs b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-enumeration-extensions-openapi-template.hbs new file mode 100644 index 000000000..9af5c2627 --- /dev/null +++ b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-enumeration-extensions-openapi-template.hbs @@ -0,0 +1,57 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.PSM.Enumerations +{ + using System; + using System.CodeDom.Compiler; + + /// + /// Extension methods for the enumeration + /// + [GeneratedCode("SysML2.NET", "latest")] + public static class {{this.Key}}Extensions + { + /// + /// Queries the value that represents the literal in the Systems Modeling API and Services + /// + /// The subject . + /// The value as it appears on the wire. + /// Thrown when the literal is not known. + public static string ToWireValue(this {{this.Key}} value) + { + return value switch + { + {{#each (Enumeration.QueryValues this.Value) as | enumerationValue |}} + {{../this.Key}}.{{#Enumeration.WriteLiteralName enumerationValue}} => "{{{enumerationValue}}}", + {{/each}} + _ => throw new ArgumentOutOfRangeException(nameof(value)) + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-json-serialization-provider-openapi-template.hbs b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-json-serialization-provider-openapi-template.hbs new file mode 100644 index 000000000..b72bc5625 --- /dev/null +++ b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-json-serialization-provider-openapi-template.hbs @@ -0,0 +1,90 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Collections.Generic; + using System.Text.Json; + + using SysML2.NET.Serializer.Json; + + /// + /// Delegate provider for the appropriate serialization method to serialize a + /// + internal static class SerializationProvider + { + /// + /// Caches the delegate for the + /// that is to be serialized + /// + private static readonly Dictionary> SerializerActionMap = + new Dictionary> + { + {{#each this as | schemaName |}} + { typeof(SysML2.NET.PSM.DTO.{{schemaName}}), {{schemaName}}Serializer.Serialize }, + {{/each}} + }; + + /// + /// Provides the delegate that serializes the specified + /// + /// + /// The that is to be serialized + /// + /// + /// The delegate that serializes the + /// + /// + /// Thrown when the is not supported + /// + internal static Action Provide(Type type) + { + if (!SerializerActionMap.TryGetValue(type, out var action)) + { + throw new NotSupportedException($"The {type.Name} is not supported by the SerializationProvider."); + } + + return action; + } + + /// + /// Asserts whether the specified is supported by the provider + /// + /// + /// The for which support is asserted + /// + /// + /// True when the is supported + /// + internal static bool IsTypeSupported(Type type) + { + return SerializerActionMap.ContainsKey(type); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-json-serializer-openapi-template.hbs b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-json-serializer-openapi-template.hbs new file mode 100644 index 000000000..1fd1d1dc6 --- /dev/null +++ b/SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-json-serializer-openapi-template.hbs @@ -0,0 +1,196 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class {{this.Key}}Serializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not {{this.Key}} {{#Serializer.WriteInstanceName this.Key}}) + { + throw new ArgumentException("The object shall be a {{this.Key}}", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + {{#if (Schema.QueryHasTypeDiscriminator this.Value)}} + writer.WriteString("@type"u8, "{{#Schema.WriteTypeDiscriminator this.Value}}"); + + {{/if}} + {{#each (Schema.QueryPropertyNames this.Value this.Key) as | propertyName |}} + {{#if (Property.QueryIsOverridden propertyName ../this.Key ../this.Value)}} + writer.WriteStartArray("{{propertyName}}"u8); + + if ({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}} != null) + { + foreach (var item in {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}) + { + {{#Property.WriteElementWriter propertyName ../this.Key ../this.Value}}(item, writer); + } + } + + writer.WriteEndArray(); + {{else if (Property.QueryIsCollection propertyName ../this.Key ../this.Value)}} + writer.WriteStartArray("{{propertyName}}"u8); + + if ({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}} != null) + { + foreach (var item in {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}) + { + {{#if (Property.QueryIsIdentifiedReference propertyName ../this.Key ../this.Value)}} + writer.WriteStartObject(); + writer.WriteString("@id"u8, item); + writer.WriteEndObject(); + {{else if (Property.QueryIsPolymorphic propertyName ../this.Key ../this.Value)}} + PsmSerializationDispatcher.Provide(item.GetType())(item, writer, serializationModeKind, includeDerivedProperties); + {{else if (Property.QueryIsComposite propertyName ../this.Key ../this.Value)}} + {{#Property.WriteReferencedSerializer propertyName ../this.Key ../this.Value}}.Serialize(item, writer, serializationModeKind, includeDerivedProperties); + {{else if (Property.QueryIsEnumeration propertyName ../this.Key ../this.Value)}} + writer.WriteStringValue(item.ToWireValue()); + {{else if (Property.QueryIsBoolean propertyName ../this.Key ../this.Value)}} + writer.WriteBooleanValue(item); + {{else if (Property.QueryIsNumeric propertyName ../this.Key ../this.Value)}} + writer.WriteNumberValue(item); + {{else if (Property.QueryIsUri propertyName ../this.Key ../this.Value)}} + writer.WriteStringValue(item?.ToString()); + {{else}} + writer.WriteStringValue(item); + {{/if}} + } + } + + writer.WriteEndArray(); + {{else if (Property.QueryIsIdentifiedReference propertyName ../this.Key ../this.Value)}} + {{#if (Property.QueryIsNullableValue propertyName ../this.Key ../this.Value)}} + if ({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.HasValue) + { + writer.WriteStartObject("{{propertyName}}"u8); + writer.WriteString("@id"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("{{propertyName}}"u8); + } + {{else}} + writer.WriteStartObject("{{propertyName}}"u8); + writer.WriteString("@id"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}); + writer.WriteEndObject(); + {{/if}} + {{else if (Property.QueryIsPolymorphic propertyName ../this.Key ../this.Value)}} + if ({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}} != null) + { + writer.WritePropertyName("{{propertyName}}"u8); + PsmSerializationDispatcher.Provide({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.GetType())({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("{{propertyName}}"u8); + } + {{else if (Property.QueryIsComposite propertyName ../this.Key ../this.Value)}} + if ({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}} != null) + { + writer.WritePropertyName("{{propertyName}}"u8); + {{#Property.WriteReferencedSerializer propertyName ../this.Key ../this.Value}}.Serialize({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("{{propertyName}}"u8); + } + {{else if (Property.QueryIsNullableValue propertyName ../this.Key ../this.Value)}} + if ({{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.HasValue) + { + {{#if (Property.QueryIsEnumeration propertyName ../this.Key ../this.Value)}} + writer.WriteString("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.Value.ToWireValue()); + {{else if (Property.QueryIsBoolean propertyName ../this.Key ../this.Value)}} + writer.WriteBoolean("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.Value); + {{else if (Property.QueryIsNumeric propertyName ../this.Key ../this.Value)}} + writer.WriteNumber("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.Value); + {{else}} + writer.WriteString("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.Value); + {{/if}} + } + else + { + writer.WriteNull("{{propertyName}}"u8); + } + {{else if (Property.QueryIsEnumeration propertyName ../this.Key ../this.Value)}} + writer.WriteString("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}.ToWireValue()); + {{else if (Property.QueryIsBoolean propertyName ../this.Key ../this.Value)}} + writer.WriteBoolean("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}); + {{else if (Property.QueryIsNumeric propertyName ../this.Key ../this.Value)}} + writer.WriteNumber("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}); + {{else if (Property.QueryIsUri propertyName ../this.Key ../this.Value)}} + writer.WriteString("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}?.ToString()); + {{else}} + writer.WriteString("{{propertyName}}"u8, {{#Property.WriteAccessor propertyName ../this.Key ../this.Value}}); + {{/if}} + + {{/each}} + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json.Tests/PsmSerializerTestFixture.cs b/SysML2.NET.Serializer.Json.Tests/PsmSerializerTestFixture.cs new file mode 100644 index 000000000..0b732bc7d --- /dev/null +++ b/SysML2.NET.Serializer.Json.Tests/PsmSerializerTestFixture.cs @@ -0,0 +1,294 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.Tests +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Text; + using System.Text.Json; + + using NUnit.Framework; + + using SysML2.NET.Core.DTO.Core.Features; + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + [TestFixture] + public class PsmSerializerTestFixture + { + private static readonly Guid ProjectIdentifier = Guid.Parse("9b0e1914-3241-461e-b9ee-a3ff5120de4e"); + + private static readonly Guid BranchIdentifier = Guid.Parse("a910a705-7fbe-415f-9cbb-624bfadf6c20"); + + private static readonly Guid DataVersionIdentifier = Guid.Parse("94e5b40e-741e-49ca-bd7f-f3138c071bf9"); + + private static readonly Guid ElementIdentifier = Guid.Parse("00a6ef10-d3dc-4741-9029-2c9978c2f083"); + + private Serializer serializer; + + private JsonWriterOptions jsonWriterOptions; + + [SetUp] + public void SetUp() + { + this.serializer = new Serializer(); + this.jsonWriterOptions = new JsonWriterOptions { Indented = false }; + } + + [Test] + public void VerifySerializeResponse() + { + var project = new Project + { + Id = ProjectIdentifier, + Alias = ["first", "second"], + Created = new DateTime(1976, 8, 20, 0, 0, 0, DateTimeKind.Utc), + DefaultBranch = BranchIdentifier, + Description = "the description", + Name = "the name" + }; + + var json = Serialize(stream => this.serializer.SerializeResponse(project, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var document = JsonDocument.Parse(json); + var root = document.RootElement; + + using (Assert.EnterMultipleScope()) + { + Assert.That(root.GetProperty("@type").GetString(), Is.EqualTo("Project")); + Assert.That(root.GetProperty("@id").GetGuid(), Is.EqualTo(ProjectIdentifier)); + Assert.That(root.GetProperty("alias").GetArrayLength(), Is.EqualTo(2)); + Assert.That(root.GetProperty("alias")[0].GetString(), Is.EqualTo("first")); + Assert.That(root.GetProperty("created").GetDateTime(), Is.EqualTo(new DateTime(1976, 8, 20, 0, 0, 0, DateTimeKind.Utc))); + Assert.That(root.GetProperty("defaultBranch").GetProperty("@id").GetGuid(), Is.EqualTo(BranchIdentifier)); + Assert.That(root.GetProperty("name").GetString(), Is.EqualTo("the name")); + } + + var collectionJson = Serialize(stream => + this.serializer.SerializeResponse(new List { project }, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + Assert.That(collectionJson, Does.StartWith("[{").And.EndWith("}]")); + } + + [Test] + public void VerifySerializeRequest() + { + var projectRequest = new ProjectRequest + { + Alias = [], + DefaultBranch = BranchIdentifier, + Description = null, + Name = "the name" + }; + + var json = Serialize(stream => this.serializer.SerializeRequest(projectRequest, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var document = JsonDocument.Parse(json); + var root = document.RootElement; + + using (Assert.EnterMultipleScope()) + { + Assert.That(root.GetProperty("@type").GetString(), Is.EqualTo("Project")); + Assert.That(root.TryGetProperty("@id", out _), Is.False); + Assert.That(root.GetProperty("alias").GetArrayLength(), Is.EqualTo(0)); + Assert.That(root.GetProperty("defaultBranch").GetProperty("@id").GetGuid(), Is.EqualTo(BranchIdentifier)); + Assert.That(root.GetProperty("description").ValueKind, Is.EqualTo(JsonValueKind.Null)); + } + + var withoutBranch = new ProjectRequest { Name = "no branch" }; + + var nullBranchJson = Serialize(stream => this.serializer.SerializeRequest(withoutBranch, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + Assert.That(nullBranchJson, Does.Contain("\"defaultBranch\":null")); + } + + [Test] + public void VerifySerializeConstraint() + { + var constraint = new PrimitiveConstraint + { + Inverse = true, + Operator = PrimitiveConstraintOperator.lessthan, + Property = "created", + Value = + [ + ConstraintValue.From(true), + ConstraintValue.From(1.5), + ConstraintValue.From("text"), + ConstraintValue.From(ProjectIdentifier), + ConstraintValue.Null + ] + }; + + var json = Serialize(stream => this.serializer.SerializeResponse(constraint, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var document = JsonDocument.Parse(json); + var root = document.RootElement; + var values = root.GetProperty("value"); + + using (Assert.EnterMultipleScope()) + { + Assert.That(root.GetProperty("@type").GetString(), Is.EqualTo("PrimitiveConstraint")); + Assert.That(root.GetProperty("inverse").GetBoolean(), Is.True); + Assert.That(root.GetProperty("operator").GetString(), Is.EqualTo("<")); + Assert.That(values.GetArrayLength(), Is.EqualTo(5)); + Assert.That(values[0].GetBoolean(), Is.True); + Assert.That(values[1].GetDouble(), Is.EqualTo(1.5)); + Assert.That(values[2].GetString(), Is.EqualTo("text")); + Assert.That(values[3].GetProperty("@id").GetGuid(), Is.EqualTo(ProjectIdentifier)); + Assert.That(values[4].ValueKind, Is.EqualTo(JsonValueKind.Null)); + } + + var composite = new CompositeConstraint + { + Operator = CompositeConstraintOperator.and, + Constraint = [constraint] + }; + + var compositeJson = Serialize(stream => this.serializer.SerializeResponse(composite, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var compositeDocument = JsonDocument.Parse(compositeJson); + var compositeRoot = compositeDocument.RootElement; + + using (Assert.EnterMultipleScope()) + { + Assert.That(compositeRoot.GetProperty("@type").GetString(), Is.EqualTo("CompositeConstraint")); + Assert.That(compositeRoot.GetProperty("operator").GetString(), Is.EqualTo("and")); + Assert.That(compositeRoot.GetProperty("constraint")[0].GetProperty("@type").GetString(), Is.EqualTo("PrimitiveConstraint")); + } + } + + [Test] + public void VerifySerializeDataVersion() + { + var element = new Feature { Id = ElementIdentifier, ElementId = ElementIdentifier.ToString() }; + + var dataVersion = new DataVersion + { + Id = DataVersionIdentifier, + Identity = new DataIdentity { Id = ElementIdentifier, Name = "the identity" }, + Payload = element + }; + + var json = Serialize(stream => this.serializer.SerializeResponse(dataVersion, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var document = JsonDocument.Parse(json); + var root = document.RootElement; + + using (Assert.EnterMultipleScope()) + { + Assert.That(root.GetProperty("@type").GetString(), Is.EqualTo("DataVersion")); + Assert.That(root.GetProperty("@id").GetGuid(), Is.EqualTo(DataVersionIdentifier)); + Assert.That(root.GetProperty("identity").GetProperty("@type").GetString(), Is.EqualTo("DataIdentity")); + Assert.That(root.GetProperty("identity").GetProperty("name").GetString(), Is.EqualTo("the identity")); + Assert.That(root.GetProperty("payload").GetProperty("@type").GetString(), Is.EqualTo("Feature")); + Assert.That(root.GetProperty("payload").GetProperty("@id").GetGuid(), Is.EqualTo(ElementIdentifier)); + } + + var withApiPayload = new DataVersion + { + Id = DataVersionIdentifier, + Payload = new ExternalData { Id = ElementIdentifier, ResourceIdentifier = new Uri("http://www.stariongroup.eu/external") } + }; + + var apiJson = Serialize(stream => this.serializer.SerializeResponse(withApiPayload, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var apiDocument = JsonDocument.Parse(apiJson); + + using (Assert.EnterMultipleScope()) + { + Assert.That(apiDocument.RootElement.GetProperty("payload").GetProperty("@type").GetString(), Is.EqualTo("ExternalData")); + Assert.That(apiDocument.RootElement.GetProperty("payload").GetProperty("resourceIdentifier").GetString(), Is.EqualTo("http://www.stariongroup.eu/external")); + } + + var withoutPayload = new DataVersion { Id = DataVersionIdentifier }; + + var nullPayloadJson = Serialize(stream => this.serializer.SerializeResponse(withoutPayload, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var nullPayloadDocument = JsonDocument.Parse(nullPayloadJson); + + using (Assert.EnterMultipleScope()) + { + Assert.That(nullPayloadDocument.RootElement.GetProperty("payload").ValueKind, Is.EqualTo(JsonValueKind.Null)); + Assert.That(nullPayloadDocument.RootElement.GetProperty("identity").ValueKind, Is.EqualTo(JsonValueKind.Null)); + } + + var commitRequest = new CommitRequest + { + Description = "the commit", + Change = [new DataVersionRequest { Payload = element }] + }; + + var commitJson = Serialize(stream => this.serializer.SerializeRequest(commitRequest, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var commitDocument = JsonDocument.Parse(commitJson); + var change = commitDocument.RootElement.GetProperty("change"); + + using (Assert.EnterMultipleScope()) + { + Assert.That(commitDocument.RootElement.GetProperty("@type").GetString(), Is.EqualTo("Commit")); + Assert.That(change.GetArrayLength(), Is.EqualTo(1)); + Assert.That(change[0].GetProperty("@type").GetString(), Is.EqualTo("DataVersion")); + Assert.That(change[0].GetProperty("payload").GetProperty("@type").GetString(), Is.EqualTo("Feature")); + Assert.That(change[0].GetProperty("payload").GetProperty("@id").GetGuid(), Is.EqualTo(ElementIdentifier)); + } + + var requestWithApiPayload = new DataVersionRequest + { + Payload = new ExternalDataRequest { Id = ElementIdentifier, ResourceIdentifier = new Uri("http://www.stariongroup.eu/external") } + }; + + var requestJson = Serialize(stream => this.serializer.SerializeRequest(requestWithApiPayload, SerializationModeKind.JSON, false, stream, this.jsonWriterOptions)); + + using var requestDocument = JsonDocument.Parse(requestJson); + var requestPayload = requestDocument.RootElement.GetProperty("payload"); + + using (Assert.EnterMultipleScope()) + { + Assert.That(requestDocument.RootElement.GetProperty("@type").GetString(), Is.EqualTo("DataVersion")); + Assert.That(requestPayload.GetProperty("@type").GetString(), Is.EqualTo("ExternalData")); + Assert.That(requestPayload.GetProperty("resourceIdentifier").GetString(), Is.EqualTo("http://www.stariongroup.eu/external")); + } + } + + [Test] + public void VerifySerializeUnsupportedMode() + { + var project = new Project { Id = ProjectIdentifier, Name = "the name" }; + + using var stream = new MemoryStream(); + + Assert.That(() => this.serializer.SerializeResponse(project, SerializationModeKind.JSONLD, false, stream, this.jsonWriterOptions), + Throws.TypeOf()); + } + + private static string Serialize(Action serialize) + { + using var stream = new MemoryStream(); + + serialize(stream); + + return Encoding.UTF8.GetString(stream.ToArray()); + } + } +} diff --git a/SysML2.NET.Serializer.Json/ISerializer.cs b/SysML2.NET.Serializer.Json/ISerializer.cs index 6c9a44b10..11436fb65 100644 --- a/SysML2.NET.Serializer.Json/ISerializer.cs +++ b/SysML2.NET.Serializer.Json/ISerializer.cs @@ -27,6 +27,7 @@ namespace SysML2.NET.Serializer.Json using System.Threading.Tasks; using SysML2.NET.Common; + using SysML2.NET.PSM.DTO; /// /// The purpose of the is to write an and @@ -119,5 +120,93 @@ public interface ISerializer /// The used to cancel the operation /// Task SerializeAsync(IIdentified dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken); + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + void SerializeRequest(IRequest dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions); + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + void SerializeRequest(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions); + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + void SerializeResponse(IResponse dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions); + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + void SerializeResponse(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions); + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + Task SerializeRequestAsync(IRequest dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken); + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + Task SerializeRequestAsync(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken); + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + Task SerializeResponseAsync(IResponse dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken); + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + Task SerializeResponseAsync(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken); } } diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/BranchRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/BranchRequestSerializer.cs new file mode 100644 index 000000000..60c8d3f90 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/BranchRequestSerializer.cs @@ -0,0 +1,111 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class BranchRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not BranchRequest branchRequest) + { + throw new ArgumentException("The object shall be a BranchRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Branch"); + + writer.WriteStartArray("alias"u8); + + if (branchRequest.Alias != null) + { + foreach (var item in branchRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, branchRequest.Description); + + if (branchRequest.Head.HasValue) + { + writer.WriteStartObject("head"u8); + writer.WriteString("@id"u8, branchRequest.Head.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("head"u8); + } + + writer.WriteString("name"u8, branchRequest.Name); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/BranchSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/BranchSerializer.cs new file mode 100644 index 000000000..704b4d2e3 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/BranchSerializer.cs @@ -0,0 +1,132 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class BranchSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Branch branch) + { + throw new ArgumentException("The object shall be a Branch", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Branch"); + + writer.WriteString("@id"u8, branch.Id); + + writer.WriteStartArray("alias"u8); + + if (branch.Alias != null) + { + foreach (var item in branch.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("created"u8, branch.Created); + + if (branch.Deleted.HasValue) + { + writer.WriteString("deleted"u8, branch.Deleted.Value); + } + else + { + writer.WriteNull("deleted"u8); + } + + writer.WriteString("description"u8, branch.Description); + + if (branch.Head.HasValue) + { + writer.WriteStartObject("head"u8); + writer.WriteString("@id"u8, branch.Head.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("head"u8); + } + + writer.WriteString("name"u8, branch.Name); + + writer.WriteStartObject("owningProject"u8); + writer.WriteString("@id"u8, branch.OwningProject); + writer.WriteEndObject(); + + writer.WriteStartObject("referencedCommit"u8); + writer.WriteString("@id"u8, branch.ReferencedCommit); + writer.WriteEndObject(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CommitRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CommitRequestSerializer.cs new file mode 100644 index 000000000..844f0fa99 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CommitRequestSerializer.cs @@ -0,0 +1,112 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class CommitRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not CommitRequest commitRequest) + { + throw new ArgumentException("The object shall be a CommitRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Commit"); + + writer.WriteStartArray("alias"u8); + + if (commitRequest.Alias != null) + { + foreach (var item in commitRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteStartArray("change"u8); + + if (commitRequest.Change != null) + { + foreach (var item in commitRequest.Change) + { + DataVersionRequestSerializer.Serialize(item, writer, serializationModeKind, includeDerivedProperties); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, commitRequest.Description); + + writer.WriteString("name"u8, commitRequest.Name); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CommitSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CommitSerializer.cs new file mode 100644 index 000000000..7a1246f76 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CommitSerializer.cs @@ -0,0 +1,122 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class CommitSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Commit commit) + { + throw new ArgumentException("The object shall be a Commit", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Commit"); + + writer.WriteString("@id"u8, commit.Id); + + writer.WriteStartArray("alias"u8); + + if (commit.Alias != null) + { + foreach (var item in commit.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("created"u8, commit.Created); + + writer.WriteString("description"u8, commit.Description); + + writer.WriteString("name"u8, commit.Name); + + writer.WriteStartObject("owningProject"u8); + writer.WriteString("@id"u8, commit.OwningProject); + writer.WriteEndObject(); + + writer.WriteStartArray("previousCommit"u8); + + if (commit.PreviousCommit != null) + { + foreach (var item in commit.PreviousCommit) + { + writer.WriteStartObject(); + writer.WriteString("@id"u8, item); + writer.WriteEndObject(); + } + } + + writer.WriteEndArray(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CompositeConstraintRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CompositeConstraintRequestSerializer.cs new file mode 100644 index 000000000..5fc1ac5a7 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CompositeConstraintRequestSerializer.cs @@ -0,0 +1,98 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class CompositeConstraintRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not CompositeConstraintRequest compositeConstraintRequest) + { + throw new ArgumentException("The object shall be a CompositeConstraintRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "CompositeConstraint"); + + writer.WriteStartArray("constraint"u8); + + if (compositeConstraintRequest.Constraint != null) + { + foreach (var item in compositeConstraintRequest.Constraint) + { + PsmSerializationDispatcher.Provide(item.GetType())(item, writer, serializationModeKind, includeDerivedProperties); + } + } + + writer.WriteEndArray(); + + writer.WriteString("operator"u8, compositeConstraintRequest.Operator.ToWireValue()); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CompositeConstraintSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CompositeConstraintSerializer.cs new file mode 100644 index 000000000..324e9a164 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/CompositeConstraintSerializer.cs @@ -0,0 +1,98 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class CompositeConstraintSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not CompositeConstraint compositeConstraint) + { + throw new ArgumentException("The object shall be a CompositeConstraint", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "CompositeConstraint"); + + writer.WriteStartArray("constraint"u8); + + if (compositeConstraint.Constraint != null) + { + foreach (var item in compositeConstraint.Constraint) + { + PsmSerializationDispatcher.Provide(item.GetType())(item, writer, serializationModeKind, includeDerivedProperties); + } + } + + writer.WriteEndArray(); + + writer.WriteString("operator"u8, compositeConstraint.Operator.ToWireValue()); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataDifferenceSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataDifferenceSerializer.cs new file mode 100644 index 000000000..655b57f46 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataDifferenceSerializer.cs @@ -0,0 +1,104 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class DataDifferenceSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not DataDifference dataDifference) + { + throw new ArgumentException("The object shall be a DataDifference", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "DataDifference"); + + if (dataDifference.BaseData != null) + { + writer.WritePropertyName("baseData"u8); + DataVersionSerializer.Serialize(dataDifference.BaseData, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("baseData"u8); + } + + if (dataDifference.CompareData != null) + { + writer.WritePropertyName("compareData"u8); + DataVersionSerializer.Serialize(dataDifference.CompareData, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("compareData"u8); + } + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataIdentityRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataIdentityRequestSerializer.cs new file mode 100644 index 000000000..150babab2 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataIdentityRequestSerializer.cs @@ -0,0 +1,102 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class DataIdentityRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not DataIdentityRequest dataIdentityRequest) + { + throw new ArgumentException("The object shall be a DataIdentityRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "DataIdentity"); + + writer.WriteString("@id"u8, dataIdentityRequest.Id); + + writer.WriteStartArray("alias"u8); + + if (dataIdentityRequest.Alias != null) + { + foreach (var item in dataIdentityRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, dataIdentityRequest.Description); + + writer.WriteString("name"u8, dataIdentityRequest.Name); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataIdentitySerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataIdentitySerializer.cs new file mode 100644 index 000000000..bd3678842 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataIdentitySerializer.cs @@ -0,0 +1,102 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class DataIdentitySerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not DataIdentity dataIdentity) + { + throw new ArgumentException("The object shall be a DataIdentity", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "DataIdentity"); + + writer.WriteString("@id"u8, dataIdentity.Id); + + writer.WriteStartArray("alias"u8); + + if (dataIdentity.Alias != null) + { + foreach (var item in dataIdentity.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, dataIdentity.Description); + + writer.WriteString("name"u8, dataIdentity.Name); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataVersionRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataVersionRequestSerializer.cs new file mode 100644 index 000000000..720c3a700 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataVersionRequestSerializer.cs @@ -0,0 +1,120 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class DataVersionRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not DataVersionRequest dataVersionRequest) + { + throw new ArgumentException("The object shall be a DataVersionRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "DataVersion"); + + writer.WriteStartArray("alias"u8); + + if (dataVersionRequest.Alias != null) + { + foreach (var item in dataVersionRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, dataVersionRequest.Description); + + if (dataVersionRequest.Identity != null) + { + writer.WritePropertyName("identity"u8); + DataIdentityRequestSerializer.Serialize(dataVersionRequest.Identity, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("identity"u8); + } + + writer.WriteString("name"u8, dataVersionRequest.Name); + + if (dataVersionRequest.Payload != null) + { + writer.WritePropertyName("payload"u8); + PsmSerializationDispatcher.Provide(dataVersionRequest.Payload.GetType())(dataVersionRequest.Payload, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("payload"u8); + } + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataVersionSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataVersionSerializer.cs new file mode 100644 index 000000000..d6626e911 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/DataVersionSerializer.cs @@ -0,0 +1,122 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class DataVersionSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not DataVersion dataVersion) + { + throw new ArgumentException("The object shall be a DataVersion", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "DataVersion"); + + writer.WriteString("@id"u8, dataVersion.Id); + + writer.WriteStartArray("alias"u8); + + if (dataVersion.Alias != null) + { + foreach (var item in dataVersion.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, dataVersion.Description); + + if (dataVersion.Identity != null) + { + writer.WritePropertyName("identity"u8); + DataIdentitySerializer.Serialize(dataVersion.Identity, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("identity"u8); + } + + writer.WriteString("name"u8, dataVersion.Name); + + if (dataVersion.Payload != null) + { + writer.WritePropertyName("payload"u8); + PsmSerializationDispatcher.Provide(dataVersion.Payload.GetType())(dataVersion.Payload, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("payload"u8); + } + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ErrorSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ErrorSerializer.cs new file mode 100644 index 000000000..64dbda711 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ErrorSerializer.cs @@ -0,0 +1,86 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ErrorSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Error error) + { + throw new ArgumentException("The object shall be a Error", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Error"); + + writer.WriteString("description"u8, error.Description); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalDataRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalDataRequestSerializer.cs new file mode 100644 index 000000000..13f34cad5 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalDataRequestSerializer.cs @@ -0,0 +1,95 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ExternalDataRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ExternalDataRequest externalDataRequest) + { + throw new ArgumentException("The object shall be a ExternalDataRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "ExternalData"); + + if (externalDataRequest.Id.HasValue) + { + writer.WriteString("@id"u8, externalDataRequest.Id.Value); + } + else + { + writer.WriteNull("@id"u8); + } + + writer.WriteString("resourceIdentifier"u8, externalDataRequest.ResourceIdentifier?.ToString()); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalDataSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalDataSerializer.cs new file mode 100644 index 000000000..f08509d33 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalDataSerializer.cs @@ -0,0 +1,88 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ExternalDataSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ExternalData externalData) + { + throw new ArgumentException("The object shall be a ExternalData", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "ExternalData"); + + writer.WriteString("@id"u8, externalData.Id); + + writer.WriteString("resourceIdentifier"u8, externalData.ResourceIdentifier?.ToString()); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalRelationshipRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalRelationshipRequestSerializer.cs new file mode 100644 index 000000000..6ee28e9c8 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalRelationshipRequestSerializer.cs @@ -0,0 +1,119 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ExternalRelationshipRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ExternalRelationshipRequest externalRelationshipRequest) + { + throw new ArgumentException("The object shall be a ExternalRelationshipRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "ExternalRelationship"); + + if (externalRelationshipRequest.Id.HasValue) + { + writer.WriteString("@id"u8, externalRelationshipRequest.Id.Value); + } + else + { + writer.WriteNull("@id"u8); + } + + if (externalRelationshipRequest.ElementEnd.HasValue) + { + writer.WriteStartObject("elementEnd"u8); + writer.WriteString("@id"u8, externalRelationshipRequest.ElementEnd.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("elementEnd"u8); + } + + if (externalRelationshipRequest.ExternalDataEnd.HasValue) + { + writer.WriteStartObject("externalDataEnd"u8); + writer.WriteString("@id"u8, externalRelationshipRequest.ExternalDataEnd.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("externalDataEnd"u8); + } + + writer.WriteString("language"u8, externalRelationshipRequest.Language); + + writer.WriteString("specification"u8, externalRelationshipRequest.Specification); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalRelationshipSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalRelationshipSerializer.cs new file mode 100644 index 000000000..02633cc22 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ExternalRelationshipSerializer.cs @@ -0,0 +1,98 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ExternalRelationshipSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ExternalRelationship externalRelationship) + { + throw new ArgumentException("The object shall be a ExternalRelationship", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "ExternalRelationship"); + + writer.WriteString("@id"u8, externalRelationship.Id); + + writer.WriteStartObject("elementEnd"u8); + writer.WriteString("@id"u8, externalRelationship.ElementEnd); + writer.WriteEndObject(); + + writer.WriteStartObject("externalDataEnd"u8); + writer.WriteString("@id"u8, externalRelationship.ExternalDataEnd); + writer.WriteEndObject(); + + writer.WriteString("language"u8, externalRelationship.Language); + + writer.WriteString("specification"u8, externalRelationship.Specification); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/PrimitiveConstraintRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/PrimitiveConstraintRequestSerializer.cs new file mode 100644 index 000000000..527ae31bc --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/PrimitiveConstraintRequestSerializer.cs @@ -0,0 +1,109 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class PrimitiveConstraintRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not PrimitiveConstraintRequest primitiveConstraintRequest) + { + throw new ArgumentException("The object shall be a PrimitiveConstraintRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "PrimitiveConstraint"); + + if (primitiveConstraintRequest.Inverse.HasValue) + { + writer.WriteBoolean("inverse"u8, primitiveConstraintRequest.Inverse.Value); + } + else + { + writer.WriteNull("inverse"u8); + } + + writer.WriteString("operator"u8, primitiveConstraintRequest.Operator.ToWireValue()); + + writer.WriteString("property"u8, primitiveConstraintRequest.Property); + + writer.WriteStartArray("value"u8); + + if (primitiveConstraintRequest.Value != null) + { + foreach (var item in primitiveConstraintRequest.Value) + { + ConstraintValueWriter.Write(item, writer); + } + } + + writer.WriteEndArray(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/PrimitiveConstraintSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/PrimitiveConstraintSerializer.cs new file mode 100644 index 000000000..951412f28 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/PrimitiveConstraintSerializer.cs @@ -0,0 +1,102 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class PrimitiveConstraintSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not PrimitiveConstraint primitiveConstraint) + { + throw new ArgumentException("The object shall be a PrimitiveConstraint", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "PrimitiveConstraint"); + + writer.WriteBoolean("inverse"u8, primitiveConstraint.Inverse); + + writer.WriteString("operator"u8, primitiveConstraint.Operator.ToWireValue()); + + writer.WriteString("property"u8, primitiveConstraint.Property); + + writer.WriteStartArray("value"u8); + + if (primitiveConstraint.Value != null) + { + foreach (var item in primitiveConstraint.Value) + { + ConstraintValueWriter.Write(item, writer); + } + } + + writer.WriteEndArray(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectRequestSerializer.cs new file mode 100644 index 000000000..b0f5a6578 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectRequestSerializer.cs @@ -0,0 +1,111 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ProjectRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ProjectRequest projectRequest) + { + throw new ArgumentException("The object shall be a ProjectRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Project"); + + writer.WriteStartArray("alias"u8); + + if (projectRequest.Alias != null) + { + foreach (var item in projectRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + if (projectRequest.DefaultBranch.HasValue) + { + writer.WriteStartObject("defaultBranch"u8); + writer.WriteString("@id"u8, projectRequest.DefaultBranch.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("defaultBranch"u8); + } + + writer.WriteString("description"u8, projectRequest.Description); + + writer.WriteString("name"u8, projectRequest.Name); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectSerializer.cs new file mode 100644 index 000000000..89e8c6b04 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectSerializer.cs @@ -0,0 +1,108 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ProjectSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Project project) + { + throw new ArgumentException("The object shall be a Project", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Project"); + + writer.WriteString("@id"u8, project.Id); + + writer.WriteStartArray("alias"u8); + + if (project.Alias != null) + { + foreach (var item in project.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("created"u8, project.Created); + + writer.WriteStartObject("defaultBranch"u8); + writer.WriteString("@id"u8, project.DefaultBranch); + writer.WriteEndObject(); + + writer.WriteString("description"u8, project.Description); + + writer.WriteString("name"u8, project.Name); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectUsageRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectUsageRequestSerializer.cs new file mode 100644 index 000000000..4fb3d5b69 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectUsageRequestSerializer.cs @@ -0,0 +1,115 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ProjectUsageRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ProjectUsageRequest projectUsageRequest) + { + throw new ArgumentException("The object shall be a ProjectUsageRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "ProjectUsage"); + + if (projectUsageRequest.Id.HasValue) + { + writer.WriteString("@id"u8, projectUsageRequest.Id.Value); + } + else + { + writer.WriteNull("@id"u8); + } + + if (projectUsageRequest.UsedCommit.HasValue) + { + writer.WriteStartObject("usedCommit"u8); + writer.WriteString("@id"u8, projectUsageRequest.UsedCommit.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("usedCommit"u8); + } + + if (projectUsageRequest.UsedProject.HasValue) + { + writer.WriteStartObject("usedProject"u8); + writer.WriteString("@id"u8, projectUsageRequest.UsedProject.Value); + writer.WriteEndObject(); + } + else + { + writer.WriteNull("usedProject"u8); + } + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectUsageSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectUsageSerializer.cs new file mode 100644 index 000000000..bf8585582 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectUsageSerializer.cs @@ -0,0 +1,94 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class ProjectUsageSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not ProjectUsage projectUsage) + { + throw new ArgumentException("The object shall be a ProjectUsage", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "ProjectUsage"); + + writer.WriteString("@id"u8, projectUsage.Id); + + writer.WriteStartObject("usedCommit"u8); + writer.WriteString("@id"u8, projectUsage.UsedCommit); + writer.WriteEndObject(); + + writer.WriteStartObject("usedProject"u8); + writer.WriteString("@id"u8, projectUsage.UsedProject); + writer.WriteEndObject(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/QueryRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/QueryRequestSerializer.cs new file mode 100644 index 000000000..28b209fcf --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/QueryRequestSerializer.cs @@ -0,0 +1,122 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class QueryRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not QueryRequest queryRequest) + { + throw new ArgumentException("The object shall be a QueryRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Query"); + + writer.WriteStartArray("alias"u8); + + if (queryRequest.Alias != null) + { + foreach (var item in queryRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, queryRequest.Description); + + writer.WriteString("name"u8, queryRequest.Name); + + writer.WriteStartArray("select"u8); + + if (queryRequest.Select != null) + { + foreach (var item in queryRequest.Select) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + if (queryRequest.Where != null) + { + writer.WritePropertyName("where"u8); + PsmSerializationDispatcher.Provide(queryRequest.Where.GetType())(queryRequest.Where, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("where"u8); + } + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/QuerySerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/QuerySerializer.cs new file mode 100644 index 000000000..6f0e6e57c --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/QuerySerializer.cs @@ -0,0 +1,128 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class QuerySerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Query query) + { + throw new ArgumentException("The object shall be a Query", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Query"); + + writer.WriteString("@id"u8, query.Id); + + writer.WriteStartArray("alias"u8); + + if (query.Alias != null) + { + foreach (var item in query.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, query.Description); + + writer.WriteString("name"u8, query.Name); + + writer.WriteStartObject("owningProject"u8); + writer.WriteString("@id"u8, query.OwningProject); + writer.WriteEndObject(); + + writer.WriteStartArray("select"u8); + + if (query.Select != null) + { + foreach (var item in query.Select) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + if (query.Where != null) + { + writer.WritePropertyName("where"u8); + PsmSerializationDispatcher.Provide(query.Where.GetType())(query.Where, writer, serializationModeKind, includeDerivedProperties); + } + else + { + writer.WriteNull("where"u8); + } + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/SerializationProvider.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/SerializationProvider.cs new file mode 100644 index 000000000..cfa0328fe --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/SerializationProvider.cs @@ -0,0 +1,113 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Collections.Generic; + using System.Text.Json; + + using SysML2.NET.Serializer.Json; + + /// + /// Delegate provider for the appropriate serialization method to serialize a + /// + internal static class SerializationProvider + { + /// + /// Caches the delegate for the + /// that is to be serialized + /// + private static readonly Dictionary> SerializerActionMap = + new Dictionary> + { + { typeof(SysML2.NET.PSM.DTO.Branch), BranchSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.BranchRequest), BranchRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.Commit), CommitSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.CommitRequest), CommitRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.CompositeConstraint), CompositeConstraintSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.CompositeConstraintRequest), CompositeConstraintRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.DataDifference), DataDifferenceSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.DataIdentity), DataIdentitySerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.DataIdentityRequest), DataIdentityRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.DataVersion), DataVersionSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.DataVersionRequest), DataVersionRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.Error), ErrorSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.ExternalData), ExternalDataSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.ExternalDataRequest), ExternalDataRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.ExternalRelationship), ExternalRelationshipSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.ExternalRelationshipRequest), ExternalRelationshipRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.PrimitiveConstraint), PrimitiveConstraintSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.PrimitiveConstraintRequest), PrimitiveConstraintRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.Project), ProjectSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.ProjectRequest), ProjectRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.ProjectUsage), ProjectUsageSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.ProjectUsageRequest), ProjectUsageRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.Query), QuerySerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.QueryRequest), QueryRequestSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.Tag), TagSerializer.Serialize }, + { typeof(SysML2.NET.PSM.DTO.TagRequest), TagRequestSerializer.Serialize }, + }; + + /// + /// Provides the delegate that serializes the specified + /// + /// + /// The that is to be serialized + /// + /// + /// The delegate that serializes the + /// + /// + /// Thrown when the is not supported + /// + internal static Action Provide(Type type) + { + if (!SerializerActionMap.TryGetValue(type, out var action)) + { + throw new NotSupportedException($"The {type.Name} is not supported by the SerializationProvider."); + } + + return action; + } + + /// + /// Asserts whether the specified is supported by the provider + /// + /// + /// The for which support is asserted + /// + /// + /// True when the is supported + /// + internal static bool IsTypeSupported(Type type) + { + return SerializerActionMap.ContainsKey(type); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/TagRequestSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/TagRequestSerializer.cs new file mode 100644 index 000000000..1883145fe --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/TagRequestSerializer.cs @@ -0,0 +1,104 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class TagRequestSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not TagRequest tagRequest) + { + throw new ArgumentException("The object shall be a TagRequest", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Tag"); + + writer.WriteStartArray("alias"u8); + + if (tagRequest.Alias != null) + { + foreach (var item in tagRequest.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("description"u8, tagRequest.Description); + + writer.WriteString("name"u8, tagRequest.Name); + + writer.WriteStartObject("taggedCommit"u8); + writer.WriteString("@id"u8, tagRequest.TaggedCommit); + writer.WriteEndObject(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/TagSerializer.cs b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/TagSerializer.cs new file mode 100644 index 000000000..295e74a41 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/TagSerializer.cs @@ -0,0 +1,125 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + using SysML2.NET.PSM.Enumerations; + using SysML2.NET.Serializer.Json; + + /// + /// The purpose of the is to provide serialization capabilities + /// for the class + /// + internal static class TagSerializer + { + /// + /// Serializes an instance of using an + /// + /// + /// The to serialize + /// + /// + /// The target + /// + /// + /// enumeration specifying what kind of serialization shall be used + /// + /// + /// Asserts that derived properties should also be part of the serialization + /// + /// + /// Thrown when the object is not a + /// + /// + /// Thrown when the serialization mode is not supported + /// + internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + if (obj is not Tag tag) + { + throw new ArgumentException("The object shall be a Tag", nameof(obj)); + } + + if (serializationModeKind != SerializationModeKind.JSON) + { + throw new NotSupportedException($"The {serializationModeKind} serialization mode is not supported"); + } + + writer.WriteStartObject(); + + writer.WriteString("@type"u8, "Tag"); + + writer.WriteString("@id"u8, tag.Id); + + writer.WriteStartArray("alias"u8); + + if (tag.Alias != null) + { + foreach (var item in tag.Alias) + { + writer.WriteStringValue(item); + } + } + + writer.WriteEndArray(); + + writer.WriteString("created"u8, tag.Created); + + if (tag.Deleted.HasValue) + { + writer.WriteString("deleted"u8, tag.Deleted.Value); + } + else + { + writer.WriteNull("deleted"u8); + } + + writer.WriteString("description"u8, tag.Description); + + writer.WriteString("name"u8, tag.Name); + + writer.WriteStartObject("owningProject"u8); + writer.WriteString("@id"u8, tag.OwningProject); + writer.WriteEndObject(); + + writer.WriteStartObject("referencedCommit"u8); + writer.WriteString("@id"u8, tag.ReferencedCommit); + writer.WriteEndObject(); + + writer.WriteStartObject("taggedCommit"u8); + writer.WriteString("@id"u8, tag.TaggedCommit); + writer.WriteEndObject(); + + writer.WriteEndObject(); + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET.Serializer.Json/PSM/ConstraintValueWriter.cs b/SysML2.NET.Serializer.Json/PSM/ConstraintValueWriter.cs new file mode 100644 index 000000000..108bdd550 --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/ConstraintValueWriter.cs @@ -0,0 +1,85 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.PSM.DTO; + + /// + /// The purpose of the is to write a as JSON + /// + /// + /// Each alternative occupies a distinct JSON token type, so no type discriminator is written. + /// + internal static class ConstraintValueWriter + { + /// + /// Writes a using an + /// + /// + /// The to write + /// + /// + /// The target + /// + /// + /// Thrown when the writer is null + /// + internal static void Write(ConstraintValue value, Utf8JsonWriter writer) + { + if (writer is null) + { + throw new ArgumentNullException(nameof(writer)); + } + + switch (value.Kind) + { + case ConstraintValueKind.Boolean: + value.TryGetBoolean(out var booleanValue); + writer.WriteBooleanValue(booleanValue); + break; + + case ConstraintValueKind.Number: + value.TryGetNumber(out var numberValue); + writer.WriteNumberValue(numberValue); + break; + + case ConstraintValueKind.String: + value.TryGetString(out var stringValue); + writer.WriteStringValue(stringValue); + break; + + case ConstraintValueKind.Guid: + value.TryGetGuid(out var guidValue); + writer.WriteStartObject(); + writer.WriteString("@id"u8, guidValue); + writer.WriteEndObject(); + break; + + default: + writer.WriteNullValue(); + break; + } + } + } +} diff --git a/SysML2.NET.Serializer.Json/PSM/PsmSerializationDispatcher.cs b/SysML2.NET.Serializer.Json/PSM/PsmSerializationDispatcher.cs new file mode 100644 index 000000000..7fc51619d --- /dev/null +++ b/SysML2.NET.Serializer.Json/PSM/PsmSerializationDispatcher.cs @@ -0,0 +1,57 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Serializer.Json.PSM +{ + using System; + using System.Text.Json; + + using SysML2.NET.Serializer.Json; + + /// + /// Delegate provider that resolves the serialization method of a value that may be a Systems Modeling API and + /// Services data transfer object or a SysML Core element + /// + /// + /// The Data union admits Element alongside the Systems Modeling API and Services types, so a payload is resolved + /// against both providers. + /// + internal static class PsmSerializationDispatcher + { + /// + /// Provides the delegate that serializes the specified + /// + /// + /// The that is to be serialized + /// + /// + /// The delegate that serializes the + /// + /// + /// Thrown when neither provider supports the + /// + internal static Action Provide(Type type) + { + return SerializationProvider.IsTypeSupported(type) + ? SerializationProvider.Provide(type) + : SysML2.NET.Serializer.Json.Core.DTO.SerializationProvider.Provide(type); + } + } +} diff --git a/SysML2.NET.Serializer.Json/Serializer.cs b/SysML2.NET.Serializer.Json/Serializer.cs index 50c25acdb..9fb0ab404 100644 --- a/SysML2.NET.Serializer.Json/Serializer.cs +++ b/SysML2.NET.Serializer.Json/Serializer.cs @@ -28,9 +28,12 @@ namespace SysML2.NET.Serializer.Json using SysML2.NET.Common; using SysML2.NET.Core.DTO.Root.Elements; + using SysML2.NET.PSM.DTO; using SysML2.NET.Serializer.Json.PIM.DTO; using SysML2.NET.Serializer.Json.Core.DTO; + using PsmSerializationProvider = SysML2.NET.Serializer.Json.PSM.SerializationProvider; + /// /// The purpose of the is to write an and /// as JSON to a @@ -204,5 +207,180 @@ public async Task SerializeAsync(IIdentified dataItem, SerializationModeKind ser await writer.FlushAsync(cancellationToken); } } + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + public void SerializeRequest(IRequest dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions) + { + using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteSingle(dataItem, writer, serializationModeKind, includeDerivedProperties); + } + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + public void SerializeRequest(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions) + { + using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteMany(dataItems, writer, serializationModeKind, includeDerivedProperties); + } + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + public void SerializeResponse(IResponse dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions) + { + using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteSingle(dataItem, writer, serializationModeKind, includeDerivedProperties); + } + + /// + /// Serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + public void SerializeResponse(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions) + { + using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteMany(dataItems, writer, serializationModeKind, includeDerivedProperties); + } + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + public async Task SerializeRequestAsync(IRequest dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken) + { + await using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteSingle(dataItem, writer, serializationModeKind, includeDerivedProperties); + + await writer.FlushAsync(cancellationToken); + } + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + public async Task SerializeRequestAsync(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken) + { + await using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteMany(dataItems, writer, serializationModeKind, includeDerivedProperties); + + await writer.FlushAsync(cancellationToken); + } + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + public async Task SerializeResponseAsync(IResponse dataItem, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken) + { + await using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteSingle(dataItem, writer, serializationModeKind, includeDerivedProperties); + + await writer.FlushAsync(cancellationToken); + } + + /// + /// Asynchronously serialize an as JSON to a target + /// + /// The that shall be serialized. + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + /// The target . + /// The to use. + /// The used to cancel the operation. + /// an awaitable . + public async Task SerializeResponseAsync(IEnumerable dataItems, SerializationModeKind serializationModeKind, bool includeDerivedProperties, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken) + { + await using var writer = new Utf8JsonWriter(stream, jsonWriterOptions); + + WriteMany(dataItems, writer, serializationModeKind, includeDerivedProperties); + + await writer.FlushAsync(cancellationToken); + } + + /// + /// Writes a single Systems Modeling API and Services data transfer object + /// + /// The object that shall be written. + /// The target . + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + private static void WriteSingle(object dataItem, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + var serializationAction = PsmSerializationProvider.Provide(dataItem.GetType()); + + serializationAction(dataItem, writer, serializationModeKind, includeDerivedProperties); + + writer.Flush(); + } + + /// + /// Writes a collection of Systems Modeling API and Services data transfer objects as a JSON array + /// + /// The objects that shall be written. + /// The target . + /// The to use. + /// Asserts that derived properties should also be part of the serialization. + private static void WriteMany(IEnumerable dataItems, Utf8JsonWriter writer, SerializationModeKind serializationModeKind, bool includeDerivedProperties) + { + writer.WriteStartArray(); + + foreach (var dataItem in dataItems) + { + var serializationAction = PsmSerializationProvider.Provide(dataItem.GetType()); + + serializationAction(dataItem, writer, serializationModeKind, includeDerivedProperties); + } + + writer.WriteEndArray(); + + writer.Flush(); + } } } diff --git a/SysML2.NET.Tests/PSM/EnumerationExtensionsTestFixture.cs b/SysML2.NET.Tests/PSM/EnumerationExtensionsTestFixture.cs new file mode 100644 index 000000000..86f9523e2 --- /dev/null +++ b/SysML2.NET.Tests/PSM/EnumerationExtensionsTestFixture.cs @@ -0,0 +1,63 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Tests.PSM +{ + using System; + + using NUnit.Framework; + + using SysML2.NET.PSM.Enumerations; + + [TestFixture] + public class EnumerationExtensionsTestFixture + { + [Test] + public void VerifyToWireValue() + { + using (Assert.EnterMultipleScope()) + { + Assert.That(PrimitiveConstraintOperator.lessthan.ToWireValue(), Is.EqualTo("<")); + Assert.That(PrimitiveConstraintOperator.lessthanorequalto.ToWireValue(), Is.EqualTo("<=")); + Assert.That(PrimitiveConstraintOperator.equalto.ToWireValue(), Is.EqualTo("=")); + Assert.That(PrimitiveConstraintOperator.greaterthan.ToWireValue(), Is.EqualTo(">")); + Assert.That(PrimitiveConstraintOperator.greaterthanorequalto.ToWireValue(), Is.EqualTo(">=")); + Assert.That(PrimitiveConstraintOperator.@in.ToWireValue(), Is.EqualTo("in")); + Assert.That(PrimitiveConstraintOperator.instanceOf.ToWireValue(), Is.EqualTo("instanceOf")); + + Assert.That(PrimitiveConstraintRequestOperator.lessthan.ToWireValue(), Is.EqualTo("<")); + Assert.That(PrimitiveConstraintRequestOperator.instanceOf.ToWireValue(), Is.EqualTo("instanceOf")); + + Assert.That(CompositeConstraintOperator.and.ToWireValue(), Is.EqualTo("and")); + Assert.That(CompositeConstraintOperator.or.ToWireValue(), Is.EqualTo("or")); + Assert.That(CompositeConstraintRequestOperator.and.ToWireValue(), Is.EqualTo("and")); + Assert.That(CompositeConstraintRequestOperator.or.ToWireValue(), Is.EqualTo("or")); + } + + using (Assert.EnterMultipleScope()) + { + Assert.That(() => ((PrimitiveConstraintOperator)999).ToWireValue(), Throws.TypeOf()); + Assert.That(() => ((CompositeConstraintOperator)999).ToWireValue(), Throws.TypeOf()); + Assert.That(() => ((PrimitiveConstraintRequestOperator)999).ToWireValue(), Throws.TypeOf()); + Assert.That(() => ((CompositeConstraintRequestOperator)999).ToWireValue(), Throws.TypeOf()); + } + } + } +} diff --git a/SysML2.NET/Common/IDataRequest.cs b/SysML2.NET/Common/IDataRequest.cs new file mode 100644 index 000000000..4ee874d35 --- /dev/null +++ b/SysML2.NET/Common/IDataRequest.cs @@ -0,0 +1,34 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Common +{ + /// + /// DataRequest represents any entity that can be sent to the Systems Modeling API and Services as the payload of + /// a data version + /// + /// + /// Realized by Element, ExternalDataRequest, ExternalRelationshipRequest and ProjectUsageRequest; it carries no + /// identifier because a request may omit one. + /// + public interface IDataRequest + { + } +} diff --git a/SysML2.NET/Core/Dto/IElement.cs b/SysML2.NET/Core/Dto/IElement.cs index a9c79ef0b..5b30166f4 100644 --- a/SysML2.NET/Core/Dto/IElement.cs +++ b/SysML2.NET/Core/Dto/IElement.cs @@ -25,7 +25,7 @@ namespace SysML2.NET.Core.DTO.Root.Elements /// /// Hand-coded interface /// - public partial interface IElement : IData + public partial interface IElement : IData, IDataRequest { } } \ No newline at end of file diff --git a/SysML2.NET/PSM/AutoGenDto/DataVersion.cs b/SysML2.NET/PSM/AutoGenDto/DataVersion.cs index f6e78f54e..2bc89db5d 100644 --- a/SysML2.NET/PSM/AutoGenDto/DataVersion.cs +++ b/SysML2.NET/PSM/AutoGenDto/DataVersion.cs @@ -69,7 +69,7 @@ public partial class DataVersion : IResponse, SysML2.NET.Common.IIdentified /// /// Gets or sets the payload of the DataVersion /// - public IData Payload { get; set; } + public SysML2.NET.Common.IData Payload { get; set; } } } diff --git a/SysML2.NET/PSM/AutoGenDto/DataVersionRequest.cs b/SysML2.NET/PSM/AutoGenDto/DataVersionRequest.cs index 743403d21..cdef1827c 100644 --- a/SysML2.NET/PSM/AutoGenDto/DataVersionRequest.cs +++ b/SysML2.NET/PSM/AutoGenDto/DataVersionRequest.cs @@ -64,7 +64,7 @@ public partial class DataVersionRequest : IRequest /// /// Gets or sets the payload of the DataVersionRequest /// - public IDataRequest Payload { get; set; } + public SysML2.NET.Common.IDataRequest Payload { get; set; } } } diff --git a/SysML2.NET/PSM/AutoGenDto/ExternalData.cs b/SysML2.NET/PSM/AutoGenDto/ExternalData.cs index 504b48c9a..23e29048b 100644 --- a/SysML2.NET/PSM/AutoGenDto/ExternalData.cs +++ b/SysML2.NET/PSM/AutoGenDto/ExternalData.cs @@ -34,7 +34,7 @@ namespace SysML2.NET.PSM.DTO /// Data transfer object that represents the ExternalData schema of the Systems Modeling API and Services /// [GeneratedCode("SysML2.NET", "latest")] - public partial class ExternalData : IData, IResponse, SysML2.NET.Common.IIdentified + public partial class ExternalData : IResponse, SysML2.NET.Common.IData, SysML2.NET.Common.IIdentified { /// /// The value of the type discriminator of the ExternalData schema diff --git a/SysML2.NET/PSM/AutoGenDto/ExternalDataRequest.cs b/SysML2.NET/PSM/AutoGenDto/ExternalDataRequest.cs index 1fb69500a..6dd87bf2b 100644 --- a/SysML2.NET/PSM/AutoGenDto/ExternalDataRequest.cs +++ b/SysML2.NET/PSM/AutoGenDto/ExternalDataRequest.cs @@ -34,7 +34,7 @@ namespace SysML2.NET.PSM.DTO /// Data transfer object that represents the ExternalDataRequest schema of the Systems Modeling API and Services /// [GeneratedCode("SysML2.NET", "latest")] - public partial class ExternalDataRequest : IDataRequest, IRequest + public partial class ExternalDataRequest : IRequest, SysML2.NET.Common.IDataRequest { /// /// The value of the type discriminator of the ExternalDataRequest schema diff --git a/SysML2.NET/PSM/AutoGenDto/ExternalRelationship.cs b/SysML2.NET/PSM/AutoGenDto/ExternalRelationship.cs index cebb8a772..ba042d0bb 100644 --- a/SysML2.NET/PSM/AutoGenDto/ExternalRelationship.cs +++ b/SysML2.NET/PSM/AutoGenDto/ExternalRelationship.cs @@ -34,7 +34,7 @@ namespace SysML2.NET.PSM.DTO /// Data transfer object that represents the ExternalRelationship schema of the Systems Modeling API and Services /// [GeneratedCode("SysML2.NET", "latest")] - public partial class ExternalRelationship : IData, IResponse, SysML2.NET.Common.IIdentified + public partial class ExternalRelationship : IResponse, SysML2.NET.Common.IData, SysML2.NET.Common.IIdentified { /// /// The value of the type discriminator of the ExternalRelationship schema diff --git a/SysML2.NET/PSM/AutoGenDto/ExternalRelationshipRequest.cs b/SysML2.NET/PSM/AutoGenDto/ExternalRelationshipRequest.cs index a75909c2c..751a7cbf0 100644 --- a/SysML2.NET/PSM/AutoGenDto/ExternalRelationshipRequest.cs +++ b/SysML2.NET/PSM/AutoGenDto/ExternalRelationshipRequest.cs @@ -34,7 +34,7 @@ namespace SysML2.NET.PSM.DTO /// Data transfer object that represents the ExternalRelationshipRequest schema of the Systems Modeling API and Services /// [GeneratedCode("SysML2.NET", "latest")] - public partial class ExternalRelationshipRequest : IDataRequest, IRequest + public partial class ExternalRelationshipRequest : IRequest, SysML2.NET.Common.IDataRequest { /// /// The value of the type discriminator of the ExternalRelationshipRequest schema diff --git a/SysML2.NET/PSM/AutoGenDto/ProjectUsage.cs b/SysML2.NET/PSM/AutoGenDto/ProjectUsage.cs index 74b89941c..706272e54 100644 --- a/SysML2.NET/PSM/AutoGenDto/ProjectUsage.cs +++ b/SysML2.NET/PSM/AutoGenDto/ProjectUsage.cs @@ -34,7 +34,7 @@ namespace SysML2.NET.PSM.DTO /// Data transfer object that represents the ProjectUsage schema of the Systems Modeling API and Services /// [GeneratedCode("SysML2.NET", "latest")] - public partial class ProjectUsage : IData, IResponse, SysML2.NET.Common.IIdentified + public partial class ProjectUsage : IResponse, SysML2.NET.Common.IData, SysML2.NET.Common.IIdentified { /// /// The value of the type discriminator of the ProjectUsage schema diff --git a/SysML2.NET/PSM/AutoGenDto/ProjectUsageRequest.cs b/SysML2.NET/PSM/AutoGenDto/ProjectUsageRequest.cs index fdb78d9df..b42d678bb 100644 --- a/SysML2.NET/PSM/AutoGenDto/ProjectUsageRequest.cs +++ b/SysML2.NET/PSM/AutoGenDto/ProjectUsageRequest.cs @@ -34,7 +34,7 @@ namespace SysML2.NET.PSM.DTO /// Data transfer object that represents the ProjectUsageRequest schema of the Systems Modeling API and Services /// [GeneratedCode("SysML2.NET", "latest")] - public partial class ProjectUsageRequest : IDataRequest, IRequest + public partial class ProjectUsageRequest : IRequest, SysML2.NET.Common.IDataRequest { /// /// The value of the type discriminator of the ProjectUsageRequest schema diff --git a/SysML2.NET/PSM/AutoGenDto/IData.cs b/SysML2.NET/PSM/AutoGenEnum/CompositeConstraintOperatorExtensions.cs similarity index 60% rename from SysML2.NET/PSM/AutoGenDto/IData.cs rename to SysML2.NET/PSM/AutoGenEnum/CompositeConstraintOperatorExtensions.cs index f56bd4368..49c164ea6 100644 --- a/SysML2.NET/PSM/AutoGenDto/IData.cs +++ b/SysML2.NET/PSM/AutoGenEnum/CompositeConstraintOperatorExtensions.cs @@ -1,5 +1,5 @@ // ------------------------------------------------------------------------------------------------- -// +// // // Copyright (C) 2022-2026 Starion Group S.A. // @@ -22,19 +22,32 @@ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- // ------------------------------------------------------------------------------------------------ -namespace SysML2.NET.PSM.DTO +namespace SysML2.NET.PSM.Enumerations { + using System; using System.CodeDom.Compiler; /// - /// Marker interface implemented by the alternatives of the Data schema of the Systems Modeling API and Services + /// Extension methods for the enumeration /// - /// - /// The Data schema admits Element, ExternalData, ExternalRelationship, ProjectUsage - /// [GeneratedCode("SysML2.NET", "latest")] - public partial interface IData : SysML2.NET.Common.IData + public static class CompositeConstraintOperatorExtensions { + /// + /// Queries the value that represents the literal in the Systems Modeling API and Services + /// + /// The subject . + /// The value as it appears on the wire. + /// Thrown when the literal is not known. + public static string ToWireValue(this CompositeConstraintOperator value) + { + return value switch + { + CompositeConstraintOperator.and => "and", + CompositeConstraintOperator.or => "or", + _ => throw new ArgumentOutOfRangeException(nameof(value)) + }; + } } } diff --git a/SysML2.NET/PSM/AutoGenDto/IDataRequest.cs b/SysML2.NET/PSM/AutoGenEnum/CompositeConstraintRequestOperatorExtensions.cs similarity index 58% rename from SysML2.NET/PSM/AutoGenDto/IDataRequest.cs rename to SysML2.NET/PSM/AutoGenEnum/CompositeConstraintRequestOperatorExtensions.cs index 9414eb95f..d8aedb404 100644 --- a/SysML2.NET/PSM/AutoGenDto/IDataRequest.cs +++ b/SysML2.NET/PSM/AutoGenEnum/CompositeConstraintRequestOperatorExtensions.cs @@ -1,5 +1,5 @@ // ------------------------------------------------------------------------------------------------- -// +// // // Copyright (C) 2022-2026 Starion Group S.A. // @@ -22,19 +22,32 @@ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- // ------------------------------------------------------------------------------------------------ -namespace SysML2.NET.PSM.DTO +namespace SysML2.NET.PSM.Enumerations { + using System; using System.CodeDom.Compiler; /// - /// Marker interface implemented by the alternatives of the DataRequest schema of the Systems Modeling API and Services + /// Extension methods for the enumeration /// - /// - /// The DataRequest schema admits ElementRequest, ExternalDataRequest, ExternalRelationshipRequest, ProjectUsageRequest - /// [GeneratedCode("SysML2.NET", "latest")] - public partial interface IDataRequest + public static class CompositeConstraintRequestOperatorExtensions { + /// + /// Queries the value that represents the literal in the Systems Modeling API and Services + /// + /// The subject . + /// The value as it appears on the wire. + /// Thrown when the literal is not known. + public static string ToWireValue(this CompositeConstraintRequestOperator value) + { + return value switch + { + CompositeConstraintRequestOperator.and => "and", + CompositeConstraintRequestOperator.or => "or", + _ => throw new ArgumentOutOfRangeException(nameof(value)) + }; + } } } diff --git a/SysML2.NET/PSM/AutoGenEnum/PrimitiveConstraintOperatorExtensions.cs b/SysML2.NET/PSM/AutoGenEnum/PrimitiveConstraintOperatorExtensions.cs new file mode 100644 index 000000000..3d8457e9b --- /dev/null +++ b/SysML2.NET/PSM/AutoGenEnum/PrimitiveConstraintOperatorExtensions.cs @@ -0,0 +1,61 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.PSM.Enumerations +{ + using System; + using System.CodeDom.Compiler; + + /// + /// Extension methods for the enumeration + /// + [GeneratedCode("SysML2.NET", "latest")] + public static class PrimitiveConstraintOperatorExtensions + { + /// + /// Queries the value that represents the literal in the Systems Modeling API and Services + /// + /// The subject . + /// The value as it appears on the wire. + /// Thrown when the literal is not known. + public static string ToWireValue(this PrimitiveConstraintOperator value) + { + return value switch + { + PrimitiveConstraintOperator.lessthan => "<", + PrimitiveConstraintOperator.lessthanorequalto => "<=", + PrimitiveConstraintOperator.equalto => "=", + PrimitiveConstraintOperator.greaterthan => ">", + PrimitiveConstraintOperator.greaterthanorequalto => ">=", + PrimitiveConstraintOperator.@in => "in", + PrimitiveConstraintOperator.instanceOf => "instanceOf", + _ => throw new ArgumentOutOfRangeException(nameof(value)) + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/SysML2.NET/PSM/AutoGenEnum/PrimitiveConstraintRequestOperatorExtensions.cs b/SysML2.NET/PSM/AutoGenEnum/PrimitiveConstraintRequestOperatorExtensions.cs new file mode 100644 index 000000000..6f9504512 --- /dev/null +++ b/SysML2.NET/PSM/AutoGenEnum/PrimitiveConstraintRequestOperatorExtensions.cs @@ -0,0 +1,61 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.PSM.Enumerations +{ + using System; + using System.CodeDom.Compiler; + + /// + /// Extension methods for the enumeration + /// + [GeneratedCode("SysML2.NET", "latest")] + public static class PrimitiveConstraintRequestOperatorExtensions + { + /// + /// Queries the value that represents the literal in the Systems Modeling API and Services + /// + /// The subject . + /// The value as it appears on the wire. + /// Thrown when the literal is not known. + public static string ToWireValue(this PrimitiveConstraintRequestOperator value) + { + return value switch + { + PrimitiveConstraintRequestOperator.lessthan => "<", + PrimitiveConstraintRequestOperator.lessthanorequalto => "<=", + PrimitiveConstraintRequestOperator.equalto => "=", + PrimitiveConstraintRequestOperator.greaterthan => ">", + PrimitiveConstraintRequestOperator.greaterthanorequalto => ">=", + PrimitiveConstraintRequestOperator.@in => "in", + PrimitiveConstraintRequestOperator.instanceOf => "instanceOf", + _ => throw new ArgumentOutOfRangeException(nameof(value)) + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------