OpenAPITools / OpenAPITools/openapi-generator

[BUG] [GO] properties in a multipart/form-data endpoint are not parsed to the correct type in the generated code

Open
#16,024 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Generating an endpoint that accepts a multipart/form-data payload with a non string property in the schema will result in a compilation error in the method.

In the example below, the generated interface method for receiveCake expects a number for the Cake parameter, however, the generated code parses the cake from the form payload as a string and passes the string into the method, thus resulting in a compiler error.

openapi-generator version

openapitools/openapi-generator-cli:v6.6.0
and
openapitools/openapi-generator-cli:latest

OpenAPI declaration file content or url

Simplest:

---
info:
  contact:
    email: jacob.shedenhelm@workiva.com
    name: Jacob Shedenhelm
  description: An API for birthday cakes
  title:  Cakes
  version: v0.0.1
openapi: 3.0.3
paths:
  /birthday-cakes/v1/receiveCake:
    post:
      operationId: receiveCake
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                cake:
                 type: number
      responses:
        200:
          description: Ok
      security:
        - {oauth: []}

The issue I am running into is when using a $ref, it also hits the same error.

---
info:
  contact:
    email: jacob.shedenhelm@workiva.com
    name: Jacob Shedenhelm 
  description: An API for birthday cakes 
  title:  Cakes
  version: v0.0.1
openapi: 3.0.3
components:
  schemas:
    Cake:
      type: object
      properties:
        toppings: 
          type: string
        message: 
          type: string
      required:
        - toppings 
        - message 
paths:
  /birthday-cakes/v1/receiveCake:
    post:
      operationId: receiveCake
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                handshake:
                  $ref: '#/components/schemas/Cake'
      responses:
        200:
          description: Ok
      security:
        - {oauth: []}
Generation Details

openapigenerator-cli v6.6.0 & latest
Golang

Note - you must set the global-property skipFormModel=true in order to generate the Cake model from the second oas provided, this is an open issue.

Steps to reproduce

use the open api generator to generate code from the top provided oas, navigate to the generated ReceiveCake method, notice compile error.

Related issues/PRs

n/a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the minimal multipart/form-data YAML with the OpenAPI Generator CLI and generate the Go code. Start at the generated ReceiveCake method, comparing its parameter type with how the form payload is parsed. Done means non-string properties, including the referenced Cake schema, are parsed with their declared types and the generated code compiles without requiring unexpected options.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.