swagger-api / swagger-api/swagger-codegen-generators
typescript-fetch not working with requestBodies (reusable bodies)
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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