Comments (14)
@IgorKha fastapi/fastapi#11882 (comment)
from openapi-ts.
@IgorKha feel free to propose a different implementation!
from openapi-ts.
Yes @sagardwivedi, but that is a FastAPI question. Had the OpenAPI specification been correct, then it would be an issue with this package
from openapi-ts.
Okay, I will raise the question with FastAPI. @mrlubos, thank you for your response!
from openapi-ts.
Should I close the issue here?
from openapi-ts.
I am trying to custom set the error message if i get the response 400
if (response.status === 400) {
return setError(error?.detail)
}
but i am getting (property) detail?: ValidationError[] | undefined
in error?.detail
but I am getting from the backend
from openapi-ts.
It doesn't matter what is returned from the backend. OpenAPI specification is the contract describing the API. It's up to the server to then value that contract. In your case, there are scenarios you're not describing in the contract as you can see from your spec
from openapi-ts.
same problem....
@sagardwivedi Will you bring up the FastAPI issue? Please provide a link
from openapi-ts.
I think it would be correct to always return the server's response status code in the case of an error. This makes more sense, as it provides the actual response status from the server.
from openapi-ts.
@IgorKha I understand your point, but after thoroughly checking the FastAPI
documentation, I couldn't find an alternative method. The @hey-api/openapi-ts
library relies on openapi.json
to generate client, and unfortunately, the openapi.json
doesn't include the raise HTTPException
.
from openapi-ts.
Yes, I understand; I read the discussion about FastAPI. I realize this is an issue specific to their implementation. However, I would still like to ask the author of this library to consider providing an option to return the actual server response status code in case of an error, regardless of what's in the OpenAPI specification. In my opinion, this would be quite versatile and convenient for everyone.
Thank you :)
from openapi-ts.
@IgorKha if you're using the new standalone client packages, you have access to the raw response object. Is that what you need?
from openapi-ts.
I use @hey-api/client-axios
, but I also tested @hey-api/client-fetch
. Indeed, the raw response contains the server status, but the issue is that you have to remember this additional step while working. This workaround does address the problem, though it's not as native as I'd like. It seems I'll have to adjust the backend 🥲
Anyway, thank you for the great tool! 😄
from openapi-ts.
FastAPI actually provides a solution to this in the documentation. When you set a responses parameter in your path operation decorators, the other response codes will show up in the OpenAPI spec and openapi-ts will capture them.
from openapi-ts.
Related Issues (20)
- react-query `createQueryKey` uses `baseUrl` of global client rather than `options.client` HOT 1
- TanStack Query (Vue) code generates `body` parameter for infinite list
- Generating services incorrectly HOT 5
- Option to customize schema names and/or $ prefix HOT 3
- Discriminator in OpenApi schema not recognized correctly HOT 2
- Available Clients add Nuxt.js support HOT 1
- Help catch non declared query or path parameters HOT 10
- Interceptor Duplicates When Modifying and Saving _layout.tsx File in Expo Project Using client-fetch
- Add `clear()` method to remove all interceptors
- Axios gets imported wrong during testing HOT 5
- V0.53.0 generates empty core/request.ts HOT 4
- Option to ignore headers HOT 11
- Colon in path results in invalid generation HOT 2
- Using wrong client config parameter leads to undefined HttpRequestConstructor HOT 3
- BaseURL not being set when using client.setConfig HOT 1
- Tanstack Query Incorrect onError Types HOT 4
- Improved types for Vue Tanstack Query HOT 1
- Concurrent createClient calls resolve to same input HOT 1
- fetch-api mistakenly serializes FormData as application/json instead of multipart/form-data
- Parameter in path with multiple dollar sign gets replaced to a single dollar sign HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-ts.