Skip to content

Handle parsing port in host when reading V2 - #289

Merged
Darrel (darrelmiller) merged 6 commits into
vnextfrom
dm/vnext/hostswithports
Jul 9, 2018
Merged

Darrel (darrelmiller) merged 6 commits into
vnextfrom
dm/vnext/hostswithports

Conversation

@darrelmiller

Copy link
Copy Markdown
Member

No description provided.

host = "//" + host; // The double slash prefix creates a relative url where the scheme is defined by the BaseUrl
}

int? port = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

int? [](start = 20, length = 4)

nullable not needed -- int.Parse(pieces.Last()) throws an error if pieces.Last() is not parsable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

PerthCharern I think my logic is correct here. If the host does not contain ":" then we won't try to call int.Parse(pieces.Last()) and therefore port will be null. I don't want to update uriBuilder.Port if port isn't specified because the URL should omit port.
If the host does contain ":" and the part after the colon is not a number, I'm ok with it throwing a parsing exception.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That makes sense.

@PerthCharern

Copy link
Copy Markdown
Contributor

Same changes as above needed here too?


Refers to: src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs:197 in dff6ff7. [](commit_id = dff6ff7, deletion_comment = False)

@PerthCharern PerthCharern left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🕐

@@ -149,39 +149,19 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
{

@PerthCharern PerthCharern Jul 9, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If schemes is set to an empty list, I think we should treat that in the same way as schemes being null, i.e. line 148 should be if (schemes != null && schemes.Count != 0)

Spec says:
If the schemes is not included, the default scheme to be used is the one used to access the Swagger definition itself.

The term "not included" is not really precisely defined, but I think it should also apply to an empty schemes list.

If we don't modify the if clause as above, we won't have any server when schemes is an empty list. When servers is an empty list, the V3 spec interprets it as a default url of /, which is something totally different.

@PerthCharern

Copy link
Copy Markdown
Contributor

I approved, but please see the above comment before checking in.

@darrelmiller
Darrel (darrelmiller) merged commit 5d92b29 into vnext Jul 9, 2018
@darrelmiller
Darrel (darrelmiller) deleted the dm/vnext/hostswithports branch July 9, 2018 14:27
@darrelmiller
Darrel (darrelmiller) restored the dm/vnext/hostswithports branch July 13, 2018 18:28
@darrelmiller
Darrel (darrelmiller) deleted the dm/vnext/hostswithports branch January 4, 2020 20:28
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.

2 participants