Add more missed objects in core#28
Add more missed objects in core#28xuzhg merged 8 commits intomicrosoft:masterfrom xuzhg:AddMoreMissingObjects
Conversation
|
@xuzhg, |
| @@ -27,6 +27,14 @@ public class OpenApiSecurityScheme : IOpenApiReference, IOpenApiExtension | |||
| public Uri TokenUrl { get; set; } | |||
| public IDictionary<string,string> Scopes { get; set; } | |||
There was a problem hiding this comment.
These 4 should be removed since they belong in the OAuthFlow object, not here. #Closed
|
The builders in https://github.com/Microsoft/OpenAPI.NET/blob/master/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV3Builder.cs and https://github.com/Microsoft/OpenAPI.NET/blob/master/src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV2Builder.cs would need to write things for these new fields too. #Closed |
| public class OpenApiSecurityScheme : IOpenApiReference, IOpenApiExtension | ||
| { | ||
| public string Key { get; set; } | ||
| public string Type { get; set; } |
There was a problem hiding this comment.
string [](start = 15, length = 6)
SecuritySchemeTypeKind ?
There was a problem hiding this comment.
Yes. I didn't figure out how to use this enum type. But, I do think we should use the enum to limit the value.
There was a problem hiding this comment.
You should make this SecuritySchemeTypeKind.
Then, in the Builder, you can use Enum.Parse. See how the "in" parameter is mapped in the ParameterObject (OpenApiBuilderV3.cs about line 337).
It would be nice to do something similar for the In property in OpenApiSecurityScheme too.
There was a problem hiding this comment.
Maybe we should have moved the YAML/JSON readers out into a different project so you wouldn't have felt obliged to fix my unfinished code because it was in the core project ;-) You folks don't need the V2 reader, for your purposes, right?
There was a problem hiding this comment.
Personally, it's fine. It's more like a team project at this point, and I already feel it's something integral to the core part we should get finished before releasing anyway.
I don't need V2, and I don't think Sam does as well. Fixing V2 builder and writer is a bit of a pain since our model is sorta closely based on V3, and it's not always easy to do the translation. Let's see how it goes. If fixing V2 wastes incrementally way more time than needed, maybe one person can tackle it at the end?
There was a problem hiding this comment.
:-) Agreed. Using the V2 builder to map onto the V3 dom is a pain, especially if you are not familiar with the differences between V2 and V3. However, it is the pain we do here that will save many people who are trying to make the transition from V2 to V3.
|
I modify the builder, but for the V2 builder, I can not make sure the fixed and pattern fields are ok. We can modify it in the coming PR. Besides, It looks I have to duplicate a lot of codes both in V2 and V3, It's better to refactor them. Let's also figure out later. #Closed |
|
|
||
| public static OpenApiOAuthFlows LoadOAuthFlows(ParseNode node) | ||
| { | ||
| var mapNode = node.CheckMapNode("OAuthFlows"); |
There was a problem hiding this comment.
OAuthFlows [](start = 45, length = 10)
flows
There was a problem hiding this comment.
"OAuthFlows" -> "OAuthflows" ?
There was a problem hiding this comment.
Sorry. OAuthFlows is ok.
|
|
||
| public static OpenApiOAuthFlows LoadOAuthFlows(ParseNode node) | ||
| { | ||
| var mapNode = node.CheckMapNode("OAuthFlows"); |
There was a problem hiding this comment.
OAuthFlows [](start = 45, length = 10)
flows
There was a problem hiding this comment.
Actually, ignore my comment. I think your existing code "OAuthFlows" is okay here.
|
That's fine. I think a lot of things will have to change for the V2 builder. I don't think it's correct at the moment. In reply to: 338807100 [](ancestors = 338807100) |
| { | ||
| var mapNode = node.CheckMapNode("OAuthFlows"); | ||
|
|
||
| var oauthFlows = new OpenApiOAuthFlows(); |
There was a problem hiding this comment.
oauthFlows [](start = 16, length = 10)
Correct casing here should be "oAuthFlows"
|
You mean to change:
|
|
Ignore that comment. I misunderstood how that string is used. OAuthFlows is ok. In reply to: 338808548 [](ancestors = 338808548) |
|
For the security scheme type, the spec says:
So, I think enum type is necessary to narrow the accept value for the type. What do you think? |
|
@xuzhg See the "in" parameter of ParameterObject in V3Builder on how to use Enum in the builder. |
|
@xuzhg I forgot to mention this early on. In addition to the builder, you should also fix the WriteSecurityScheme in OpenApiV3Writer (and OpenApiV2Writer if you can). |
| { "scheme", (o,n) => o.Scheme = n.GetScalarValue() }, | ||
| { "bearerFormat", (o,n) => o.BearerFormat = n.GetScalarValue() }, | ||
| { "openIdConnectUrl", (o,n) => o.OpenIdConnectUrl = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute) }, | ||
| { "flows", (o,n) => o.Flows = LoadOAuthFlows(n) } |
There was a problem hiding this comment.
There is no such thing as a "flows" property in V2. There is a flow property as only a single flow can be described.
There is also no "openIdConnectUrl" or "bearerFormat". See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#securityDefinitionsObject
There was a problem hiding this comment.
Right. Those should be removed.
It's a little complicated now that we try to deserialize V2 doc into our model (which is closely based on V3), but there's a nice way to do it for this I think.
Keep the model as what Sam has now (commit 2). The authorizationUrl, tokenUrl, and scopes read from the document should be populated in the OpenApiOAuthFlow object and assigned to the right field in OpenApiOAuthFlows object based on value in flow
|
Would you share your approve here? I will continue on |
|
@xuzhg I would say you need to fix WriteSecurityScheme in OpenApiV3Writer and OpenApiV2Writer first. Otherwise, the change doesn't seem complete to me, and the state of the writer/model will be unsynced. |
|
Oh, yes. I am working on it. |
|
@PerthCharern see the latest commit. @darrelmiller are you working on the writer stuff? It seems that I have to duplicate a lot of codes. |
| private static void WriteValue(IOpenApiWriter writer, string value) | ||
| { | ||
| writer.WriteValue(value); | ||
| } |
There was a problem hiding this comment.
V2 doesn't have this structure.
I suggest this: Read the object in Flows (if more than one object exist, arbitrarily choose one), and then populate the SecurityScheme object with the info from there.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#securitySchemeObject
|
|
||
| /// <summary> | ||
| /// REQUIRED. The location of the API key | ||
| /// </summary> |
There was a problem hiding this comment.
InEnum [](start = 15, length = 6)
The InEnum is used in multiple classes now. I'd take out its definition from Parameter object and put in its own file.
There was a problem hiding this comment.
I think it's ok to be in the OpenApiParameter.cs. If you do think it should be in a separate file, We can do it later.
There was a problem hiding this comment.
Why should it be in OpenApiParameter.cs when it's used in multiple places? #Closed
| private static void WriteValue(IOpenApiWriter writer, string value) | ||
| { | ||
| writer.WriteValue(value); | ||
| } |
There was a problem hiding this comment.
Can't we use writer.WriteValue above directly?
There was a problem hiding this comment.
no, the signature doesn't match.
There was a problem hiding this comment.
Use this:
(w, s) => w.WriteValue(s)
| writer.WriteEndObject(); | ||
| } | ||
|
|
||
| private static bool WriteOAuthFlow(IOpenApiWriter writer, OpenApiOAuthFlow oAuthFlow, string flow) |
There was a problem hiding this comment.
bool [](start = 23, length = 4)
This return type is not consistent with other WriteXXX method. I strongly discourage this to avoid confusion. #Closed
There was a problem hiding this comment.
When this is fixed, I'll approve. Please note that the V2 reader is still not correct, but that's an isolated issue that can be fixed later. #Closed
There was a problem hiding this comment.
@PerthCharern Ok. Got it. Please see the latest commits. #Closed
| WriteOAuthFlow(writer, securityScheme.Flows.AuthorizationCode, "accessCode"); | ||
| } | ||
| } | ||
| writer.WriteStringProperty("flow", "implicit"); |
There was a problem hiding this comment.
I don't like the codes here. :)
| /// <summary> | ||
| /// Exception type representing exceptions in the Open API library. | ||
| /// </summary> | ||
| public class OpenApiException : InvalidOperationException |
There was a problem hiding this comment.
InvalidOperationException [](start = 36, length = 25)
I think it's better that this inherits just Exception. OpenApiException is not really always about Operation, and it is a little misleading this way.
There was a problem hiding this comment.
Ok. I changed to "Exception"
…um to individual file
…8d61-10c9af657b14 Add support for document $self property (OAI 3.2.0)
add:
OpenApiOAuthFlow
OpenApiOAuthFlows
Modify: OpenApiSecurityScheme.
It seems the OpenApiSecurityScheme structure doesn't follow up the Spec. @darrelmiller