OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-fetch] withInterfaces result includes 'raw' methods

Open
#10,237 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When I generate typescript-fetch code from OpenAPI spec, using withInterfaces=true switch, the generated interfaces include two methods for each API operation, e.g. getArticles and getArticlesRaw.

The raw method is not part of the API, it's an implementation detail; the interface should be 1:1 with the OpenAPI spec.

openapi-generator version

"@openapitools/openapi-generator-cli": "^2.3.7"

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Example
  description: Reproducing bug
  version: 1.0.0
servers:
  - url: 'http://localhost:9000/'
tags:
  - name: article
    description: 'Everything concerning articles, comments'
paths:
  /article:
    get:
      tags:
        - article
      summary: Get all articles
      operationId: getArticles
      parameters:
        - in: query
          name: category
          schema:
            type: string
            default: BLOG
        - in: query
          name: filter
          schema:
            type: string
        - in: query
          name: language
          schema:
            type: string
            default: en
        - in: query
          name: page
          schema:
            type: integer
            default: 0
        - in: query
          name: itemsPerPage
          schema:
            type: integer
            default: 20
      responses:
        '200':
          description: Articles retrieved
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Article'      
components:
  schemas:
    Article:
      type: object
      properties:
        id:
          type: string
          format: uuid
        author:
          $ref: '#/components/schemas/User'
        category:
          type: string
          description: Category
          enum:
            - BLOG
            - FRONT_PAGE
        title:
          type: string
          description: Title
        slug:
          type: string
        text:
          type: string
        tags:
          type: string
        language:
          type: string
        publishDate:
          type: string
          format: date-time
          description: Published Date    
Generation Details
openapi-generator-cli generate -g typescript-fetch -i api-bundle.yaml -o ./packages/generated --additional-properties=typescriptThreePlus=true,withInterfaces=true
Steps to reproduce

Generate code from provided spec using provided script.
Check generated/apis/ArticleApi.ts

Suggest a fix

The method is written here -- either remove this completely, or make it ? optional.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache, especially the method referenced in the issue, and reproduce the output with the provided OpenAPI spec and generation command. Inspect generated/apis/ArticleApi.ts. Done means withInterfaces=true exposes only the operation method defined by the OpenAPI spec, without the raw implementation method.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.