diff --git a/src/AasxServerStandardBib/Interfaces/ISubmodelService.cs b/src/AasxServerStandardBib/Interfaces/ISubmodelService.cs index 1df444324..b9aa31778 100644 --- a/src/AasxServerStandardBib/Interfaces/ISubmodelService.cs +++ b/src/AasxServerStandardBib/Interfaces/ISubmodelService.cs @@ -25,7 +25,7 @@ public interface ISubmodelService void DeleteSubmodelById(string submodelIdentifier); void DeleteSubmodelElementByPath(string submodelIdentifier, string idShortPath); List GetAllSubmodelElements(string submodelIdentifier); - List GetAllSubmodels(); + List GetAllSubmodels(IReference reqSemanticId = null, string idShort = null); string GetFileByPath(string submodelIdentifier, string idShortPath, out byte[] byteArray, out long fileSize); ISubmodel GetSubmodelById(string submodelIdentifier); ISubmodelElement GetSubmodelElementByPath(string submodelIdentifier, string idShortPath); diff --git a/src/AasxServerStandardBib/Services/SubmodelService.cs b/src/AasxServerStandardBib/Services/SubmodelService.cs index 84877162a..6a5e26fa7 100644 --- a/src/AasxServerStandardBib/Services/SubmodelService.cs +++ b/src/AasxServerStandardBib/Services/SubmodelService.cs @@ -16,10 +16,12 @@ using AasxServerStandardBib.Interfaces; using AasxServerStandardBib.Logging; using AasxServerStandardBib.Transformers; +using AdminShellNS.Extensions; using Extensions; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -488,7 +490,35 @@ public void ReplaceSubmodelElementByPath(string submodelIdentifier, string idSho } } - public List GetAllSubmodels() => _packageEnvService.GetAllSubmodels(); + public List GetAllSubmodels(IReference reqSemanticId = null, string idShort = null) + { + var output = _packageEnvService.GetAllSubmodels(); + + if(!output.IsNullOrEmpty()) + { + if (!string.IsNullOrEmpty(idShort)) + { + _logger.LogDebug($"Filtering Submodels with idShort {idShort}."); + output = output.Where(s => s.IdShort.Equals(idShort)).ToList(); + if (output.IsNullOrEmpty()) + { + _logger.LogInformation($"No Submodels with idShort {idShort} found."); + } + } + + if(reqSemanticId != null) + { + _logger.LogDebug($"Filtering Submodels with requested Semnatic Id."); + output = output.Where(s => s.SemanticId != null && s.SemanticId.Matches(reqSemanticId)).ToList(); + if (output.IsNullOrEmpty()) + { + _logger.LogInformation($"No Submodels with requested semanticId found."); + } + } + } + + return output; + } public ISubmodel CreateSubmodel(ISubmodel newSubmodel, string aasIdentifier) { diff --git a/src/IO.Swagger.Lib.V3.Tests/Controllers/DescriptionAPIApiControllerTests.cs b/src/IO.Swagger.Lib.V3.Tests/Controllers/DescriptionAPIApiControllerTests.cs index 56f5dc046..07b76f256 100644 --- a/src/IO.Swagger.Lib.V3.Tests/Controllers/DescriptionAPIApiControllerTests.cs +++ b/src/IO.Swagger.Lib.V3.Tests/Controllers/DescriptionAPIApiControllerTests.cs @@ -31,7 +31,7 @@ public void GetDescription_ShouldReturn200WithServiceDescription() var mockServiceDescription = new Mock(); var expectedServiceDescription = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.AasxFileServerServiceSpecificationSSP001, ServiceDescription.ServiceProfiles.SubmodelRepositoryServiceSpecificationSSP001, diff --git a/src/IO.Swagger.Lib.V3.Tests/Models/ServiceDescriptionTests.cs b/src/IO.Swagger.Lib.V3.Tests/Models/ServiceDescriptionTests.cs index 7bf156f63..a99b176da 100644 --- a/src/IO.Swagger.Lib.V3.Tests/Models/ServiceDescriptionTests.cs +++ b/src/IO.Swagger.Lib.V3.Tests/Models/ServiceDescriptionTests.cs @@ -25,7 +25,7 @@ public void ToString_ShouldReturnFormattedString() // Arrange var serviceDescription = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 } @@ -45,7 +45,7 @@ public void ToJson_ShouldReturnIndentedJsonString() // Arrange var serviceDescription = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 } @@ -66,7 +66,7 @@ public void Equals_WithSameObject_ShouldReturnTrue() // Arrange var serviceDescription = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 } @@ -88,8 +88,8 @@ public void Equals_WithEqualObject_ShouldReturnTrue() ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 }; - var serviceDescription1 = new ServiceDescription { Profiles = profiles }; - var serviceDescription2 = new ServiceDescription { Profiles = profiles }; + var serviceDescription1 = new ServiceDescription { profiles = profiles }; + var serviceDescription2 = new ServiceDescription { profiles = profiles }; // Act var result = serviceDescription1.Equals(serviceDescription2); @@ -104,7 +104,7 @@ public void Equals_WithDifferentObject_ShouldReturnFalse() // Arrange var serviceDescription1 = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 } @@ -112,7 +112,7 @@ public void Equals_WithDifferentObject_ShouldReturnFalse() var serviceDescription2 = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.AssetAdministrationShellRepositoryServiceSpecificationSSP001 } @@ -134,7 +134,7 @@ public void GetHashCode_ShouldReturnCorrectHashCode() ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 }; - var serviceDescription = new ServiceDescription { Profiles = profiles }; + var serviceDescription = new ServiceDescription { profiles = profiles }; var expectedHashCode = 41; expectedHashCode = (expectedHashCode * 59) + profiles.GetHashCode(); @@ -154,8 +154,8 @@ public void OperatorEquals_WithEqualObjects_ShouldReturnTrue() ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 }; - var serviceDescription1 = new ServiceDescription { Profiles = profiles }; - var serviceDescription2 = new ServiceDescription { Profiles = profiles }; + var serviceDescription1 = new ServiceDescription { profiles = profiles }; + var serviceDescription2 = new ServiceDescription { profiles = profiles }; // Act var result = serviceDescription1 == serviceDescription2; @@ -170,7 +170,7 @@ public void OperatorNotEquals_WithDifferentObjects_ShouldReturnTrue() // Arrange var serviceDescription1 = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001 } @@ -178,7 +178,7 @@ public void OperatorNotEquals_WithDifferentObjects_ShouldReturnTrue() var serviceDescription2 = new ServiceDescription { - Profiles = new List + profiles = new List { ServiceDescription.ServiceProfiles.SubmodelServiceSpecificationSSP002 } diff --git a/src/IO.Swagger.Lib.V3.Tests/Services/GenerateSerializationServiceTests.cs b/src/IO.Swagger.Lib.V3.Tests/Services/GenerateSerializationServiceTests.cs index 6ca963502..3ce7184a0 100644 --- a/src/IO.Swagger.Lib.V3.Tests/Services/GenerateSerializationServiceTests.cs +++ b/src/IO.Swagger.Lib.V3.Tests/Services/GenerateSerializationServiceTests.cs @@ -61,7 +61,7 @@ public void GenerateSerializationByIds_ShouldReturnEmptyEnvironment_WhenNoIdsPro { // Arrange _mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny?>(), It.IsAny())).Returns([]); - _mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([]); + _mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny(), It.IsAny())).Returns([]); // Act var result = _service.GenerateSerializationByIds(); @@ -80,7 +80,7 @@ public void GenerateSerializationByIds_ShouldFetchAASs_WhenAasIdsProvided() mockAas.SetupGet(x => x.Id).Returns(aasId); _mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny?>(), It.IsAny())).Returns([mockAas.Object]); - _mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([]); + _mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny(), It.IsAny())).Returns([]); // Act var result = _service.GenerateSerializationByIds(new List {aasId}); @@ -99,7 +99,7 @@ public void GenerateSerializationByIds_ShouldFetchSubmodels_WhenSubmodelIdsProvi mockSubmodel.SetupGet(x => x.Id).Returns(submodelId); _mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny?>(), It.IsAny())).Returns([]); - _mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([mockSubmodel.Object]); + _mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny(), It.IsAny())).Returns([mockSubmodel.Object]); // Act var result = _service.GenerateSerializationByIds(null, new List {submodelId}); @@ -123,7 +123,7 @@ public void GenerateSerializationByIds_ShouldFetchAASsAndSubmodels_WhenBothIdsPr mockSubmodel.SetupGet(x => x.Id).Returns(submodelId); _mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny?>(), It.IsAny())).Returns([mockAas.Object]); - _mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([mockSubmodel.Object]); + _mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny(), It.IsAny())).Returns([mockSubmodel.Object]); // Act var result = _service.GenerateSerializationByIds(new List {aasId}, new List {submodelId}); diff --git a/src/IO.Swagger.Lib.V3/Controllers/DescriptionAPIApi.cs b/src/IO.Swagger.Lib.V3/Controllers/DescriptionAPIApi.cs index 590ecfb31..731382d9e 100644 --- a/src/IO.Swagger.Lib.V3/Controllers/DescriptionAPIApi.cs +++ b/src/IO.Swagger.Lib.V3/Controllers/DescriptionAPIApi.cs @@ -55,7 +55,7 @@ public class DescriptionAPIApiController : ControllerBase public virtual IActionResult GetDescription() { var output = new ServiceDescription(); - _serviceDescription.Profiles = new List + _serviceDescription.profiles = new List { ServiceProfiles.AasxFileServerServiceSpecificationSSP001, ServiceProfiles.SubmodelRepositoryServiceSpecificationSSP001, diff --git a/src/IO.Swagger.Lib.V3/Controllers/SerializationAPIApi.cs b/src/IO.Swagger.Lib.V3/Controllers/SerializationAPIApi.cs index 1c6d82556..7bae2b331 100644 --- a/src/IO.Swagger.Lib.V3/Controllers/SerializationAPIApi.cs +++ b/src/IO.Swagger.Lib.V3/Controllers/SerializationAPIApi.cs @@ -77,15 +77,7 @@ public SerializationAPIApiController(IAppLogger l public virtual IActionResult GenerateSerializationByIds([FromQuery] List? aasIds, [FromQuery] List? submodelIds, [FromQuery] bool? includeConceptDescriptions) { - if (aasIds == null) - { - throw new NotAllowed($"Cannot proceed as {nameof(aasIds)} is null"); - } - - if (submodelIds == null) - { - throw new NotAllowed($"Cannot proceed as {nameof(submodelIds)} is null"); - } + _logger.LogDebug($"Received a request an appropriate serialization"); var decodedAasIds = aasIds.Select(aasId => _decoderService.Decode("aasIdentifier", aasId)).ToList(); diff --git a/src/IO.Swagger.Lib.V3/Controllers/SubmodelRepositoryAPIApi.cs b/src/IO.Swagger.Lib.V3/Controllers/SubmodelRepositoryAPIApi.cs index 5f31f2538..93ec53612 100644 --- a/src/IO.Swagger.Lib.V3/Controllers/SubmodelRepositoryAPIApi.cs +++ b/src/IO.Swagger.Lib.V3/Controllers/SubmodelRepositoryAPIApi.cs @@ -474,16 +474,13 @@ public virtual IActionResult GetAllSubmodelElementsMetadataSubmodelRepo([FromRou [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] public virtual IActionResult GetAllSubmodelElementsPathSubmodelRepo([FromRoute][Required]string submodelIdentifier, - [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string? level, - [FromQuery] string? diff) - { + [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string? level, [FromQuery] string? diff) + { + //Validate level and extent + var levelEnum = _validateModifierService.ValidateLevel(level); + var decodedSubmodelIdentifier = _decoderService.Decode($"submodelIdentifier", submodelIdentifier); - if (decodedSubmodelIdentifier == null) - { - throw new NotAllowed($"Decoding {submodelIdentifier} returned null"); - } - _logger.LogDebug($"Received request to get all the submodel elements from the submodel with id {decodedSubmodelIdentifier}"); if (!Program.noSecurity) { @@ -513,10 +510,11 @@ public virtual IActionResult GetAllSubmodelElementsPathSubmodelRepo([FromRoute][ else filtered = submodelElementList; - // TODO (jtikekar, 2023-09-04): pagination and modifier - // TODO (jtikekar, 2023-09-04): not complete implemented - var output = _pathModifierService.ToIdShortPath(filtered); - return new ObjectResult(output); + var smePaginated = _paginationService.GetPaginatedList(filtered, new PaginationParameters(cursor, limit)); + var smeLevelList = _levelExtentModifierService.ApplyLevelExtent(smePaginated.result ?? [], levelEnum); + var smePathList = _pathModifierService.ToIdShortPath(smeLevelList.ConvertAll(sme => (ISubmodelElement)sme)); + var output = new PathPagedResult { result = smePathList, paging_metadata = smePaginated.paging_metadata }; + return new ObjectResult(output); } /// @@ -675,9 +673,7 @@ public virtual IActionResult GetAllSubmodelElementsValueOnlySubmodelRepo([FromRo [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllSubmodels([FromQuery][StringLength(3072, MinimumLength=1)] string? semanticId, [FromQuery]string? idShort, - [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string level, - [FromQuery]string extent) + public virtual IActionResult GetAllSubmodels([FromQuery][StringLength(3072, MinimumLength=1)] string? semanticId, [FromQuery]string? idShort, [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string? level, [FromQuery]string? extent) { //Validate level and extent var levelEnum = _validateModifierService.ValidateLevel(level); @@ -686,17 +682,7 @@ public virtual IActionResult GetAllSubmodels([FromQuery][StringLength(3072, Mini var reqSemanticId = _jsonQueryDeserializer.DeserializeReference("semanticId", semanticId); - var submodelList = new List(); - - if (reqSemanticId != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsBySemanticId(reqSemanticId)); - } - - if (idShort != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsByIdShort(idShort)); - } + var submodelList = _submodelService.GetAllSubmodels(reqSemanticId, idShort); var submodelsPagedList = _paginationService.GetPaginatedList(submodelList, new PaginationParameters(cursor, limit)); var smLevelList = _levelExtentModifierService.ApplyLevelExtent(submodelsPagedList.result, levelEnum, extentEnum); @@ -728,24 +714,13 @@ public virtual IActionResult GetAllSubmodels([FromQuery][StringLength(3072, Mini [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllSubmodelsMetadata([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, - [FromQuery]int? limit, [FromQuery]string? cursor) + public virtual IActionResult GetAllSubmodelsMetadata([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, [FromQuery]int? limit, [FromQuery]string? cursor) { _logger.LogInformation($"Received request to get the metadata of all the submodels."); var reqSemanticId = _jsonQueryDeserializer.DeserializeReference("semanticId", semanticId); - var submodelList = new List(); - - if (reqSemanticId != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsBySemanticId(reqSemanticId)); - } - - if (idShort != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsByIdShort(idShort)); - } + var submodelList = _submodelService.GetAllSubmodels(reqSemanticId, idShort); var submodelPagedList = _paginationService.GetPaginatedList(submodelList, new PaginationParameters(cursor, limit)); var smMetadataList = _mappingService.Map(submodelPagedList.result, "metadata"); @@ -777,8 +752,7 @@ public virtual IActionResult GetAllSubmodelsMetadata([FromQuery][StringLength(30 [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllSubmodelsPath([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, - [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string level) + public virtual IActionResult GetAllSubmodelsPath([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string? level) { //Validate level and extent var levelEnum = _validateModifierService.ValidateLevel(level); @@ -786,21 +760,10 @@ public virtual IActionResult GetAllSubmodelsPath([FromQuery][StringLength(3072, var reqSemanticId = _jsonQueryDeserializer.DeserializeReference("semanticId", semanticId); - var submodelList = new List(); - - if (reqSemanticId != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsBySemanticId(reqSemanticId)); - } - - if (idShort != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsByIdShort(idShort)); - } + var submodelList = _submodelService.GetAllSubmodels(reqSemanticId, idShort); var submodelPagedList = _paginationService.GetPaginatedList(submodelList, new PaginationParameters(cursor, limit)); var submodelLevelList = _levelExtentModifierService.ApplyLevelExtent(submodelPagedList.result, levelEnum); - // TODO (jtikekar, 2023-09-04): @Andreas, what if the first element is property, where path is not applicable var submodelsPath = _pathModifierService.ToIdShortPath(submodelLevelList.ConvertAll(sm => (ISubmodel)sm)); var output = new PathPagedResult() {result = submodelsPath, paging_metadata = submodelPagedList.paging_metadata}; return new ObjectResult(output); @@ -830,23 +793,12 @@ public virtual IActionResult GetAllSubmodelsPath([FromQuery][StringLength(3072, [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllSubmodelsReference([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, - [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string level) + public virtual IActionResult GetAllSubmodelsReference([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string? level) { _logger.LogInformation($"Received a request to get all the submodels."); var reqSemanticId = _jsonQueryDeserializer.DeserializeReference("semanticId", semanticId); - var submodelList = new List(); - - if (reqSemanticId != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsBySemanticId(reqSemanticId)); - } - - if (idShort != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsByIdShort(idShort)); - } + var submodelList = _submodelService.GetAllSubmodels(reqSemanticId, idShort); var submodelsPagedList = _paginationService.GetPaginatedList(submodelList, new PaginationParameters(cursor, limit)); var smReferences = _referenceModifierService.GetReferenceResult(submodelsPagedList.result.ConvertAll(sm => (IReferable)sm)); @@ -881,9 +833,7 @@ public virtual IActionResult GetAllSubmodelsReference([FromQuery][StringLength(3 [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllSubmodelsValueOnly([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, - [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string level, - [FromQuery]string extent) + public virtual IActionResult GetAllSubmodelsValueOnly([FromQuery][StringLength(3072, MinimumLength=1)]string? semanticId, [FromQuery]string? idShort, [FromQuery]int? limit, [FromQuery]string? cursor, [FromQuery]string level, [FromQuery]string extent) { //Validate level and extent var levelEnum = _validateModifierService.ValidateLevel(level); @@ -892,17 +842,7 @@ public virtual IActionResult GetAllSubmodelsValueOnly([FromQuery][StringLength(3 var reqSemanticId = _jsonQueryDeserializer.DeserializeReference("semanticId", semanticId); - var submodelList = new List(); - - if (reqSemanticId != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsBySemanticId(reqSemanticId)); - } - - if (idShort != null) - { - submodelList.AddRange(_adminShellPackageEnvironmentService.GetSubmodelsByIdShort(idShort)); - } + var submodelList = _submodelService.GetAllSubmodels(reqSemanticId, idShort); var submodelsPagedList = _paginationService.GetPaginatedList(submodelList, new PaginationParameters(cursor, limit)); var submodelLevelList = _levelExtentModifierService.ApplyLevelExtent(submodelsPagedList.result, levelEnum, extentEnum); diff --git a/src/IO.Swagger.Lib.V3/Interfaces/IPathModifierService.cs b/src/IO.Swagger.Lib.V3/Interfaces/IPathModifierService.cs index 66d6e0e8c..dd357c1bb 100644 --- a/src/IO.Swagger.Lib.V3/Interfaces/IPathModifierService.cs +++ b/src/IO.Swagger.Lib.V3/Interfaces/IPathModifierService.cs @@ -32,12 +32,13 @@ public interface IPathModifierService /// /// The list of submodels to transform. /// A list of lists of strings representing the transformed paths. - List> ToIdShortPath(List submodelList); + List ToIdShortPath(List submodelList); /// /// Transforms the paths of a list of submodel elements into short ID paths. /// /// The list of submodel elements to transform. /// A list of lists of strings representing the transformed paths. - List> ToIdShortPath(List submodelElementList); + //List> ToIdShortPath(List submodelElementList); + List ToIdShortPath(List submodelElementList); } diff --git a/src/IO.Swagger.Lib.V3/Models/IServiceDescription.cs b/src/IO.Swagger.Lib.V3/Models/IServiceDescription.cs index 6270c6e6d..154d251fe 100644 --- a/src/IO.Swagger.Lib.V3/Models/IServiceDescription.cs +++ b/src/IO.Swagger.Lib.V3/Models/IServiceDescription.cs @@ -23,7 +23,7 @@ public interface IServiceDescription /// /// Gets or Sets Profiles /// - List? Profiles { get; set; } + List? profiles { get; set; } /// /// Returns the string presentation of the object diff --git a/src/IO.Swagger.Lib.V3/Models/PathPagedResult.cs b/src/IO.Swagger.Lib.V3/Models/PathPagedResult.cs index a1809305c..5f5cb2622 100644 --- a/src/IO.Swagger.Lib.V3/Models/PathPagedResult.cs +++ b/src/IO.Swagger.Lib.V3/Models/PathPagedResult.cs @@ -18,7 +18,7 @@ namespace IO.Swagger.Lib.V3.Models { public class PathPagedResult { - public List>? result { get; set; } + public List? result { get; set; } public PagedResultPagingMetadata? paging_metadata { get; set; } } diff --git a/src/IO.Swagger.Lib.V3/Models/ServiceDescription.cs b/src/IO.Swagger.Lib.V3/Models/ServiceDescription.cs index 1c35f2deb..8615b935c 100644 --- a/src/IO.Swagger.Lib.V3/Models/ServiceDescription.cs +++ b/src/IO.Swagger.Lib.V3/Models/ServiceDescription.cs @@ -39,14 +39,14 @@ public partial class ServiceDescription : IEquatable, IServi { /// [DataMember(Name = "profiles")] - public List? Profiles { get; set; } + public List? profiles { get; set; } /// public override string ToString() { var sb = new StringBuilder(); sb.Append("class ServiceDescription {\n"); - sb.Append(" Profiles: ").Append(Profiles).Append('\n'); + sb.Append(" Profiles: ").Append(profiles).Append('\n'); sb.Append("}\n"); return sb.ToString(); } @@ -56,12 +56,11 @@ public override string ToString() public string ToJson() => JsonSerializer.Serialize(this, Options); private static readonly JsonSerializerOptions Options = new() - { - WriteIndented = true, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - //Converters = {new JsonStringEnumConverter()} - Converters = {new ServiceProfileEnumValueConverter()} - }; + { + WriteIndented = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + Converters = { new ServiceProfileEnumValueConverter() } + }; /// @@ -95,9 +94,9 @@ public bool Equals(ServiceDescription? other) } return - other.Profiles != null && (Profiles == other.Profiles || - (Profiles != null && - Profiles.SequenceEqual(other.Profiles))); + other.profiles != null && (profiles == other.profiles || + (profiles != null && + profiles.SequenceEqual(other.profiles))); } @@ -108,9 +107,9 @@ public override int GetHashCode() { var hashCode = 41; // Suitable nullity checks etc., of course :) - if (Profiles != null) + if (profiles != null) { - hashCode = (hashCode * 59) + Profiles.GetHashCode(); + hashCode = (hashCode * 59) + profiles.GetHashCode(); } return hashCode; diff --git a/src/IO.Swagger.Lib.V3/SerializationModifiers/PathModifier/PathTransformer.cs b/src/IO.Swagger.Lib.V3/SerializationModifiers/PathModifier/PathTransformer.cs index 30062e6c0..6b3786a5f 100644 --- a/src/IO.Swagger.Lib.V3/SerializationModifiers/PathModifier/PathTransformer.cs +++ b/src/IO.Swagger.Lib.V3/SerializationModifiers/PathModifier/PathTransformer.cs @@ -231,7 +231,9 @@ public List TransformMultiLanguageProperty(IMultiLanguageProperty that, public List TransformOperation(IOperation that, PathModifierContext context) { - if (context.IdShortPaths.Count == 0 || string.IsNullOrEmpty(context.ParentPath)) + if (context.IsRoot && !context.IsGetAllSmes) + throw new InvalidSerializationModifierException("Path", that.GetType().Name); + if (string.IsNullOrEmpty(context.ParentPath)) { context.IdShortPaths.Add(that.IdShort); } @@ -239,38 +241,6 @@ public List TransformOperation(IOperation that, PathModifierContext cont { context.IdShortPaths.Add($"{context.ParentPath}.{that.IdShort}"); } - - var currentParentPath = string.IsNullOrEmpty(context.ParentPath) ? that.IdShort : $"{context.ParentPath}.{that.IdShort}"; - if (that.InputVariables != null) - { - foreach (var element in that.InputVariables) - { - context.IsRoot = false; - context.ParentPath = currentParentPath; - Transform(element, context); - } - } - - if (that.OutputVariables != null) - { - foreach (var element in that.OutputVariables) - { - context.IsRoot = false; - context.ParentPath = currentParentPath; - Transform(element, context); - } - } - - if (that.InoutputVariables != null) - { - foreach (var element in that.InoutputVariables) - { - context.IsRoot = false; - context.ParentPath = currentParentPath; - Transform(element, context); - } - } - return context.IdShortPaths; } diff --git a/src/IO.Swagger.Lib.V3/Services/PathModifierService.cs b/src/IO.Swagger.Lib.V3/Services/PathModifierService.cs index ddae0cde7..4b3f7dc6d 100644 --- a/src/IO.Swagger.Lib.V3/Services/PathModifierService.cs +++ b/src/IO.Swagger.Lib.V3/Services/PathModifierService.cs @@ -14,6 +14,7 @@ using IO.Swagger.Lib.V3.Interfaces; using IO.Swagger.Lib.V3.SerializationModifiers.PathModifier; using System.Collections.Generic; +using System.Linq; namespace IO.Swagger.Lib.V3.Services { @@ -30,29 +31,29 @@ public List ToIdShortPath(IClass? that) return _pathTransformer.Transform(that, context); } - public List> ToIdShortPath(List submodelList) + public List ToIdShortPath(List submodelList) { - var output = new List>(); + var output = new List(); foreach (var submodel in submodelList) { var context = new PathModifierContext(); var path = _pathTransformer.Transform(submodel, context); - output.Add(path); + output.AddRange(path); } return output; } - public List> ToIdShortPath(List submodelElementList) + public List ToIdShortPath(List submodelElementList) { - var output = new List>(); - + //var output = new List>(); + var output = new List(); foreach (var submodelElement in submodelElementList) { var context = new PathModifierContext(isGetAllSmes: true); var path = _pathTransformer.Transform(submodelElement, context); - output.Add(path); + output.AddRange(path); } return output;