Skip to content

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

Merged
merged 16 commits into from
Nov 24, 2021

Conversation

baywet
Copy link
Member

@baywet baywet commented Nov 22, 2021

  • pattern matching refactoring
  • adds launch configuration for update docs tool
  • adds update docs to solution file so debug works properly
  • code linting
  • code linting
  • fixes Count path segments are missing after translation #129 a bug where odata count paths would be missing from the description

TODO

@baywet baywet self-assigned this Nov 22, 2021
@baywet baywet linked an issue Nov 22, 2021 that may be closed by this pull request
@baywet baywet added this to the 1.0.10 milestone Nov 22, 2021
@baywet baywet force-pushed the bugifx/count-segments branch from d09c5e9 to 2335fdd Compare November 22, 2021 19:34
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>
@baywet baywet force-pushed the bugifx/count-segments branch from 2335fdd to 76cfc30 Compare November 22, 2021 19:42
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>
@baywet baywet marked this pull request as ready for review November 23, 2021 16:51
Base automatically changed from feature/net5 to master November 23, 2021 18:19
@baywet baywet enabled auto-merge November 23, 2021 18:20
@@ -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();
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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

Choose a reason for hiding this comment

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

make a better format

Copy link
Contributor

Choose a reason for hiding this comment

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

for others

Copy link
Member Author

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.

Copy link
Contributor

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

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

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

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?
}

Copy link
Member Author

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 &&
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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": {
Copy link
Contributor

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.

Copy link
Member Author

@baywet baywet Nov 23, 2021

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.

EdmEntitySet cities = new EdmEntitySet(entityContainer, "City", city);

Copy link
Contributor

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>
@baywet baywet requested a review from xuzhg November 23, 2021 18:41
@xuzhg
Copy link
Contributor

xuzhg commented Nov 23, 2021

I'd suggest some "rules" about "coding style":

  1. leave new T() unchanged to use new(), until we have whole separate PR to clean all.

  2. Insert white-line between paragraph.

  3. If (....) xxxx =>
    if (....)
    {
    ...
    }

    even it's only one line code.

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

Choose a reason for hiding this comment

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

IncludeDollarCountPathSegments -> EnableDollarCountPath

Copy link
Member Author

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>
@baywet
Copy link
Member Author

baywet commented Nov 23, 2021

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

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.

Copy link
Member Author

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

Copy link
Member Author

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

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

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 &&
Copy link
Contributor

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

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

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/>
Copy link
Contributor

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 {
Copy link
Contributor

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": {
Copy link
Contributor

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 baywet merged commit 2814714 into master Nov 24, 2021
@baywet baywet deleted the bugifx/count-segments branch November 24, 2021 01:41
@xuzhg
Copy link
Contributor

xuzhg commented Nov 24, 2021

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

@baywet
Copy link
Member Author

baywet commented Nov 24, 2021

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.

@baywet
Copy link
Member Author

baywet commented Nov 24, 2021

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

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.

Count path segments are missing after translation
2 participants