Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

Issue with code generator #113

Closed AlexGorodilov closed 2 years ago

AlexGorodilov commented 4 years ago

Hello.

When I use multipart/form-data.

Such code is generated. And compiller type script show error.

export class FileService { /**

Type 'FormData' is not assignable to type 'null'

JSON file is next

"/api/File/UploadFile": { "post": { "tags": [ "File" ], "summary": "Загрузка файлов на сервер", "requestBody": { "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "uploadedFile": { "type": "string", "description": "файл", "format": "binary", "nullable": true } } }, "encoding": { "uploadedFile": { "style": "form" } } } } }, "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "type": "integer", "format": "int32" } } } } } } },

Manweill commented 4 years ago

can use format your code with markdown

Manweill commented 3 years ago

Close up for a long time is not active Issue

MinaroShikuchi commented 2 years ago

Sorry for reopening but I can't see why I get this error

static uploadFile(
    params: {
      /**  */
      id: string;
      /**  */
      type: string;
      /**  */
      file: any;
    } = {} as any,
    options: IRequestOptions = {}
  ): Promise<GedFileDto> {
    return new Promise((resolve, reject) => {
      let url = basePath + '/ged/files/{id}/upload';
      url = url.replace('{id}', params['id'] + '');

      const configs: IRequestConfig = getConfigs('post', 'multipart/form-data', url, options);
      configs.params = { type: params['type'] };
      let data = null;
      data = new FormData();
      if (params['file']) {
        if (Object.prototype.toString.call(params['file']) === '[object Array]') {
          for (const item of params['file']) {
            data.append('file', item as any);
          }
        } else {
          data.append('file', params['file'] as any);
        }
      }

      configs.data = data;
      axios(configs, resolve, reject);
    });

it should just this

let data = new FormData();
Manweill commented 2 years ago

any details?

MinaroShikuchi commented 2 years ago

Yes sorry,

/ged/files/{id}/upload: {
  post: {
    operationId: "uploadFile",
    parameters: [
      {
        name: "id",
        required: true,
        in: "path",
        schema: { type: "string" }
      },
      { 
        name: "type", 
        required: true, 
        in: "query", 
        schema: { type: "string" }
      }
    ],
    requestBody: { 
      required: true,
      content: {
        multipart/form-data: {
          schema: {
            type: "object",
            properties: {  file: { type: "string", format: "binary" } }
          }
        }
      }
    },
  responses: {
    201: {
      description: "",
        content: {
         application/json: { schema: { $ref: "#/components/schemas/GedFileDto" } }
        }
      }
    },
tags: [
"ged"
]
}
}
Manweill commented 2 years ago

i will try it.

Manweill commented 2 years ago

@MinaroShikuchi fix in v0.12.9

MinaroShikuchi commented 2 years ago

It works great. Thanks a lot !