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

Add more metadata #824

Closed
JKamsker opened this issue Apr 25, 2022 · 5 comments
Closed

Add more metadata #824

JKamsker opened this issue Apr 25, 2022 · 5 comments

Comments

@JKamsker
Copy link

JKamsker commented Apr 25, 2022

For minimal apis, i miss methods to add descriptions

app
        .DefineApi("People")
        .HasMapping(api =>
        {
            api.MapGet("/api/v{version:apiVersion}/people/{id:int}", (int id) => "Some response")
              .Produces(response => response.Body<WeatherForecast>())
              .Produces(404)
              .HasApiVersion(1.0)
              ;

        });

Produces:

{
    "x-generator": "NSwag v13.15.10.0 (NJsonSchema v10.6.10.0 (Newtonsoft.Json v9.0.0.0))",
    "openapi": "3.0.0",
    "info": {
        "title": "Minimal API",
        "version": "1"
    },
    "servers": [
        {
            "url": "https://localhost:7174"
        }
    ],
    "paths": {
        "/api/v1/people/{id}": {
            "get": {
                "tags": [
                    "people"
                ],
                "operationId": "GetApiV1People",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer",
                            "format": "int32"
                        },
                        "x-position": 1
                    }
                ],
                "responses": {
                    "200": {
                        "description": "",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/WeatherForecast"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "WeatherForecast": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                    "date": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "temperatureC": {
                        "type": "integer",
                        "format": "int32"
                    },
                    "temperatureF": {
                        "type": "integer",
                        "format": "int32"
                    },
                    "summary": {
                        "type": "string",
                        "nullable": true
                    }
                }
            }
        }
    }
}

In this example i want to be able to add paths.['/api/v1/people/{id}'].get.description and paths.['/api/v1/people/{id}'].get.responses.['200'].description which is currently (6.0.0-preview.2) not possible

@commonsensesoftware
Copy link
Collaborator

This will be reverted in Preview 3, which would alleviate this problem. It should be published - soon. 😉 I'll leave this unresolved until you can confirm you're getting the behavior/features you expected.

@JKamsker
Copy link
Author

JKamsker commented May 5, 2022

Ahh what?
You will remove features? 😵

How would this solve the issue? 💩

@commonsensesoftware
Copy link
Collaborator

🤣 HA! No, not quite. After a long discussion and some refactoring, the mechanisms by which you provide intrinsic metadata will be reverted back to how they were/are. You can see what it will look like here in the updated example.

It's less than ideal, but probably the best that can be done for 6.0. Once MapGroup is available in 7.0, then I'm hoping to pair things down even more. 🤞🏽

@commonsensesoftware
Copy link
Collaborator

I'm going to call this a 🐞 simply because it didn't do what you expected. As I mentioned, there is a significant refactor in Preview 3 that will address this. Effectively, the API Versioning-specific code for this has been removed and things should now behave the same as any other Minimal API.

Preview 3 is now available and contains the fix for this issue. Review the release notes and updated examples to see how things have changed.

@commonsensesoftware
Copy link
Collaborator

6.0 is officially released and has the same setup as in Preview 3. This should feel natural and coherent with how the metadata is applied, even without API Versioning. In .NET 7.0, some improvements will come to streamline things even further. Thanks for reporting the issue.

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

No branches or pull requests

2 participants