Giter VIP home page Giter VIP logo

Comments (14)

sagardwivedi avatar sagardwivedi commented on September 14, 2024 1

@IgorKha fastapi/fastapi#11882 (comment)

from openapi-ts.

mrlubos avatar mrlubos commented on September 14, 2024 1

@IgorKha feel free to propose a different implementation!

from openapi-ts.

mrlubos avatar mrlubos commented on September 14, 2024

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.

sagardwivedi avatar sagardwivedi commented on September 14, 2024

Okay, I will raise the question with FastAPI. @mrlubos, thank you for your response!

from openapi-ts.

sagardwivedi avatar sagardwivedi commented on September 14, 2024

Should I close the issue here?

from openapi-ts.

sagardwivedi avatar sagardwivedi commented on September 14, 2024

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

image

from openapi-ts.

mrlubos avatar mrlubos commented on September 14, 2024

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.

IgorKha avatar IgorKha commented on September 14, 2024

same problem....
@sagardwivedi Will you bring up the FastAPI issue? Please provide a link

from openapi-ts.

IgorKha avatar IgorKha commented on September 14, 2024

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.

sagardwivedi avatar sagardwivedi commented on September 14, 2024

@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.

IgorKha avatar IgorKha commented on September 14, 2024

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.

mrlubos avatar mrlubos commented on September 14, 2024

@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.

IgorKha avatar IgorKha commented on September 14, 2024

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.

Daynil avatar Daynil commented on September 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.