-
Notifications
You must be signed in to change notification settings - Fork 65
fixes a bug where OData Count path items would be missing from the description #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d09c5e9
to
2335fdd
Compare
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
…description Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
2335fdd
to
76cfc30
Compare
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
…e unique Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
…nt path Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@@ -146,8 +146,8 @@ public string GetPathItemName(OpenApiConvertSettings settings) | |||
|
|||
// From Open API spec, parameter name is case sensitive, so don't use the IgnoreCase HashSet. | |||
// HashSet<string> parameters = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | |||
HashSet<string> parameters = new HashSet<string>(); | |||
StringBuilder sb = new StringBuilder(); | |||
HashSet<string> parameters = new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, let's keep it unchanged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the harm in using the newer syntax that saves code writing and removes squiggles when we're editing the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can save a lot of time. It's the same as:
var parameters = new HashSet<string>();
Actually, it's no harm, but for readability.
/// <param name="currentPath">The current OData path.</param> | ||
/// <param name="convertSettings">The settings for the current conversion.</param> | ||
private void CreateCountPath(ODataPath currentPath, OpenApiConvertSettings convertSettings) { | ||
if(currentPath == null) throw new ArgumentNullException(nameof(currentPath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make a better format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that you're referring to the curly brace not being on the next line. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(currentPath == null)
{
throw new ArgumentNullException(nameof(currentPath));
}
and, maybe to use Error.ArgumentNull(...) method?
if (entitySet != null) | ||
{ | ||
count = _model.GetRecord<CountRestrictionsType>(entitySet, CapabilitiesConstants.CountRestrictions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we add a config in the settings to allow/disallow the $count segment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see that. IncludeDollarCountPathSegments.
But, why don't you check it then call "GetRecord". If it's not allowed, we don't need to call "GetRecord".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the setting is already read in the CreateCountPath
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (setting.IncludeDollarCountPathSegments)
{
call CreateCountPath(...)
}
in the CreateCountPath()
{
Get CountRestirction()
then do something based on the CountRestriciton?
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why read the setting in the before the call to CreateCountPath? It's only going to lead to code/logic duplication.
} | ||
|
||
return null; | ||
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of these code change are not related to the $count path feature.
Maybe better to have a separate PR for clarification, better understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to keep that in mind for the next pull requests. I usually try to fix warnings/suggestions on the files I touch, but not the ones I don't touch. As this is my first actual PR in this codebase, I was exploring the code to understand how things work and I made a few modifications at other places. Since the work was already done, and it's only syntax change that doesn't impact the behavior, I suggest we make a one time exception. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, Ok
@@ -293,6 +293,27 @@ | |||
"x-ms-docs-operation-type": "operation" | |||
} | |||
}, | |||
"/City/$count": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
City looks like a singleton.
It's not allowed to have $count after a single navigation property or singleton.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
city is actually also an entity set, arguably it should be named cities but I didn't want to impact the source file.
OpenAPI.NET.OData/test/Microsoft.OpenAPI.OData.Reader.Tests/Common/EdmModelHelper.cs
Line 273 in 1342794
EdmEntitySet cities = new EdmEntitySet(entityContainer, "City", city); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok. My error
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
I'd suggest some "rules" about "coding style":
|
/// <summary> | ||
/// Gets/sets a value indicating whether or not add OData $count segments in the description for collections. | ||
/// </summary> | ||
public bool IncludeDollarCountPathSegments { get; set; } = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IncludeDollarCountPathSegments -> EnableDollarCountPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@xuzhg I'm going to push back on those rules until we have a comprehensive editorconfig + linter to enforce them (and resolve them automatically). It's a poor use of our time to enforce those things manually. And I do agree on the fact that the bulk of changes + configuration should happen in a separate PR. |
@@ -16,6 +16,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution | |||
.editorconfig = .editorconfig | |||
EndProjectSection | |||
EndProject | |||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tool", "tool", "{DE8F8E75-A119-4CF3-AFDD-4132B55DAE76}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I have a separate solution for updateDocs.
Do you think it's convenient to have it into the main solution? Because it's only a helper tooling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having it in the main solution makes f5 debug work for VS code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also enables static analysis and more for that project with CI
@@ -146,8 +146,8 @@ public string GetPathItemName(OpenApiConvertSettings settings) | |||
|
|||
// From Open API spec, parameter name is case sensitive, so don't use the IgnoreCase HashSet. | |||
// HashSet<string> parameters = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | |||
HashSet<string> parameters = new HashSet<string>(); | |||
StringBuilder sb = new StringBuilder(); | |||
HashSet<string> parameters = new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can save a lot of time. It's the same as:
var parameters = new HashSet<string>();
Actually, it's no harm, but for readability.
/// <param name="currentPath">The current OData path.</param> | ||
/// <param name="convertSettings">The settings for the current conversion.</param> | ||
private void CreateCountPath(ODataPath currentPath, OpenApiConvertSettings convertSettings) { | ||
if(currentPath == null) throw new ArgumentNullException(nameof(currentPath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(currentPath == null)
{
throw new ArgumentNullException(nameof(currentPath));
}
and, maybe to use Error.ArgumentNull(...) method?
} | ||
|
||
return null; | ||
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, Ok
@@ -25,15 +25,16 @@ internal class DollarCountGetOperationHandler : OperationHandler | |||
/// this segment could be "entity set", "Collection property", "Composable function whose return is collection",etc. | |||
/// </summary> | |||
internal ODataSegment LastSecondSegment { get; set; } | |||
|
|||
private const int SecondLastSegmentIndex = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insert a new line before and after
{ | ||
Type = "integer", | ||
Format = "int32" | ||
OpenApiSchema schema = new() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align the codes
@@ -46,8 +45,8 @@ internal class NavigationPropertyPathItemHandler : PathItemHandler | |||
/// </summary> | |||
protected bool LastSegmentIsRefSegment { get; private set; } | |||
|
|||
/// <inheritdoc/> | |||
protected override void SetOperations(OpenApiPathItem item) | |||
/// <inheritdoc/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align
// Arrange | ||
IEdmModel model = GetInheritanceModel(string.Empty); | ||
ODataPathProvider provider = new ODataPathProvider(); | ||
var settings = new OpenApiConvertSettings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ in a separate linke
@@ -293,6 +293,27 @@ | |||
"x-ms-docs-operation-type": "operation" | |||
} | |||
}, | |||
"/City/$count": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok. My error
@baywet I don't like the auto-merge setting. Should turn it off. Besides, we should merge the changes squash. It's better for one feature/one fix into one commit. |
Squash: sure we can disable merge and rebase in the branch policy if you prefer linear history. Although it leads to more conflicts. Auto-merge: what's the issue with it? It saves time to everyone. |
And I can't reply to your var comment for some reason. But I saw the style was not to use var here, I usually go with the var syntax to avoid duplicating the type name |
TODO