Haskell-OpenAPI-Client-Code-Generator icon indicating copy to clipboard operation
Haskell-OpenAPI-Client-Code-Generator copied to clipboard

API spec with mime type application/vnd.xxx

Open schoettl opened this issue 2 months ago • 2 comments

Another question: The Xentral ERP OpenAPI spec declares custom mime types like application/vnd.xxx+json.

…
        "operationId": "product.view",
        "summary": "View product",
        "description": "Returns details of a single product",
        "responses": {
          "200": {
            "description": "Operation completed successfully.",
            "content": {
              "application/vnd.xentral.default.v1+json": {

…

yields

data Product'viewResponse =
   Product'viewResponseError GHC.Base.String -- ^ Means either no matching case available or a parse error
  | Product'viewResponse200 -- ^ Operation completed successfully.
  | Product'viewResponse400 -- ^ IETF RFC 7807 Problem API compliant response
  …

with no actual response data type.

The custom vendor mime types seem to be generally OK but seem to be unsupported by this generator. It might make sense to change the parser to handle regex application/(vnd\.[\a\d]+\+)?json as JSON.

I just did search & replace with application/json, then types were generated.

The next problem is that the Xentral API server requires the exact mime type specified in their spec and it does not respond to requests with Accept: application/json. I think it's not a good design decision by Xentral. But this maybe should be considered when implementing support vendor mime types in this generator.

I now have to work around this... my plan is to use this config:

  let config = Configuration { configBaseURL = "https://xxx.xentral.biz"
                             , configSecurityScheme = addXentralAuthHeader "xxxx" . HS.addRequestHeader "Accept" "application/vnd.xentral.default.v1+json"
                             , configIncludeUserAgent = False
                             , configApplicationName = "xxx"
                             }

Though, even worse, Xentral declares different vendor mime types so I need to generate a map for looking up the specific mime type for each operation.

schoettl avatar Apr 24 '24 15:04 schoettl