Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operations based on request content type #1491

Open
csaba-veezla opened this issue Jan 7, 2025 · 0 comments
Open

Operations based on request content type #1491

csaba-veezla opened this issue Jan 7, 2025 · 0 comments

Comments

@csaba-veezla
Copy link

What is the problem this feature would solve?

So we have a use-case, where you can create asset resources (inline, upload, import from url, external url).
This endpoint can be called with both application/json and multipart/form-data content types.
But only the latter provides you with the capability to upload actual files as content from your computer.
(We know with base64 encoding application/json could be able to handle it, but it would result in a 33% transfer size increase, so this is why we opted for the multipart/form-data content type.)

So our schema looks similar to this:

{
  "paths": {
    "/assets": {
      "post": {
        "operationId": "createAsset",
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Asset"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssetCreate"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/AssetCreateWithUploadRequestMultiPart"
              }
            }
          }
        }
      }
    }
  }
}

Currently, @kubb/plugin-react-query is ignoring the "multipart/form-data" content type, but it should not.

External documents/projects?

No response

What is the feature you are proposing to solve the problem?

@kubb/plugin-react-query should generate additional operations for the different content types.
the application/json could still be viewed as the default resulting in the usual: useCreateOperationName hook name
As for other contentTypes, they could get sensible names, like:

  • multipart/form-data -> Form
  • application/x-www-form-urlencoded -> EncodedForm
  • text/plain -> Text
  • application/xml - XML
    If the content type is not in the predefined list, we could just Pascalcase the content type.
    With these names, the resulting hook could be called <basename>With<sensible_name> like useCreateOperationNameWithEncodedForm.

What alternatives have you considered?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants