Skip to content
GitLab
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
  • Issues
  • #2035
Closed
Open
Issue created Jan 31, 2019 by Administrator@rootContributor

[BUG] [typescript-angular] Missing handling of text responses

Created by: Fredx87

Description

When the returned content type of an API is a text type (e.g. text/plain), the Angular generated service doesn't set the responseType: text option (as shown in Angular documentation: https://angular.io/guide/http#requesting-non-json-data)

openapi-generator version

3.3.4

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: MyAPI
  description: MY API
  version: 0.0.0
servers:
  - url: http://localhost:8080/api/
paths:
  /example:
    get:
      operationId: getExample
      responses:
        "200":
          description: "Success"
          content:
            text/plain:
              schema:
                type: string
Command line used for generation

`docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v3.3.4 generate -i /local/swagger.yaml -g typescript-angular\ -o /local/src/app/api\ -DngVersion=6.0.0

Suggest a fix

This is the generated service:

    public getExample(observe?: 'body', reportProgress?: boolean): Observable<string>;
    public getExample(observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<string>>;
    public getExample(observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<string>>;
    public getExample(observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        let headers = this.defaultHeaders;

        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'text/plain'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected !== undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.get<string>(`${this.configuration.basePath}/example`,
            {
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

Instead the generator should call the get method with this format:

        return this.httpClient.get(`${this.configuration.basePath}/example`,
            {
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress,
                responseType: 'text'
            }
        );

Without the setting of this option. the http client will return an error instead of the text content of the called API

Assignee
Assign to
Time tracking