So fügen Sie das Pfad in das Server -URL -Element der OpenAPI -Spezifikation ein, das aus der ASP.NET -Kernminimal -API

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: So fügen Sie das Pfad in das Server -URL -Element der OpenAPI -Spezifikation ein, das aus der ASP.NET -Kernminimal -API

by Anonymous » 03 Apr 2025, 04:47

Ich habe eine C# / ASP.NET -Kern -Minimal -API -App, wobei die Prahlerei eine OpenAPI -Spezifikation generiert. Um dem Publish YML zu entsprechen, muss ich einen Server mit Pfad hinzufügen und die Pfadelemente aus einzelnen Gruppen entfernen.

Code: Select all

.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "My API",
Version = "2.0",
});

c.AddServer(new OpenApiServer
{
Url = "https://api.myapi.org.uk/api/v2",
Description = "Production"
});

c.AddServer(new OpenApiServer
{
Url = "https://localhost:{port}/api/v2",
Description = "Local",
Variables =
{
new ("port", new OpenApiServerVariable
{
Default = "7147",
}),
},
});
})
< /code>
Dann kartieren Sie später einen Endpunkt in einer Gruppe wie: < /p>
var builder = app.MapGroup("/needs");
builder .MapGet("/", async (CancellationToken cancellationToken) => { ... });
< /code>
Wenn ich versuche, dies mit der SWAGVE -UI zu testen, bekomme ich eine 404 -Antwort. Aber wenn ich den Pfad vom Server in die Gruppe bewege, funktioniert es gut..AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "My API",
Version = "2.0",
});

c.AddServer(new OpenApiServer
{
Url = "https://api.myapi.org.uk/",
Description = "Production"
});

c.AddServer(new OpenApiServer
{
Url = "https://localhost:{port}/",
Description = "Local",
Variables =
{
new ("port", new OpenApiServerVariable
{
Default = "7147",
}),
},
});
})

// ...

var builder = app.MapGroup("/api/v2/needs");
builder .MapGet("/", async (CancellationToken cancellationToken) => { ... });
< /code>
Ich habe viele Kombinationen ausprobiert, kann aber nicht herausfinden, was los ist. Ist dies einfach Teil der Spezifikation, die nicht korrekt implementiert wird, oder gibt es eine Möglichkeit, dass es funktioniert?openapi: 3.0.1
info:
title: My API
version: '2.0'
servers:
- url: https://myapi.org.uk/api/v2
description: Production
- url: 'https://localhost:{port}'
description: Local
variables:
port:
default: '7147'

paths:
/needs:
get:
...

Top