Invalid Typescript schema requested for POST
See original GitHub issueHi, love this initiative. It’s allowed me to remove hundreds of lines of code.
I’ve got a strange problem trying to wire up a POST request using the standard approach:
export const submitForm = fetcher.path('/form/{formId}/submit').method('post').create();
The Swagger API definition requests formId
as a parameter and formFields as the post body, but the returned function requests the following input, a intersection between an object and an array, which is impossible to provide:
I might be doing something wrong, but it seems like a potential bug. Here’s the type for the request:
"/form/{formId}/submit": {
post: {
parameters: {
path: {
formId: string;
};
};
responses: {
/** Success */
200: {
content: {
"text/plain": components["schemas"]["FormModel"];
"application/json": components["schemas"]["FormModel"];
"text/json": components["schemas"]["FormModel"];
};
};
};
requestBody: {
content: {
"application/json":
| components["schemas"]["FormFieldInputModel"][]
| null;
"text/json": components["schemas"]["FormFieldInputModel"][] | null;
"application/*+json":
| components["schemas"]["FormFieldInputModel"][]
| null;
};
};
};
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Typescript request-body types validation always pass for ...
Typescript never gives me error for any request body schema. It always gives success response. tsconfig.json { "compilerOptions": { "target": " ...
Read more >Using with TypeScript - Ajv JSON schema validator
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Read more >fluent-json-schema - npm
fluent-json-schema. A fluent API to generate JSON schemas (draft-07) for Node.js and browser. Framework agnostic.
Read more >17.7.0 API Reference - joi.dev
If the input is invalid, error is assigned a ValidationError object providing more information. The schema can be a plain JavaScript object where...
Read more >Chapter 6: Validations with Joi | Hapi With Typescript - Softcover
In this chapter, we will learn about: schema validations with joi plugin;; validating requests and responses with joi ;; customizing validation errors; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bnhovde as a workaround you could try
You still get type safety on the required properties.
Hate to say it, but I think I might have evidence that top level arrays in a body is a fairly common usecase: RFC 6902 - Section 3.
That being said, it does look like the workaround and the utility function
arrayRequestBody
you provided is doing the trick! Just made use of it, and as with the rest of the library, it trivialized the problem. Really glad I ran across this library. Honestly this is the first time I’ve had an API service actually backed directly by the openapi spec with type validation and it’s fantastic.