OpenAPITools / OpenAPITools/openapi-generator

[BUG][Go][Server] File upload does not seems to work

Open
#11,542 0 comments 4 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

Defining requestBody as a media file generate invalid code that use *os.File{}.

This is not possible to work with file upload as the code is not correct.

openapi-generator version

6.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: Test
  title: Test
  version: 0.0.0
servers:
- url: http://127.0.0.1:8080/api/v1
tags:
- description: Videos operations
  name: videos
paths:
  /videos:
    post:
      description: Create a video
      operationId: createVideo
      requestBody:
        content:
          videos/*:
            schema:
              format: binary
              type: string
        description: Video to add
        required: true
      responses:
        "201":
          description: Null response
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Unexpected error
      summary: Create a video
      tags:
      - videos
components:
  schemas:
    Error:
      properties:
        code:
          format: int32
          type: integer
        message:
          type: string
      required:
      - code
      - message
      type: object
Generation Details
Steps to reproduce
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
    -i /local/openapi.yaml \
    -g go-server \
    -o /local/server \
    --additional-properties=packageName=testapi,featureCORS=true,sourceFolder=testapi
Related issues/PRs
Suggest a fix

I have tried to change *os.File{} to *os.Create("tmp") but this lead to another error during the Decode step.

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

Start by running the supplied docker openapi-generator command with the provided OpenAPI declaration and inspect the generated go-server file-upload handling. Trace the Decode step and determine why the generated code uses *os.File{}; done means the generated server accepts the binary request body without invalid code or a subsequent Decode error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.