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

[C# client generation] Improper handling of 204 status code #4853

Open
mdzieg opened this issue Apr 10, 2024 · 0 comments
Open

[C# client generation] Improper handling of 204 status code #4853

mdzieg opened this issue Apr 10, 2024 · 0 comments

Comments

@mdzieg
Copy link

mdzieg commented Apr 10, 2024

I have a problem with C# generator.
Version 13.6.2 is the latest one what works. Code generated with that version looks like this:

                         if (status_ == "200") 
                        {
                            return;
                        }
                        else
                        if (status_ != "200" && status_ != "204")
                        {

As of version 13.7.0, generated code thwors exception instead of default value in case 204 status code is returned:

            int status_ = (int) response_.StatusCode;
            if (status_ == 200)
            {
              ...
            }
            else
            { 

I added attributes on controller method to inform generator that it can result with 204, and the code generated is also not okay:

                        var status_ = (int)response_.StatusCode;
                        if (status_ == 200)
                        {
                            var objectResponse_ = await ReadObjectResponseAsync<GetRealizationRepartitionAppDto>(response_, headers_, cancellationToken).ConfigureAwait(false);
                            return objectResponse_.Object;
                        }
                        else
                        if (status_ == 204)
                        {
                            string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
                            throw new ApiException("No Content", status_, responseText_, headers_, null);
                        }

swagger.json looks more or less like this (after applying attributes):

"responses": {
					"200": {
						"description": "Success",
						"content": {
							"text/plain": {
								"schema": {
									"$ref": "#/components/schemas/AppDto"
								}
							},
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/AppDto"
								}
							},
							"text/json": {
								"schema": {
									"$ref": "#/components/schemas/AppDto"
								}
							},
							"application/xml": {
								"schema": {
									"$ref": "#/components/schemas/AppDto"
								}
							},
							"text/xml": {
								"schema": {
									"$ref": "#/components/schemas/AppDto"
								}
							}
						}
					},
					"204": {
						"description": "No Content"
					}
				}

@RicoSuter What should I do to get correct 204 status code handling.

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

1 participant