eclipse-aaspe / package-explorer

AASX Package Explorer
Other
63 stars 19 forks source link

[BUG] expects an integer as server response when a new aasx file is added to a file repository #220

Open impact-merlinzerbe opened 5 months ago

impact-merlinzerbe commented 5 months ago

Describe the bug

The package explorer tries to parse the response of a PostAASXPackage operation as an integer which conflicts the specification:

https://github.com/eclipse-aaspe/package-explorer/blob/423f03f50f51749329a5259eaf7b7c6bc31667d1/src/AasxPackageLogic/PackageCentral/AasxFileServerInterface/AasxServerService.cs#L245

However the official openapi documentation specifies the reponse type of the operation as a json object of type PackageDescription (see https://app.swaggerhub.com/apis/Plattform_i40/AasxFileServerServiceSpecification/V3.0.1_SSP-001).

If such a json response is sent, the package explorer fails, trying to parse the response as an integer:

Error: Unhandled exception in AasxPackageExplorer v1.0.0.0: Input string was not in a correct format. Input string was not in a correct format. at    at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
   at AasxPackageLogic.PackageCentral.AasxFileServerInterface.AasxServerService.PostAASXPackage(Byte[] fileContent, String fileName, PackageContainerAasxFileRepository fileRepository) in D:\a\package-explorer\package-explorer\src\AasxPackageLogic\PackageCentral\AasxFileServerInterface\AasxServerService.cs:line 219
   at AasxPackageLogic.PackageCentral.AasxFileServerInterfaceService.PostAasxFileOnServer(String fileName, Byte[] fileContent, PackageContainerAasxFileRepository fileRepository) in D:\a\package-explorer\package-explorer\src\AasxPackageLogic\PackageCentral\AasxFileServerInterface\AasxFileServerInterfaceService.cs:line 103
   at AasxPackageLogic.PackageCentral.AasxFileServerInterface.PackageContainerAasxFileRepository.AddPackageToServer(String fileName) in D:\a\package-explorer\package-explorer\src\AasxPackageLogic\PackageCentral\AasxFileServerInterface\PackageContainerAasxFileRepository.cs:line 114
   at AasxWpfControlLibrary.PackageCentral.PackageContainerListOfListControl.CommandBinding_FileRepoAll(Control senderList, PackageContainerListBase fr, String cmd) in D:\a\package-explorer\package-explorer\src\AasxWpfControlLibrary\PackageCentral\PackageContainerListOfListControl.xaml.cs:line 329
   at AasxWpfControlLibrary.PackageCentral.PackageContainerListOfListControl.<>c__DisplayClass25_0.<<PackageContainerListControl_ButtonClick>b__0>d.MoveNext() in D:\a\package-explorer\package-explorer\src\AasxWpfControlLibrary\PackageCentral\PackageContainerListOfListControl.xaml.cs:line 466
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler).

To Reproduce

Steps to reproduce the behavior:

  1. Run this go file:

    package main
    
    import (
        "fmt"
        "net/http"
    )
    
    func main() {
        http.HandleFunc("/packages", func(w http.ResponseWriter, r *http.Request) {
            switch r.Method {
            case http.MethodGet:
                w.Header().Set("content-type", "application/json")
                w.Write([]byte(`{"paging_metadata":{},"result":[]}`))
            case http.MethodPost:
                w.Header().Set("content-type", "application/json")
                w.Write([]byte(`{"packageId":"my-random-id","aasIds":[]}`))
            default:
                w.WriteHeader(http.StatusInternalServerError)
            }
        })
    
        err := http.ListenAndServe(":1234", nil)
        if err != nil {
            fmt.Println(err)
        }
    }
  2. Add a new File -> AASX File Repository -> Connect HTTP/REST Repository -> "http://localhost:1234"

  3. Click vertical dots on new file repository -> Add AASX File to File Repository -> Choose any .aasx file

  4. See error in logs

Expected behavior

The package explorer should parse the response as json as defined in the official openapi documentation and not fail.

Desktop (please complete the following information):

juileetikekar commented 4 months ago

Hi @impact-merlinmarek,

Thank you for raising the issue !

Yes, support for only int should be changed to string in case of packageId. We will try to provide the solution as soon as possible.

impact-merlinzerbe commented 4 months ago

Hi @juileetikekar ,

I think there is a conflict between the pdf specification and the openapi documentation:

The pdf specification contains the output parameter packageId of type string while the openapi specification defines the return type as a json object of type PackageDescription. Since the openapi specification is referenced in the pdf file, I consider both to be "the standard".

Do you have more information which of these definitions should take precedence or is this something I should raise an issue for in the specs repo?

juileetikekar commented 4 weeks ago

Hi @impact-merlinzerbe,

Well, in general, in case of inconsistencies between the pdf and the openAPI, the issue needs to be created in the specs repo. However, the PackageDescription object consists of the PackageId as string.