Skip to content

Conversation

@MazZzDaI
Copy link

@MazZzDaI MazZzDaI commented Jan 9, 2023

Fix of the #1124 issue.

Overload added for Microsoft.OpenApi.Hidi/OpenApiService.cs/ApplyFilter to accept both string and stream variables.

…because ApplyFilter expects a local file but not a URL address microsoft#1124
@MazZzDaI
Copy link
Author

MazZzDaI commented Jan 9, 2023

@microsoft-github-policy-service agree [company="Olk inc."]

@MazZzDaI
Copy link
Author

MazZzDaI commented Jan 9, 2023

@microsoft-github-policy-service agree company="Olk inc."

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, here are a couple of comments to help improve it

{
XslCompiledTransform transform = GetFilterTransform();
stream = ApplyFilter(csdl, csdlFilter, transform);
stream = csdl.StartsWith("http") ? ApplyFilter(stream, csdlFilter, transform) : ApplyFilter(csdl, csdlFilter, transform);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stream = csdl.StartsWith("http") ? ApplyFilter(stream, csdlFilter, transform) : ApplyFilter(csdl, csdlFilter, transform);
stream = csdl.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? ApplyFilter(new StreamReader(stream), csdlFilter, transform) : ApplyFilter(new StreamReader(csdl), csdlFilter, transform);

Copy link
Member

@darrelmiller darrelmiller Jan 13, 2023

Choose a reason for hiding this comment

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

The original code here seems wrong. GetStream does all the logic to determine if stream is coming from a file or via HTTP. Currently the code is getting the stream and then ignoring it if there is a filter. The solution should be to change ApplyFilter to just accept the stream that comes from GetStream. And the case-insensitive check needs to be added to GetStream.

I'm not sure why the OP closed the PR. This seems like a good thing to fix.

Comment on lines +252 to +263
private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslCompiledTransform transform)
{
StreamReader inputReader = new(csdl);
return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform);
}

private static Stream ApplyFilter(Stream csdlStream, string entitySetOrSingleton, XslCompiledTransform transform)
{
StreamReader inputReader = new(csdlStream);
return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform);
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslCompiledTransform transform)
{
StreamReader inputReader = new(csdl);
return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform);
}
private static Stream ApplyFilter(Stream csdlStream, string entitySetOrSingleton, XslCompiledTransform transform)
{
StreamReader inputReader = new(csdlStream);
return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform);
}

}

private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslCompiledTransform transform)
private static Stream ApplyFilterForStreamReader(StreamReader inputReader, string entitySetOrSingleton, XslCompiledTransform transform)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private static Stream ApplyFilterForStreamReader(StreamReader inputReader, string entitySetOrSingleton, XslCompiledTransform transform)
private static Stream ApplyFilter(StreamReader inputReader, string entitySetOrSingleton, XslCompiledTransform transform)

{
StreamReader inputReader = new(csdlStream);
return ApplyFilterForStreamReader(inputReader, entitySetOrSingleton, transform);
}

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable

Disposable 'StreamReader' is created but not disposed.

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable

Disposable 'StreamReader' is created but not disposed.
@MazZzDaI MazZzDaI closed this Jan 10, 2023
@baywet
Copy link
Member

baywet commented Jan 13, 2023

@MazZzDaI is there any specific reason why you closed that PR?

@MazZzDaI MazZzDaI reopened this Jan 13, 2023
@darrelmiller
Copy link
Member

I was able to resolve this issue in PR #1113 in this commit 7aac03f
I also added support for using CSDL with the show command.

@darrelmiller
Copy link
Member

Thank you @MazZzDaI for identifying this issue. PR #1113 has the fixes you are looking for and other related improvements.

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.

3 participants