christianhelle / refitter

A tool for generating Refit interfaces and contracts from OpenAPI specifications
https://refitter.github.io
MIT License
193 stars 42 forks source link

[FromForm] parameter on minimal api doesn't get generated on Interface #515

Open EdgeLee opened 2 days ago

EdgeLee commented 2 days ago

Describe the bug Consider the following endpoint using multipart form:

public record Request(string FirstName, string LastName);

public static async Task<Results<
    Ok,
    BadRequest<Error>
>>
UpdateEmployerProfile(
    [FromForm] Request request,
    [FromForm] string test,
    [FromForm] Guid employerId,
    IFormFile image,
{
}

Generated Interface

[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.4.0.0")]
public partial interface IEmployerApi
{
    [Multipart]
    [Headers("Accept: application/json")]
    [Post("/api/employer/updateemployerprofile")]
    Task<IApiResponse> UpdateEmployerProfile(StreamPart image);
}

Noticed only the image parameter is generated but not parameters with [FromForm].

Support Key: 89ljsu/

OpenAPI Specifications

"/api/employer/updateemployerprofile": {
  "post": {
    "tags": [
      "employer"
    ],
    "operationId": "UpdateEmployerProfile",
    "requestBody": {
      "content": {
        "multipart/form-data": {
          "schema": {
            "required": [
              "employerId",
              "image",
              "request",
              "test"
            ],
            "type": "object",
            "properties": {
              "request": {
                "$ref": "#/components/schemas/UpdateEmployerProfileRequest"
              },
              "test": {
                "type": "string"
              },
              "employerId": {
                "type": "string",
                "format": "uuid"
              },
              "image": {
                "type": "string",
                "format": "binary"
              }
            }
          },
          "encoding": {
            "request": {
              "style": "form"
            },
            "test": {
              "style": "form"
            },
            "employerId": {
              "style": "form"
            },
            "image": {
              "style": "form"
            }
          }
        }
      }
    },
    "responses": {
      "200": {
        "description": "OK"
      },
      "400": {
        "description": "Bad Request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
},

Additional context Ive tried using [FromQuery] and it works as intended.

EdgeLee commented 2 days ago

I've forgot to mention that I tried manually editing the generated Interface to the following:

[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.4.0.0")]
public partial interface IEmployerApi
{
    [Multipart]
    [Headers("Accept: application/json")]
    [Post("/api/employer/updateemployerprofile")]
    Task<IApiResponse> UpdateEmployerProfile(string EmployerId, string FirstName, string LastName, StreamPart image);
}

And I was able to get the values on the endpoint. Its just my changes will get overridden from the code gen.

christianhelle commented 1 day ago

@EdgeLee Thanks for taking the time to report this. Unfortunately, I'm too busy with other things to look into this. If you find a solution yourself and create a pull request, then I will find the time to review and make sure your fix gets merged in and released. Otherwise, this will have to wait a few weeks

EdgeLee commented 22 hours ago

Noted sir~ its fine, I just made a custom interface that overrides the base interface for the time being.