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

[TYPESCRIPT-ANGULAR] File list in multipart breaks ganerated angular client #9993

Closed
wutzebaer opened this issue Jan 17, 2020 · 1 comment · Fixed by swagger-api/swagger-codegen-generators#1188

Comments

@wutzebaer
Copy link

wutzebaer commented Jan 17, 2020

Description

I define a list of files on my yaml file and the gernerated angular code is broken

Swagger-codegen version

v3.0.16

Swagger declaration file content or url
openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: 'http://localhost:8080'
    description: Generated server url
paths:
  '/kunde/{kundenId}/message':
    post:
      tags:
        - kunde-controller
      operationId: uploadmessage
      parameters:
        - name: kundenId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                message:
                  type: string
                files:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        '200':
          description: default response
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i input.yaml -l typescript-angular

Steps to reproduce
git clone https://github.com/swagger-api/swagger-codegen --branch v3.0.16
mvn -f swagger-codegen/pom.xml clean package -DskipTest=true
copy swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar .
java -jar swagger-codegen-cli.jar generate -i input.yaml -l typescript-angular
Suggest a fix/enhancement

When i define one file it works correctly and generates the following code

        let useForm = false;
        let convertFormParamsToString = false;
        // use FormData to transmit files using content-type "multipart/form-data"
        // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data
        useForm = canConsumeForm;
        if (useForm) {

when defining as list it generates this, the canConsumeForm-part is missing

        let useForm = false;
        let convertFormParamsToString = false;
        if (useForm) {

when i manually set useForm=true in the generated code, everything works fine

@wutzebaer wutzebaer changed the title Upload a list af files with multipart File list in multipart breaks ganerated angular client Jan 17, 2020
@wutzebaer wutzebaer changed the title File list in multipart breaks ganerated angular client [TYPESCRIPT-ANGULAR] File list in multipart breaks ganerated angular client Jan 17, 2020
@majster
Copy link

majster commented Jan 10, 2022

Mustache template has this prepared (type="string", format="binary"), but Codegen is still checking if type == "file".

https://github.com/OpenAPITools/openapi-generator/blob/478219744e71b1faf6e6d5dee7c15a24605429f1/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L4803

image

Workaround is to implement service by hand :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants