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

SwaggerRequestBodyAttribute Description have no effect in Minimal Api #2662

Closed
akiragothick opened this issue Jun 4, 2023 · 4 comments · Fixed by #2963
Closed

SwaggerRequestBodyAttribute Description have no effect in Minimal Api #2662

akiragothick opened this issue Jun 4, 2023 · 4 comments · Fixed by #2963
Labels
stale Stale issues or pull requests

Comments

@akiragothick
Copy link

Minimal API

I'm using Swashbuckle.AspNetCore 6.5.0 with Swashbuckle.AspNetCore.Annotations 6.5.0 and have added a SwaggerRequestBodyAttribute to a response class thus:

app.MapPost("/todos", ([FromBody, SwaggerRequestBody("Todo object to be created", Required = true)] Todo todo) =>
    {
        todos.Add(todo with { Id = Guid.NewGuid() });
        return TypedResults.Ok(todo);
    })
    .WithOpenApi(operation => new(operation)
    {
        Summary = "Create a todo",
        OperationId = "createTodo",
        Tags = new List<OpenApiTag> { new() { Name = "Todos" } },
        //Parameters = new List<OpenApiParameter>
        //{
        //    new OpenApiParameter{ Description ="Todo object to be created" }
        //}
    });

The project docs say I can use this to "to enrich the corresponding Schema metadata that's generated by Swashbuckle", but the generated swagger.json doesn't contain "MyTitle" or "MyDescription" at all, only:

"post": {
    "tags": [
      "Todos"
    ],
    "summary": "Create a todo",
    "operationId": "createTodo",
    "requestBody": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/Todo"
          }
        }
      },
      "required": true
    },
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Todo"
            }
          }
        }
      }
    }
  }

My configurations

builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", new OpenApiInfo { Title = "ChatGPT Plugin", Version = "v1" });
    options.DocInclusionPredicate((docName, apiDesc) => true);
    options.EnableAnnotations();
});
@Havunen
Copy link

Havunen commented Feb 18, 2024

The issue is missing the details where "MyTitle" and "MyDescription" are defined? Can you add those details please so I can have a look at this issue

@martincostello
Copy link
Collaborator

I believe this would be resolved by #2414.

Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

@jgarciadelanoceda
Copy link
Contributor

I have just written a PR because it was giving an exception for this matter. @martincostello this parameter is to describe the RequestBody, not the operation itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues or pull requests
Projects
None yet
4 participants