Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2xx codes treated as error response #70

Open
acwl-aiq opened this issue Apr 23, 2024 · 3 comments
Open

2xx codes treated as error response #70

acwl-aiq opened this issue Apr 23, 2024 · 3 comments

Comments

@acwl-aiq
Copy link

Describe the bug
In the HTTP world, 2xx response codes tend to be treated as success. For instance, 201 is an extension of 200 which indicates the creation of a resource.

Problem
This function here dictates what code is acceptable as a response code. It will default to 200 or the first 2xx code in the list of defined responses and there is no way to specify which responses are acceptable.

def generate_return_type(operation: Operation) -> OpReturnType:

In other words, there's no way for the service provider to dictate multiple response codes as "good"

An alternative to this problem is to allow the client to decide which response codes to treat as error but the current implementation forbids that and instead throws an exception on the behalf of the client if that singular response code is not observed. The workaround for the service is to always return 200 OK

Expected behavior
Either:

  1. Treat 2xx as good
  2. Allow 2xx responses to be treated as good if defined in "responses" param of the API
  3. Option to let client to handle response codes

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@drsybren
Copy link

drsybren commented Nov 26, 2024

Describe the bug In the HTTP world, 2xx response codes tend to be treated as success.

It's stronger than that. The 2xx range is literally defined as "Successful" in RFC 9110, which defines the semantics of the HTTP protocol.

I use 204 No Content a lot in my API, which is a standard way of signalling "I did the thing, and have nothing to say in response".

@MarcoMuellner
Copy link
Owner

Would you be willing to pose a PR for this?

@drsybren
Copy link

Would you be willing to pose a PR for this?

Not sure if I have the time. It also depends on whether we settle on this code generator, or another one.

Would it be possible to have the dependencies in pyproject.toml reduced? As far as I can see, orjson and httpx are only used to download & parse the OpenAPI spec from a remote URL. This can just as well be done with the Python stdlib, and it would make it easier to integrate this generator in other projects.

Also the use of black could be optional; it's nice that code gets auto-formatted, but in our project we don't use Black, and so having this as a mandatory step in the code generation is a bit clunky.

I know this is a bit off-topic for this particular Github issue, but the answers may directly influence the answer to your question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants