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 · 3 comments
Open

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

mdzieg opened this issue Apr 10, 2024 · 3 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.

@icnocop
Copy link
Contributor

icnocop commented Jul 11, 2024

Related issues:
#1259
#1602
#2995
#4064

You can try one of the work-arounds indicated in one of these comments:
#1259 (comment)
#2995 (comment)
#2995 (comment)
#2995 (comment)
#2995 (comment)

@AnReZa
Copy link

AnReZa commented Nov 11, 2024

Having a similar issue under #5018.

@vvdb-architecture
Copy link

vvdb-architecture commented Nov 18, 2024

See GFlisch/Arc4u.Guidance.Doc#88.
You can solve it with nullable="true" in comments

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

4 participants