swagger-api / swagger-api/swagger-codegen-generators

typescript-fetch not working with requestBodies (reusable bodies)

Open
#848 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

usage of reusable (bodies https://swagger.io/docs/specification/describing-request-body/ section Reusable Bodies) doesn't generate a valid test suite and body models

definitions

paths:
  /v1/example
    post:
      tags:
        - example
      summary: create a new example
      requestBody:
        $ref: '#/components/requestBodies/CreateExample'
components:
  requestBodies:
    CreateExample:
      required: true
      content:
        application/json:
          schema:
            properties:
              name:
                type: string
            required:
              - name

Test suite errors

running npm test will produce errors like:

    api_test.spec.ts:212:21 - error TS2694: Namespace '"..."' has no exported member 'any'.

    212     const body: api.any = undefined
describe("ExampleApi", () => {
  test("v1ExamplePost", () => {
    const body: api.any = undefined // <------------------------------
    //...
  })
})

Missing body models

this is not an issue because library effectively works but doesn't use typescript types so every body use any as type

        /**
         * ...
         * @param {any} body 
         * ...
         */
        v1ExamplePost(body: any, id: string, options: any = {}): FetchArgs {

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 reproducing the issue with the supplied reusable requestBody definition and run npm test. Inspect the generated api_test.spec.ts and the generated client method, then verify that the test suite no longer references api.any and that request bodies have usable TypeScript types.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.