Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !2900

[typescript-fetch] Fix uploading files

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/Teyras/typescript-fetch-file-upload into master 6 years ago
  • Overview 0
  • Commits 21
  • Pipelines 0
  • Changes 13

Created by: Teyras

The current master converts anything that is not FormData to JSON. This behavior causes operations that accept a file to send requests where the payload is an empty JSON object.

This PR adds another branch that lets Blobs pass without modification.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10)

Compare
  • master (base)

and
  • latest version
    2ea96f7a
    21 commits, 2 years ago

13 files
+ 441
- 5

    Preferences

    File browser
    Compare changes
modules/…/…/…/…/‎typescript-fetch‎
runtime.‎mustache‎ +5 -1
samples/clie‎nt/…/…/builds‎
def‎ault‎
mod‎els‎
InlineO‎bject.ts‎ +52 -0
InlineOb‎ject1.ts‎ +52 -0
runti‎me.ts‎ +5 -1
es6-t‎arget‎
mod‎els‎
InlineO‎bject.ts‎ +52 -0
InlineOb‎ject1.ts‎ +52 -0
runti‎me.ts‎ +5 -1
with-in‎terfaces‎
mod‎els‎
InlineO‎bject.ts‎ +52 -0
InlineOb‎ject1.ts‎ +52 -0
runti‎me.ts‎ +5 -1
with-npm‎-version‎
mod‎els‎
InlineO‎bject.ts‎ +52 -0
InlineOb‎ject1.ts‎ +52 -0
runti‎me.ts‎ +5 -1
modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache
+ 5
- 1
  • View file @ 2ea96f7a

  • Edit in single-file editor

  • Open in Web IDE


@@ -3,6 +3,8 @@
export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
/**
* This is the base class for all generated API classes.
*/
@@ -47,7 +49,9 @@ export class BaseAPI {
// do not handle correctly sometimes.
url += '?' + querystring(context.query);
}
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const init = {
method: context.method,
headers: context.headers,
samples/client/petstore/typescript-fetch/builds/default/models/InlineObject.ts 0 → 100644
+ 52
- 0
  • View file @ 2ea96f7a

  • Edit in single-file editor

  • Open in Web IDE

// tslint:disable
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { exists, mapValues } from '../runtime';
/**
*
* @export
* @interface InlineObject
*/
export interface InlineObject {
/**
* Updated name of the pet
* @type {string}
* @memberof InlineObject
*/
name?: string;
/**
* Updated status of the pet
* @type {string}
* @memberof InlineObject
*/
status?: string;
}
export function InlineObjectFromJSON(json: any): InlineObject {
return {
'name': !exists(json, 'name') ? undefined : json['name'],
'status': !exists(json, 'status') ? undefined : json['status'],
};
}
export function InlineObjectToJSON(value?: InlineObject): any {
if (value === undefined) {
return undefined;
}
return {
'name': value.name,
'status': value.status,
};
}
samples/client/petstore/typescript-fetch/builds/default/models/InlineObject1.ts 0 → 100644
+ 52
- 0
  • View file @ 2ea96f7a

  • Edit in single-file editor

  • Open in Web IDE

// tslint:disable
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { exists, mapValues } from '../runtime';
/**
*
* @export
* @interface InlineObject1
*/
export interface InlineObject1 {
/**
* Additional data to pass to server
* @type {string}
* @memberof InlineObject1
*/
additionalMetadata?: string;
/**
* file to upload
* @type {Blob}
* @memberof InlineObject1
*/
file?: Blob;
}
export function InlineObject1FromJSON(json: any): InlineObject1 {
return {
'additionalMetadata': !exists(json, 'additionalMetadata') ? undefined : json['additionalMetadata'],
'file': !exists(json, 'file') ? undefined : json['file'],
};
}
export function InlineObject1ToJSON(value?: InlineObject1): any {
if (value === undefined) {
return undefined;
}
return {
'additionalMetadata': value.additionalMetadata,
'file': value.file,
};
}
samples/client/petstore/typescript-fetch/builds/default/runtime.ts
+ 5
- 1
  • View file @ 2ea96f7a

  • Edit in single-file editor

  • Open in Web IDE


@@ -14,6 +14,8 @@
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
/**
* This is the base class for all generated API classes.
*/
@@ -58,7 +60,9 @@ export class BaseAPI {
// do not handle correctly sometimes.
url += '?' + querystring(context.query);
}
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const init = {
method: context.method,
headers: context.headers,
samples/client/petstore/typescript-fetch/builds/es6-target/models/InlineObject.ts 0 → 100644
+ 52
- 0
  • View file @ 2ea96f7a

  • Edit in single-file editor

  • Open in Web IDE

// tslint:disable
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { exists, mapValues } from '../runtime';
/**
*
* @export
* @interface InlineObject
*/
export interface InlineObject {
/**
* Updated name of the pet
* @type {string}
* @memberof InlineObject
*/
name?: string;
/**
* Updated status of the pet
* @type {string}
* @memberof InlineObject
*/
status?: string;
}
export function InlineObjectFromJSON(json: any): InlineObject {
return {
'name': !exists(json, 'name') ? undefined : json['name'],
'status': !exists(json, 'status') ? undefined : json['status'],
};
}
export function InlineObjectToJSON(value?: InlineObject): any {
if (value === undefined) {
return undefined;
}
return {
'name': value.name,
'status': value.status,
};
}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
3
Feature: Composition / Inheritance Feature: Generator Issue: Regression
3
Feature: Composition / Inheritance Feature: Generator Issue: Regression
    Assign labels
  • Manage project labels

Milestone
4.3.1
4.3.1 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!5977
Source branch: github/fork/Teyras/typescript-fetch-file-upload

Menu

Explore Projects Groups Snippets