OpenAPITools / OpenAPITools/openapi-generator

[REQ] typescript-fetch - add config option to generate single-level request objects

Open
#13,836 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

I have a Spring Boot + Kotlin backend with an API endpoint defined like:

data class FooRequest(
    val bar: String,
    val baz: String,
)
@PostMapping("/foo")
fun foo(@RequestBody request: FooRequest) {
   ...
}

generating the client for this with typescript-fetch produces:

// models/FooRequest.ts
export interface FooRequest {
    bar: string;
    baz: string;
}

// apis/FooApi.ts
export interface FooOperationRequest {
    fooRequest: FooRequest;
}

// myFile.ts
new FooApi().foo({
    fooRequest: {
        bar: ''.
        baz: ''
    }
})

Describe the solution you'd like

The argument to the foo function should just be the FooRequest object rather than an object with the key fooRequest. Calling the API should look like

// myFile.ts
new FooApi().foo({
    bar: ''.
    baz: ''
})

This is how the generation is done in typescript-axios

Describe alternatives you've considered

Will probably use typescript-axios for this reason

Additional context

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 by tracing how the typescript-fetch generator creates FooOperationRequest and compare its output with typescript-axios. Done means a configuration option generates direct FooRequest arguments for the shown endpoint while preserving the current wrapped form when the option is not enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.