swagger-api / swagger-api/swagger-codegen

[TYPESCRIPT-ANGULAR] Filename during upload

Open
#8,386 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Modelling a rest service to upload a file using swagger 2.0 result in a default implementation in typescript with "Blob" type. This class does not specify a filename, so instead a File class must be used, because File extends Blob and specify a filename

Swagger-codegen version

2.3.1 ( I think current stable is behind https://editor.swagger.io too )

Swagger declaration file content or url
swagger: "2.0"
info:
  version: "0.1"
  title: "TEST UPLOAD"  
basePath: "/rest"
schemes:
- "http"
host: localhost:8080
paths: 
  /file/xml:
    post:
      consumes:
      - "multipart/form-data"
      parameters:
      - in: formData
        name: upfile
        type: file
        required: true
      produces:
      - "application/json"
      responses:
       200:
        description: file uploaded
        schema:
          type: string
Command line used for generation

Using https://editor.swagger.io/

Steps to reproduce
  1. go to https://editor.swagger.io/
  2. paste provided yaml
  3. generate-client -> typescript-angular
  4. unzip result
  5. go to /api folder
  6. open default.service.ts
  7. at row 65,66,67,68 generated methos are:
public fileXmlPost(upfile: Blob, observe?: 'body', reportProgress?: boolean): Observable<string>;
    public fileXmlPost(upfile: Blob, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<string>>;
    public fileXmlPost(upfile: Blob, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<string>>;
    public fileXmlPost(upfile: Blob, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
  1. why upfile type is Blob instead of File ?
Related issues/PRs

No one found

Suggest a fix/enhancement

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

Reproduce the issue with the provided Swagger 2.0 definition using the typescript-angular generator, then inspect the generated /api/default.service.ts entry point. Trace the generator template or type mapping that produces the Blob parameter and verify the generated upload signature against the expected filename-carrying type.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.