Skip to content

Conversation

@MaggieKimani1
Copy link
Contributor

@MaggieKimani1 MaggieKimani1 commented Nov 14, 2024

This PR:

  • Adds logic for inspecting the first character of the stream we receive during document loading to know whether its in JSON or YAML. This helps avoid a regression in functionality where users are required to pass the format of the document when loading an OpenAPI document
  • Replaces sync methods with async ones to prevent deadlocks
  • Passes a cancellation token to OpenApiModelFactory.GetStreamAsync to allow for cancellation of tasks/requests
  • Updates tests with new loading pattern

Fixes #1917, #1918

@MaggieKimani1 MaggieKimani1 marked this pull request as draft November 14, 2024 09:49
@MaggieKimani1 MaggieKimani1 marked this pull request as ready for review November 14, 2024 14:10
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
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 getting this started.
A couple of remarks

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
77.1% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

try
{
jsonNode = LoadJsonNodesFromYamlDocument(input);
jsonNode = await Task.Run(() => LoadJsonNodesFromYamlDocument(input));
Copy link
Member

Choose a reason for hiding this comment

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

why are we adding the task run here?

Copy link
Contributor Author

@MaggieKimani1 MaggieKimani1 Nov 19, 2024

Choose a reason for hiding this comment

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

The caller is async here

public static async Task<ReadFragmentResult<T>> LoadAsync<T>(Stream input,

And the interface method's equivalent in the JsonReader class is also async

public async Task<ReadFragmentResult<T>> ReadFragmentAsync<T>(TextReader input,

If I change this method's signature to be synchronous, I'll also need to update this JSON content to be read synchronously:

var content = await input.ReadToEndAsync();

@MaggieKimani1
Copy link
Contributor Author

@baywet just a head's up, the functionality on inspecting the input stream to determine the format might change based on my discussion with @darrelmiller here #1918 (comment)

@baywet
Copy link
Member

baywet commented Nov 19, 2024

@MaggieKimani1 are we going to implement those changes in this PR or in a subsequent one?

@MaggieKimani1
Copy link
Contributor Author

@MaggieKimani1 are we going to implement those changes in this PR or in a subsequent one?

I can implement it here so as not to lose the other changes on moving to async

Co-authored-by: Vincent Biret <vibiret@microsoft.com>
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.

v2 - We should NOT do sync over async

2 participants