Haskell-OpenAPI-Code-Generator / Haskell-OpenAPI-Client-Code-Generator

Generate Haskell client code from an OpenAPI 3 specification
46 stars 19 forks source link

Not including response body in GET of list endpoint #96

Closed pbrisbin closed 6 months ago

pbrisbin commented 6 months ago

I have a large-ish spec that includes,

    "/constructed-responses.json": {
      "get": {
        "responses": {
          "200": {
            "content": {
              "application/json;charset=utf-8": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/ConstructedResponse"
                  },
                  "type": "array"
                }
              }
            },
            "description": ""
          }
        }
      }
    }

References,

      "ConstructedResponse": {
        "properties": {
          "proxy_skill_id": {
            "type": "string"
          },
          "resources": {
            "items": {
              "$ref": "#/components/schemas/ConstructedResponseResource"
            },
            "minItems": 1,
            "type": "array"
          }
        },
        "required": [
          "proxy_skill_id",
          "resources"
        ],
        "type": "object"
      },
      "ConstructedResponseResource": {
        "properties": {
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "url"
        ],
        "type": "object"
      }

When I generate from this spec, I get:

-- | Represents a response of the operation 'get_constructed_responses'json'.
-- 
-- The response constructor is chosen by the status code of the response. If no case matches (no specific case for the response code, no range case, no default case), 'Get_constructed_responses'jsonResponseError' is used.
data Get_constructed_responses'jsonResponse =
   Get_constructed_responses'jsonResponseError GHC.Base.String -- ^ Means either no matching case available or a parse error
  | Get_constructed_responses'jsonResponse200 -- ^ 
  deriving (GHC.Show.Show, GHC.Classes.Eq)

Notice Get_constructed_responses'jsonResponse200 has no value.

Shouldn't there be a NonEmpty ConstructedResponse there?

pbrisbin commented 6 months ago

Oh, I think I found why:

WARN  (paths./{lang}/lesson-data.json.GET.responses.200.content): Only content type application/json is supported for response bodies.

This spec is generated from a Servant type using servant-openapi3. It decides to add the ;charset= suffix on the content-types. I think this generator should still accept such values, since it is still application/json.

joel-bach commented 6 months ago

Hey @pbrisbin , Thank you for the report. As far as I can see you analyzed the problem correctly. I do not see a reason to not support content types with a charset (although we do not do any special handling of the charset), so I applied a fix which should resolve your issue: https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator/pull/97 I'll close the issue for now but feel free to comment or reopen it if it does not work as expected.

pbrisbin commented 6 months ago

Thanks for the quick fix!