Describe the bug
I'm migrating Swashbuckle.AspNetCore to Microsoft.OpenApi 2.0.0-preview7 (as that's the version used by ASP.NET Core 10 preview 2), and an existing regression test we have for OAuth2 is failing due to the security definition not being deserialized correctly.
Distilling things down, this is what we expect:
{
"openapi": "3.0.4",
"info": { },
"paths": { },
"components": {
"securitySchemes": {
"oauth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "/auth-server/connect/authorize",
"tokenUrl": "/auth-server/connect/token",
"scopes": {
"readAccess": "Access read operations",
"writeAccess": "Access write operations"
}
}
}
}
}
},
"security": [
{
"oauth2": [
"readAccess",
"writeAccess"
]
}
]
}However, what we get is this:
{
"openapi": "3.0.4",
"info": { },
"paths": { },
"components": {
"securitySchemes": {
"oauth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "/auth-server/connect/authorize",
"tokenUrl": "/auth-server/connect/token",
"scopes": {
"readAccess": "Access read operations",
"writeAccess": "Access write operations"
}
}
}
}
}
},
"security": [
{ }
]
}As far as I can tell, the Target is returning null (so nothing is emitted), but I don't understand why it isn't found via the reference into the host document:
| foreach(varsecuritySchemeAndScopesValuePairinthis.Where(static p =>p.Key?.Targetis not null)) |
It might be that there's an additional code migration I need to do here for v2, but if there is I haven't been able to spot it.
OpenApi File To Reproduce
[Fact]publicvoidCanSerializeSecuritySchemes(){vardocument=newOpenApiDocument();document.Components??=new();document.Components.SecuritySchemes.Add("oauth2",newOpenApiSecurityScheme{Type=SecuritySchemeType.OAuth2,Flows=newOpenApiOAuthFlows{AuthorizationCode=newOpenApiOAuthFlow{AuthorizationUrl=newUri("/auth-server/connect/authorize",UriKind.Relative),TokenUrl=newUri("/auth-server/connect/token",UriKind.Relative),Scopes=newDictionary<string,string>{{"readAccess","Access read operations"},{"writeAccess","Access write operations"}}}}});document.SecurityRequirements.Add(newOpenApiSecurityRequirement{{newOpenApiSecuritySchemeReference("oauth2",document),["readAccess","writeAccess"]}});usingvarwriter=newStringWriter();varjsonWriter=newOpenApiJsonWriter(writer);document.SerializeAsV3(jsonWriter);varjson=writer.ToString();}Expected behavior
The security scheme and the required scopes are serialized to the OpenAPI document.
Describe the bug
I'm migrating Swashbuckle.AspNetCore to Microsoft.OpenApi 2.0.0-preview7 (as that's the version used by ASP.NET Core 10 preview 2), and an existing regression test we have for OAuth2 is failing due to the security definition not being deserialized correctly.
Distilling things down, this is what we expect:
{ "openapi": "3.0.4", "info": { }, "paths": { }, "components": { "securitySchemes": { "oauth2": { "type": "oauth2", "flows": { "authorizationCode": { "authorizationUrl": "/auth-server/connect/authorize", "tokenUrl": "/auth-server/connect/token", "scopes": { "readAccess": "Access read operations", "writeAccess": "Access write operations" } } } } } }, "security": [ { "oauth2": [ "readAccess", "writeAccess" ] } ] }However, what we get is this:
{ "openapi": "3.0.4", "info": { }, "paths": { }, "components": { "securitySchemes": { "oauth2": { "type": "oauth2", "flows": { "authorizationCode": { "authorizationUrl": "/auth-server/connect/authorize", "tokenUrl": "/auth-server/connect/token", "scopes": { "readAccess": "Access read operations", "writeAccess": "Access write operations" } } } } } }, "security": [ { } ] }As far as I can tell, the
Targetis returningnull(so nothing is emitted), but I don't understand why it isn't found via the reference into the host document:OpenAPI.NET/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs
Line 76 in 3534a65
It might be that there's an additional code migration I need to do here for v2, but if there is I haven't been able to spot it.
OpenApi File To Reproduce
Expected behavior
The security scheme and the required scopes are serialized to the OpenAPI document.