Skip to content

Commit

Permalink
Merge branch 'master' into issues-10307
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario committed Jun 24, 2020
2 parents a416376 + 621dfc0 commit 94c1fc9
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 128 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
- [Zalando](https://tech.zalando.com)
- [ZEEF.com](https://zeef.com/)
- [zooplus](https://www.zooplus.com/)
- [Trifork](https://www.trifork.com/)

Presentations/Videos/Tutorials/Books
----------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions modules/swagger-codegen/src/main/resources/dart/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class {{classname}} {
/// {{summary}}
///
/// {{notes}}
{{#isDeprecated}}
@deprecated
{{/isDeprecated}}
{{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async {
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{>licenseInfo}}
/* tslint:disable:no-unused-variable member-ordering */

import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import IHttpClient from "../IHttpClient";
import { inject, injectable } from "inversify";
import { IAPIConfiguration } from "../IAPIConfiguration";
import { Headers } from "../Headers";
import HttpResponse from "../HttpResponse";
import IHttpClient from '../IHttpClient';
import { inject, injectable } from 'inversify';
import { IAPIConfiguration } from '../IAPIConfiguration';
import { Headers } from '../Headers';
import HttpResponse from '../HttpResponse';

{{#imports}}
import { {{classname}} } from '../{{filename}}';
Expand All @@ -34,13 +34,10 @@ export class {{classname}} implements {{classname}}Interface {
{{^withInterfaces}}
export class {{classname}} {
{{/withInterfaces}}
private basePath: string = '{{{basePath}}}';
@inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration;
@inject('IApiHttpClient') private httpClient: IHttpClient;


constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
@inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
if(this.APIConfiguration.basePath)
this.basePath = this.APIConfiguration.basePath;
}
{{#operation}}

/**
Expand Down Expand Up @@ -68,21 +65,21 @@ export class {{classname}} {
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
queryParameters.push("{{paramName}}="+encodeURIComponent(String({{paramName}})));
queryParameters.push('{{paramName}}='+encodeURIComponent(String({{paramName}})));
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
queryParameters.push("{{paramName}}="+encodeURIComponent({{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])));
queryParameters.push('{{paramName}}='+encodeURIComponent({{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])));
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
{{#isDateTime}}
queryParameters.push("{{paramName}}="+encodeURIComponent(<any>{{paramName}}.toISOString()));
queryParameters.push('{{paramName}}='+encodeURIComponent(<any>{{paramName}}.toISOString()));
{{/isDateTime}}
{{^isDateTime}}
queryParameters.push("{{paramName}}="+encodeURIComponent(String({{paramName}})));
queryParameters.push('{{paramName}}='+encodeURIComponent(String({{paramName}})));
{{/isDateTime}}
}
{{/isListContainer}}
Expand All @@ -106,13 +103,13 @@ export class {{classname}} {
// authentication ({{name}}) required
{{#isApiKey}}
{{#isKeyInHeader}}
if (this.APIConfiguration.apiKeys["{{keyParamName}}"]) {
headers['{{keyParamName}}'] = this.APIConfiguration.apiKeys["{{keyParamName}}"];
if (this.APIConfiguration.apiKeys['{{keyParamName}}']) {
headers['{{keyParamName}}'] = this.APIConfiguration.apiKeys['{{keyParamName}}'];
}
{{/isKeyInHeader}}
{{#isKeyInQuery}}
if (this.APIConfiguration.apiKeys["{{keyParamName}}"]) {
queryParameters.push("{{paramName}}="+encodeURIComponent(String(this.APIConfiguration.apiKeys["{{keyParamName}}"])));
if (this.APIConfiguration.apiKeys['{{keyParamName}}']) {
queryParameters.push('{{paramName}}='+encodeURIComponent(String(this.APIConfiguration.apiKeys['{{keyParamName}}'])));
}
{{/isKeyInQuery}}
{{/isApiKey}}
Expand Down Expand Up @@ -169,9 +166,9 @@ export class {{classname}} {
{{/formParams}}

{{/hasFormParams}}
const response: Observable<HttpResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>> = this.httpClient.{{httpMethod}}(`${this.basePath}{{{path}}}{{#hasQueryParams}}?${queryParameters.join('&')}{{/hasQueryParams}}`{{#bodyParam}}, {{paramName}} {{/bodyParam}}{{#hasFormParams}}, body{{/hasFormParams}}, headers);
if (observe == 'body') {
return response.map(httpResponse => <{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>(httpResponse.response)){{#usePromise}}.toPromise(){{/usePromise}};
const response: Observable<HttpResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>> = this.httpClient.{{httpMethod}}(`${this.APIConfiguration.basePath}{{{path}}}{{#hasQueryParams}}?${queryParameters.join('&')}{{/hasQueryParams}}`{{#bodyParam}}, {{paramName}}{{/bodyParam}} as any{{#hasFormParams}}, body{{/hasFormParams}}, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response){{#usePromise}}.toPromise(){{/usePromise}};
}
return response{{#usePromise}}.toPromise(){{/usePromise}};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.0-SNAPSHOT
2.4.10-SNAPSHOT
77 changes: 37 additions & 40 deletions samples/client/petstore/typescript-inversify/api/pet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
*/
/* tslint:disable:no-unused-variable member-ordering */

import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import IHttpClient from "../IHttpClient";
import { inject, injectable } from "inversify";
import { IAPIConfiguration } from "../IAPIConfiguration";
import { Headers } from "../Headers";
import HttpResponse from "../HttpResponse";
import IHttpClient from '../IHttpClient';
import { inject, injectable } from 'inversify';
import { IAPIConfiguration } from '../IAPIConfiguration';
import { Headers } from '../Headers';
import HttpResponse from '../HttpResponse';

import { ApiResponse } from '../model/apiResponse';
import { Pet } from '../model/pet';
Expand All @@ -29,13 +29,10 @@ import { COLLECTION_FORMATS } from '../variables';

@injectable()
export class PetService {
private basePath: string = 'http:https://petstore.swagger.io/v2';
@inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration;
@inject('IApiHttpClient') private httpClient: IHttpClient;


constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
@inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
if(this.APIConfiguration.basePath)
this.basePath = this.APIConfiguration.basePath;
}

/**
* Add a new pet to the store
Expand All @@ -60,9 +57,9 @@ export class PetService {
headers['Accept'] = 'application/xml';
headers['Content-Type'] = 'application/json';

const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.basePath}/pet`, body , headers);
if (observe == 'body') {
return response.map(httpResponse => <any>(httpResponse.response));
const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.APIConfiguration.basePath}/pet`, body as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand Down Expand Up @@ -95,9 +92,9 @@ export class PetService {
}
headers['Accept'] = 'application/xml';

const response: Observable<HttpResponse<any>> = this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, headers);
if (observe == 'body') {
return response.map(httpResponse => <any>(httpResponse.response));
const response: Observable<HttpResponse<any>> = this.httpClient.delete(`${this.APIConfiguration.basePath}/pet/${encodeURIComponent(String(petId))}` as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand All @@ -118,7 +115,7 @@ export class PetService {

let queryParameters: string[] = [];
if (status) {
queryParameters.push("status="+encodeURIComponent(status.join(COLLECTION_FORMATS['csv'])));
queryParameters.push('status='+encodeURIComponent(status.join(COLLECTION_FORMATS['csv'])));
}

// authentication (petstore_auth) required
Expand All @@ -130,9 +127,9 @@ export class PetService {
}
headers['Accept'] = 'application/xml';

const response: Observable<HttpResponse<Array<Pet>>> = this.httpClient.get(`${this.basePath}/pet/findByStatus?${queryParameters.join('&')}`, headers);
if (observe == 'body') {
return response.map(httpResponse => <Array<Pet>>(httpResponse.response));
const response: Observable<HttpResponse<Array<Pet>>> = this.httpClient.get(`${this.APIConfiguration.basePath}/pet/findByStatus?${queryParameters.join('&')}` as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand All @@ -153,7 +150,7 @@ export class PetService {

let queryParameters: string[] = [];
if (tags) {
queryParameters.push("tags="+encodeURIComponent(tags.join(COLLECTION_FORMATS['csv'])));
queryParameters.push('tags='+encodeURIComponent(tags.join(COLLECTION_FORMATS['csv'])));
}

// authentication (petstore_auth) required
Expand All @@ -165,9 +162,9 @@ export class PetService {
}
headers['Accept'] = 'application/xml';

const response: Observable<HttpResponse<Array<Pet>>> = this.httpClient.get(`${this.basePath}/pet/findByTags?${queryParameters.join('&')}`, headers);
if (observe == 'body') {
return response.map(httpResponse => <Array<Pet>>(httpResponse.response));
const response: Observable<HttpResponse<Array<Pet>>> = this.httpClient.get(`${this.APIConfiguration.basePath}/pet/findByTags?${queryParameters.join('&')}` as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand All @@ -187,14 +184,14 @@ export class PetService {
}

// authentication (api_key) required
if (this.APIConfiguration.apiKeys["api_key"]) {
headers['api_key'] = this.APIConfiguration.apiKeys["api_key"];
if (this.APIConfiguration.apiKeys['api_key']) {
headers['api_key'] = this.APIConfiguration.apiKeys['api_key'];
}
headers['Accept'] = 'application/xml';

const response: Observable<HttpResponse<Pet>> = this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, headers);
if (observe == 'body') {
return response.map(httpResponse => <Pet>(httpResponse.response));
const response: Observable<HttpResponse<Pet>> = this.httpClient.get(`${this.APIConfiguration.basePath}/pet/${encodeURIComponent(String(petId))}` as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand Down Expand Up @@ -223,9 +220,9 @@ export class PetService {
headers['Accept'] = 'application/xml';
headers['Content-Type'] = 'application/json';

const response: Observable<HttpResponse<any>> = this.httpClient.put(`${this.basePath}/pet`, body , headers);
if (observe == 'body') {
return response.map(httpResponse => <any>(httpResponse.response));
const response: Observable<HttpResponse<any>> = this.httpClient.put(`${this.APIConfiguration.basePath}/pet`, body as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand Down Expand Up @@ -264,9 +261,9 @@ export class PetService {
formData.append('status', <any>status);
}

const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, body, headers);
if (observe == 'body') {
return response.map(httpResponse => <any>(httpResponse.response));
const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.APIConfiguration.basePath}/pet/${encodeURIComponent(String(petId))}` as any, body, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand Down Expand Up @@ -305,9 +302,9 @@ export class PetService {
formData.append('file', <any>file);
}

const response: Observable<HttpResponse<ApiResponse>> = this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, body, headers);
if (observe == 'body') {
return response.map(httpResponse => <ApiResponse>(httpResponse.response));
const response: Observable<HttpResponse<ApiResponse>> = this.httpClient.post(`${this.APIConfiguration.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage` as any, body, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand Down
49 changes: 23 additions & 26 deletions samples/client/petstore/typescript-inversify/api/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
*/
/* tslint:disable:no-unused-variable member-ordering */

import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import IHttpClient from "../IHttpClient";
import { inject, injectable } from "inversify";
import { IAPIConfiguration } from "../IAPIConfiguration";
import { Headers } from "../Headers";
import HttpResponse from "../HttpResponse";
import IHttpClient from '../IHttpClient';
import { inject, injectable } from 'inversify';
import { IAPIConfiguration } from '../IAPIConfiguration';
import { Headers } from '../Headers';
import HttpResponse from '../HttpResponse';

import { Order } from '../model/order';

Expand All @@ -28,13 +28,10 @@ import { COLLECTION_FORMATS } from '../variables';

@injectable()
export class StoreService {
private basePath: string = 'http:https://petstore.swagger.io/v2';
@inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration;
@inject('IApiHttpClient') private httpClient: IHttpClient;


constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
@inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
if(this.APIConfiguration.basePath)
this.basePath = this.APIConfiguration.basePath;
}

/**
* Delete purchase order by ID
Expand All @@ -51,9 +48,9 @@ export class StoreService {

headers['Accept'] = 'application/xml';

const response: Observable<HttpResponse<any>> = this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, headers);
if (observe == 'body') {
return response.map(httpResponse => <any>(httpResponse.response));
const response: Observable<HttpResponse<any>> = this.httpClient.delete(`${this.APIConfiguration.basePath}/store/order/${encodeURIComponent(String(orderId))}` as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand All @@ -68,14 +65,14 @@ export class StoreService {
public getInventory(observe?: 'response', headers?: Headers): Observable<HttpResponse<{ [key: string]: number; }>>;
public getInventory(observe: any = 'body', headers: Headers = {}): Observable<any> {
// authentication (api_key) required
if (this.APIConfiguration.apiKeys["api_key"]) {
headers['api_key'] = this.APIConfiguration.apiKeys["api_key"];
if (this.APIConfiguration.apiKeys['api_key']) {
headers['api_key'] = this.APIConfiguration.apiKeys['api_key'];
}
headers['Accept'] = 'application/json';

const response: Observable<HttpResponse<{ [key: string]: number; }>> = this.httpClient.get(`${this.basePath}/store/inventory`, headers);
if (observe == 'body') {
return response.map(httpResponse => <{ [key: string]: number; }>(httpResponse.response));
const response: Observable<HttpResponse<{ [key: string]: number; }>> = this.httpClient.get(`${this.APIConfiguration.basePath}/store/inventory` as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand All @@ -96,9 +93,9 @@ export class StoreService {

headers['Accept'] = 'application/xml';

const response: Observable<HttpResponse<Order>> = this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, headers);
if (observe == 'body') {
return response.map(httpResponse => <Order>(httpResponse.response));
const response: Observable<HttpResponse<Order>> = this.httpClient.get(`${this.APIConfiguration.basePath}/store/order/${encodeURIComponent(String(orderId))}` as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand All @@ -120,9 +117,9 @@ export class StoreService {
headers['Accept'] = 'application/xml';
headers['Content-Type'] = 'application/json';

const response: Observable<HttpResponse<Order>> = this.httpClient.post(`${this.basePath}/store/order`, body , headers);
if (observe == 'body') {
return response.map(httpResponse => <Order>(httpResponse.response));
const response: Observable<HttpResponse<Order>> = this.httpClient.post(`${this.APIConfiguration.basePath}/store/order`, body as any, headers);
if (observe === 'body') {
return response.map(httpResponse => httpResponse.response);
}
return response;
}
Expand Down
Loading

0 comments on commit 94c1fc9

Please sign in to comment.