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

[BUG][Go] Invalid code for files array in multipart/form-data request #8093

Closed
5 of 6 tasks
aliakseiz opened this issue Dec 4, 2020 · 1 comment
Closed
5 of 6 tasks

Comments

@aliakseiz
Copy link
Contributor

aliakseiz commented Dec 4, 2020

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

Files array in multipart/form-data requestBody produces following code:

// AddCard - Add card
func (c *DefaultApiController) AddCard(w http.ResponseWriter, r *http.Request) { 
	err := r.ParseForm()
	if err != nil {
		w.WriteHeader(500)
		return
	}
	
	iD, err := parseIntParameter( r.FormValue("iD"))
	if err != nil {
		w.WriteHeader(500)
		return
	}
	
	file, err := ReadFormFileToTempFile(r, "file")
	if err != nil {
		w.WriteHeader(500)
		return
	}
	
	result, err := c.service.AddCard(iD, file)
	if err != nil {
		w.WriteHeader(500)
		return
	}
	
	EncodeJSONResponse(result, nil, w)
}

Where file is of type *os.File, but service.AddCard expects []*os.File.

openapi-generator version

Reproducible with 3.4.1 and 5.0.0-beta3.

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: "Custom API"
servers:
  - url: http://localhost:8080/api/v1
    description: development server
paths:
  /cards:
    post:
      summary: Add card
      operationId: addCard
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                ID:
                  type: integer
                  format: int64
                File:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        '200':
          description: Successful operation
Generation Details

Generated with

npx openapi-generator-cli generate -i openapi.yaml -g go-server -o server

Non-info output:

[main] WARN  o.o.codegen.DefaultCodegen - Could not compute datatypeWithEnum from *os.File, null
[main] WARN  o.o.c.languages.AbstractGoCodegen - 4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.
Steps to reproduce

Generate a go-server with the command provided above or a Docker-container.

Related issues/PRs
Suggest a fix

PR (#8103)

@auto-labeler
Copy link

auto-labeler bot commented Dec 4, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@aliakseiz aliakseiz changed the title [BUG][GO] Invalid code for files array in multipart/form-data request [BUG][Go] Invalid code for files array in multipart/form-data request Dec 5, 2020
wing328 pushed a commit that referenced this issue Dec 10, 2020
…uest'… (#8103)

* Fix for 'Invalid code for files array in multipart/form-data request' (#8093)

* Executed ensure-up-to-date

* Replaced spaces with tabs.
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

1 participant