fixes a bug where OData Count path items would be missing from the description#141
fixes a bug where OData Count path items would be missing from the description#141
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>
| // 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.
If possible, let's keep it unchanged?
There was a problem hiding this comment.
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.
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.
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.
if(currentPath == null)
{
throw new ArgumentNullException(nameof(currentPath));
}
and, maybe to use Error.ArgumentNull(...) method?
| // for entity set, create a path with key and a $count path | ||
| if (entitySet != null) | ||
| { | ||
| count = _model.GetRecord<CountRestrictionsType>(entitySet, CapabilitiesConstants.CountRestrictions); |
There was a problem hiding this comment.
shall we add a config in the settings to allow/disallow the $count segment
There was a problem hiding this comment.
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.
the setting is already read in the CreateCountPath method
There was a problem hiding this comment.
if (setting.IncludeDollarCountPathSegments)
{
call CreateCountPath(...)
}
in the CreateCountPath()
{
Get CountRestirction()
then do something based on the CountRestriciton?
}
There was a problem hiding this comment.
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.
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.
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?
| "x-ms-docs-operation-type": "operation" | ||
| } | ||
| }, | ||
| "/City/$count": { |
There was a problem hiding this comment.
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.
city is actually also an entity set, arguably it should be named cities but I didn't want to impact the source file.
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.
IncludeDollarCountPathSegments -> EnableDollarCountPath
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. |
| .editorconfig = .editorconfig | ||
| EndProjectSection | ||
| EndProject | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tool", "tool", "{DE8F8E75-A119-4CF3-AFDD-4132B55DAE76}" |
There was a problem hiding this comment.
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.
Having it in the main solution makes f5 debug work for VS code
There was a problem hiding this comment.
Also enables static analysis and more for that project with CI
| // 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.
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.
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 && |
| /// </summary> | ||
| internal ODataSegment LastSecondSegment { get; set; } | ||
|
|
||
| private const int SecondLastSegmentIndex = 2; |
There was a problem hiding this comment.
insert a new line before and after
| { | ||
| Type = "integer", | ||
| Format = "int32" | ||
| OpenApiSchema schema = new() |
|
|
||
| /// <inheritdoc/> | ||
| protected override void SetOperations(OpenApiPathItem item) | ||
| /// <inheritdoc/> |
| // Arrange | ||
| IEdmModel model = GetInheritanceModel(string.Empty); | ||
| ODataPathProvider provider = new ODataPathProvider(); | ||
| var settings = new OpenApiConvertSettings { |
| "x-ms-docs-operation-type": "operation" | ||
| } | ||
| }, | ||
| "/City/$count": { |
|
@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