Zaid-Ajaj / Hawaii

dotnet CLI tool to generate type-safe F# and Fable clients from OpenAPI/Swagger or OData services
MIT License
138 stars 15 forks source link

Error with Stability API: Objects in multi-part form content in API spec generates invalid code #55

Open varon opened 5 months ago

varon commented 5 months ago

An example of this is in the stability API, which produces invalid code (compile errors).

config file:

{
  "schema": "./openapi-stability.json",
  "project": "Stability",
  "output": "../../gen/Stability",
  "target": "fsharp",
  "synchronous": true,
}

Errors:

0>------- Started building project: Stability
0>Client.fs(1104,15): Error FS0041 : No overloads match for method 'multipartFormData'.
Known types of arguments: string * TextPrompts

Available overloads:
 - static member RequestPart.multipartFormData: key: string * value: System.DateTimeOffset -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: System.Guid -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: bool -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: byte array -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: double -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: float32 -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: int -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: int64 -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * value: string -> RequestPart // Argument 'value' doesn't match
 - static member RequestPart.multipartFormData: key: string * values: System.Guid list -> RequestPart // Argument 'values' doesn't match
 - static member RequestPart.multipartFormData: key: string * values: int list -> RequestPart // Argument 'values' doesn't match
 - static member RequestPart.multipartFormData: key: string * values: int64 list -> RequestPart // Argument 'values' doesn't match
 - static member RequestPart.multipartFormData: key: string * values: string list -> RequestPart // Argument 'values' doesn't match

I'm not sure how we go about solving this - issue seems to be with their API defining objects in multi-part forms.

You can view an example in their API docs here: https://platform.stability.ai/docs/api-reference#tag/Image-to-Image/operation/imageToImage - see the text_prompts parameter.

I can give this a bash if you can outline the steps to solve it.

Zaid-Ajaj commented 5 months ago

Hmm that's a difficult one because here we probably need to flatten the structure we get into a list of RequestParts 🤔 the code generator needs to understand that this parameter is a complex structure, then generate code that flattens it when building the parts of the request body. Sorry if this is a bit vague, some of these API are really weird to work with.

Zaid-Ajaj commented 5 months ago

Example of how the generated code should look like:

for (part, i) in flatten textPrompts do
  yield RequestPart.multipartFormData($"text_prompts[{i}].text", part.text)
  yield RequestPart.multipartFormData($"text_prompts[{i}].weight", part.weight)
varon commented 5 months ago

(The fix for #56 is unrelated to this - FYI)