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

Using Results<T1, T2> with same statuscode and different content #2816

Open
EniacMlezi opened this issue Apr 19, 2024 · 1 comment
Open

Using Results<T1, T2> with same statuscode and different content #2816

EniacMlezi opened this issue Apr 19, 2024 · 1 comment
Labels
help-wanted A change up for grabs for contributions from the community needs investigation

Comments

@EniacMlezi
Copy link

EniacMlezi commented Apr 19, 2024

When defining an endpoint that has two possible return types with the same status code (both 200 OK), one WITH content and one WITHOUT content:

app.MapGet("/auth/test", Test).WithOpenApi();

internal static Results<Ok, Ok<TestClass>> Test()
{
    return TypedResults.Ok();
}

The resulting swagger.json does not reflect this:

"/auth/test": {
      "get": {
        "tags": [
          "AuthEndpoints"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestClass"
                }
              }
            }
          }
        }
      }
    },

I would expect a resulting swagger.json like:

"/auth/test": {
      "get": {
        "tags": [
          "AuthEndpoints"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestClass"
                }
              }
            }
          },
          "200": {
            "description": "OK"
          }
        }
      }
    },

But I imagine defining "200" twice is problematic for the spec.

@EniacMlezi
Copy link
Author

For anyone wondering why this usecase, I ran into it in the MapIdentityApi Endpoints:
https://github.com/dotnet/aspnetcore/blob/e2e689acc6e17371d1546556825c533f35446e1d/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs#L90

@martincostello martincostello added needs investigation help-wanted A change up for grabs for contributions from the community labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted A change up for grabs for contributions from the community needs investigation
Projects
None yet
Development

No branches or pull requests

2 participants