Skip to content

Comments

Add more missed objects in core#28

Merged
xuzhg merged 8 commits intomicrosoft:masterfrom
xuzhg:AddMoreMissingObjects
Oct 24, 2017
Merged

Add more missed objects in core#28
xuzhg merged 8 commits intomicrosoft:masterfrom
xuzhg:AddMoreMissingObjects

Conversation

@xuzhg
Copy link
Contributor

@xuzhg xuzhg commented Oct 23, 2017

add:

  1. OpenApiOAuthFlow

  2. OpenApiOAuthFlows

Modify: OpenApiSecurityScheme.

It seems the OpenApiSecurityScheme structure doesn't follow up the Spec. @darrelmiller

@msftclas
Copy link

@xuzhg,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

@@ -27,6 +27,14 @@ public class OpenApiSecurityScheme : IOpenApiReference, IOpenApiExtension
public Uri TokenUrl { get; set; }
public IDictionary<string,string> Scopes { get; set; }
Copy link
Contributor

@PerthCharern PerthCharern Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 should be removed since they belong in the OAuthFlow object, not here. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the new commit

@PerthCharern
Copy link
Contributor

PerthCharern commented Oct 23, 2017

public class OpenApiSecurityScheme : IOpenApiReference, IOpenApiExtension
{
public string Key { get; set; }
public string Type { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string [](start = 15, length = 6)

SecuritySchemeTypeKind ?

Copy link
Contributor Author

@xuzhg xuzhg Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) 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.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 23, 2017

@PerthCharern

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OAuthFlows [](start = 45, length = 10)

flows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"OAuthFlows" -> "OAuthflows" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. OAuthFlows is ok.


public static OpenApiOAuthFlows LoadOAuthFlows(ParseNode node)
{
var mapNode = node.CheckMapNode("OAuthFlows");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OAuthFlows [](start = 45, length = 10)

flows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, ignore my comment. I think your existing code "OAuthFlows" is okay here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@PerthCharern
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oauthFlows [](start = 16, length = 10)

Correct casing here should be "oAuthFlows"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 23, 2017

You mean to change:
var mapNode = node.CheckMapNode("OAuthFlows");
to:

var mapNode = node.CheckMapNode("flows");

@PerthCharern
Copy link
Contributor

Ignore that comment. I misunderstood how that string is used. OAuthFlows is ok.


In reply to: 338808548 [](ancestors = 338808548)

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 23, 2017

For the security scheme type, the spec says:

type string Any REQUIRED. The type of the security scheme. Valid values are "apiKey", "http", "oauth2", "openIdConnect".

So, I think enum type is necessary to narrow the accept value for the type. What do you think?
But, so far, I don't know how to use it in the Builder. so, leave it in code. Let me figure out it later.

@PerthCharern
Copy link
Contributor

@xuzhg See the "in" parameter of ParameterObject in V3Builder on how to use Enum in the builder.

@PerthCharern
Copy link
Contributor

@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) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 23, 2017

Would you share your approve here? I will continue on

@PerthCharern
Copy link
Contributor

@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.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 23, 2017

Oh, yes. I am working on it.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 23, 2017

@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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my next commit.


/// <summary>
/// REQUIRED. The location of the API key
/// </summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@PerthCharern PerthCharern Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use writer.WriteValue above directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the signature doesn't match.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this:

(w, s) => w.WriteValue(s)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. thanks.

writer.WriteEndObject();
}

private static bool WriteOAuthFlow(IOpenApiWriter writer, OpenApiOAuthFlow oAuthFlow, string flow)
Copy link
Contributor

@PerthCharern PerthCharern Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool [](start = 23, length = 4)

This return type is not consistent with other WriteXXX method. I strongly discourage this to avoid confusion. #Closed

Copy link
Contributor

@PerthCharern PerthCharern Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@xuzhg xuzhg Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PerthCharern Ok. Got it. Please see the latest commits. #Closed

WriteOAuthFlow(writer, securityScheme.Flows.AuthorizationCode, "accessCode");
}
}
writer.WriteStringProperty("flow", "implicit");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the codes here. :)

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 24, 2017

@PerthCharern

/// <summary>
/// Exception type representing exceptions in the Open API library.
/// </summary>
public class OpenApiException : InvalidOperationException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I changed to "Exception"

Copy link
Contributor

@PerthCharern PerthCharern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@xuzhg xuzhg merged commit 256d86f into microsoft:master Oct 24, 2017
baywet added a commit that referenced this pull request Nov 11, 2025
…8d61-10c9af657b14

Add support for document $self property (OAI 3.2.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants