Skip to content

[typescript-angular] produces text/plain, type: string and responseType: 'text' #12535

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CodegenOperation {
public boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams, hasRequiredParams,
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMapContainer,
isListContainer, isMultipart, hasMore = true,
isResponseBinary = false, isResponseFile = false, hasReference = false,
isResponseBinary = false, isResponseFile = false, isResponseText = false, hasReference = false,
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
isRestful, isDeprecated;
public String path, testPath, operationId, returnType, httpMethod, returnBaseType,
Expand Down Expand Up @@ -248,6 +248,8 @@ public boolean equals(Object o) {
return false;
if (isResponseFile != that.isResponseFile)
return false;
if (isResponseText != that.isResponseText)
return false;
if (isDeprecated != that.isDeprecated)
return false;
if (path != null ? !path.equals(that.path) : that.path != null)
Expand Down Expand Up @@ -335,6 +337,7 @@ public int hashCode() {
result = 31 * result + (hasMore ? 13:31);
result = 31 * result + (isResponseBinary ? 13:31);
result = 31 * result + (isResponseFile ? 13:31);
result = 31 * result + (isResponseText ? 13:31);
result = 31 * result + (hasReference ? 13:31);
result = 31 * result + (isDeprecated ? 13:31);
result = 31 * result + (path != null ? path.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,11 @@ public CodegenOperation fromOperation(String path,
if (Boolean.TRUE.equals(r.isFile) && Boolean.TRUE.equals(r.isDefault)){
op.isResponseFile = Boolean.TRUE;
}
if (Boolean.TRUE.equals(r.isString)
&& operation.getProduces() != null && operation.getProduces().contains("text/plain") // otherwise if "application/json" => wrap text with "..", and escape
&& Boolean.TRUE.equals(r.isDefault)){
op.isResponseText = Boolean.TRUE;
}
}
op.responses.get(op.responses.size() - 1).hasMore = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class {{classname}} {

{{/hasFormParams}}
{{#useHttpClient}}
return this.httpClient.{{httpMethod}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}}
return this.httpClient.{{httpMethod}}{{#isResponseText}}/*{{/isResponseText}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}{{#isResponseText}}*/{{/isResponseText}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}}
{{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}}
{
{{#hasQueryParams}}
Expand All @@ -323,6 +323,9 @@ export class {{classname}} {
{{#isResponseFile}}
responseType: "blob",
{{/isResponseFile}}
{{#isResponseText}}
responseType: 'text',
{{/isResponseText}}
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
Expand All @@ -343,6 +346,9 @@ export class {{classname}} {
{{#isResponseFile}}
responseType: ResponseContentType.Blob,
{{/isResponseFile}}
{{#isResponseText}}
responseType: "text",
{{/isResponseText}}
{{#hasQueryParams}}
search: queryParameters,
{{/hasQueryParams}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.0-SNAPSHOT
2.4.44
15 changes: 11 additions & 4 deletions samples/client/petstore-security-test/typescript-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Building

To build an compile the typescript sources to javascript use:
To install the required dependencies and to build the typescript sources run:
```
npm install
npm run build
Expand All @@ -14,15 +14,15 @@ First build the package than run ```npm publish```

### consuming

navigate to the folder of your consuming project and run one of next commando's.
Navigate to the folder of your consuming project and run one of next commands.

_published:_

```
npm install @ --save
```

_unPublished (not recommended):_
_without publishing (not recommended):_

```
npm install PATH_TO_GENERATED_PACKAGE --save
Expand All @@ -37,9 +37,16 @@ npm link

In your project:
```
npm link @
npm link
```

__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
Published packages are not effected by this issue.


#### General usage

In your Angular project:


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ApiModule {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
}
};
}

constructor( @Optional() @SkipSelf() parentModule: ApiModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class FakeService {
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
for (const consume of consumes) {
if (form === consume) {
return true;
}
Expand All @@ -67,27 +67,28 @@ export class FakeService {
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {


let headers = this.defaultHeaders;

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/json',
'*_/ =end -- '
];
let httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
headers = headers.set("Accept", httpHeaderAcceptSelected);
headers = headers.set('Accept', httpHeaderAcceptSelected);
}

// to determine the Content-Type header
let consumes: string[] = [
const consumes: string[] = [
'application/json',
'*_/ =end -- '
];

const canConsumeForm = this.canConsumeForm(consumes);

let formParams: { append(param: string, value: any): void; };
let formParams: { append(param: string, value: any): void | HttpParams; };
let useForm = false;
let convertFormParamsToString = false;
if (useForm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class Configuration {
* Select the correct content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param {string[]} contentTypes - the array of content types that are available for selection
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
* @param contentTypes - the array of content types that are available for selection
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderContentType (contentTypes: string[]): string | undefined {
if (contentTypes.length == 0) {
Expand All @@ -47,8 +47,8 @@ export class Configuration {
* Select the correct accept content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct accept content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param {string[]} accepts - the array of content types that are available for selection.
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
* @param accepts - the array of content types that are available for selection.
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderAccept(accepts: string[]): string | undefined {
if (accepts.length == 0) {
Expand All @@ -69,8 +69,8 @@ export class Configuration {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param {string} mime - MIME (Multipurpose Internet Mail Extensions)
* @return {boolean} True if the given MIME is JSON, false otherwise.
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.0-SNAPSHOT
2.4.44
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Building

To build an compile the typescript sources to javascript use:
To install the required dependencies and to build the typescript sources run:
```
npm install
npm run build
Expand All @@ -14,15 +14,15 @@ First build the package than run ```npm publish```

### consuming

navigate to the folder of your consuming project and run one of next commando's.
Navigate to the folder of your consuming project and run one of next commands.

_published:_

```
npm install @ --save
```

_unPublished (not recommended):_
_without publishing (not recommended):_

```
npm install PATH_TO_GENERATED_PACKAGE --save
Expand All @@ -37,9 +37,16 @@ npm link

In your project:
```
npm link @
npm link
```

__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
Published packages are not effected by this issue.


#### General usage

In your Angular project:


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ApiModule {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
}
};
}

constructor( @Optional() @SkipSelf() parentModule: ApiModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class FakeService {
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
for (const consume of consumes) {
if (form === consume) {
return true;
}
Expand All @@ -67,27 +67,28 @@ export class FakeService {
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {


let headers = this.defaultHeaders;

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/json',
'*_/ =end -- '
];
let httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
headers = headers.set("Accept", httpHeaderAcceptSelected);
headers = headers.set('Accept', httpHeaderAcceptSelected);
}

// to determine the Content-Type header
let consumes: string[] = [
const consumes: string[] = [
'application/json',
'*_/ =end -- '
];

const canConsumeForm = this.canConsumeForm(consumes);

let formParams: { append(param: string, value: any): void; };
let formParams: { append(param: string, value: any): void | HttpParams; };
let useForm = false;
let convertFormParamsToString = false;
if (useForm) {
Expand All @@ -103,6 +104,7 @@ export class FakeService {
return this.httpClient.put<any>(`${this.basePath}/fake`,
convertFormParamsToString ? formParams.toString() : formParams,
{
// not text :(
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class Configuration {
* Select the correct content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param {string[]} contentTypes - the array of content types that are available for selection
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
* @param contentTypes - the array of content types that are available for selection
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderContentType (contentTypes: string[]): string | undefined {
if (contentTypes.length == 0) {
Expand All @@ -47,8 +47,8 @@ export class Configuration {
* Select the correct accept content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct accept content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param {string[]} accepts - the array of content types that are available for selection.
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
* @param accepts - the array of content types that are available for selection.
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderAccept(accepts: string[]): string | undefined {
if (accepts.length == 0) {
Expand All @@ -69,8 +69,8 @@ export class Configuration {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param {string} mime - MIME (Multipurpose Internet Mail Extensions)
* @return {boolean} True if the given MIME is JSON, false otherwise.
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.19-SNAPSHOT
2.4.44
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { Configuration } from '../configurat
@Injectable()
export class PetService {

protected basePath = 'https://petstore.swagger.io/v2';
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders = new Headers();
public configuration = new Configuration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Configuration } from '../configurat
@Injectable()
export class StoreService {

protected basePath = 'https://petstore.swagger.io/v2';
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders = new Headers();
public configuration = new Configuration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Configuration } from '../configurat
@Injectable()
export class UserService {

protected basePath = 'https://petstore.swagger.io/v2';
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders = new Headers();
public configuration = new Configuration();

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.19-SNAPSHOT
2.4.44
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { Configuration } from '../configurat
@Injectable()
export class PetService {

protected basePath = 'https://petstore.swagger.io/v2';
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders = new Headers();
public configuration = new Configuration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Configuration } from '../configurat
@Injectable()
export class StoreService {

protected basePath = 'https://petstore.swagger.io/v2';
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders = new Headers();
public configuration = new Configuration();

Expand Down
Loading