Skip to content

Comments

Integrate apis.guru directory of APIs to provide smoke test for library#220

Merged
darrelmiller merged 11 commits intomasterfrom
dm/smoketests2
Mar 21, 2018
Merged

Integrate apis.guru directory of APIs to provide smoke test for library#220
darrelmiller merged 11 commits intomasterfrom
dm/smoketests2

Conversation

@darrelmiller
Copy link
Member

@darrelmiller darrelmiller commented Mar 8, 2018

This PR also includes a bunch of fixes that prevent any of the Apis.guru descriptions from throwing exceptions.

Fixes #151

@darrelmiller darrelmiller requested a review from xuzhg March 8, 2018 15:27

return array;
}

Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

remove #Resolved

Copy link
Member Author

@darrelmiller darrelmiller Mar 9, 2018

Choose a reason for hiding this comment

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

Done #Resolved

Diagnostic.Errors.Add(
new OpenApiError("", $"{nodeName} must be a map/object at " + Context.GetLocation()));
throw new OpenApiException($"{nodeName} must be a map/object");
//Diagnostic.Errors.Add(
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

remove #Resolved

Copy link
Member Author

@darrelmiller darrelmiller Mar 12, 2018

Choose a reason for hiding this comment

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

Done #Resolved

{
Diagnostic.Errors.Add(
new OpenApiError("", $"{nodeName} must be a map/object at " + Context.GetLocation()));
throw new OpenApiException($"{nodeName} must be a map/object");
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

why change to throw exception? #Resolved

Copy link
Member Author

@darrelmiller darrelmiller Mar 9, 2018

Choose a reason for hiding this comment

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

Because it caused a cascade of errors as following code attempted to handle the null node. #Resolved


public virtual List<IOpenApiAny> CreateListOfAny()
{
throw new OpenApiException("Cannot create list of any from here");
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

Maybe it's better to throw "NotSupported" #WontFix

Copy link
Member Author

@darrelmiller darrelmiller Mar 12, 2018

Choose a reason for hiding this comment

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

It definitely could use a better description. However, I want this error to be aggregated in the errors collection. #Resolved

Copy link
Member Author

@darrelmiller darrelmiller Mar 12, 2018

Choose a reason for hiding this comment

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

I've cleaned up the descriptions a bit so they are consistent. #Resolved

try
{
return _currentDocument.ResolveReference(reference) as T;
} catch(OpenApiException ex)
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

separate to different line #Resolved

o.Components.RequestBodies = n.CreateMapWithReference(ReferenceType.RequestBody, p =>
{
var parameter = LoadParameter(p, evenBody: true);
if (parameter.In == null) {
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

separate to different line #Resolved

{
case ReferenceType.Schema:
return this.Components.Schemas[reference.Id];
return this.Components.Schemas[reference.Id];
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

revert #Resolved

@@ -0,0 +1,107 @@
using Microsoft.OpenApi.Readers;
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

copyright head #Resolved

using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

sort the using #Resolved


public ApisGuruTests(ITestOutputHelper output)
{

Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

remove empty line #Resolved

AutomaticDecompression = DecompressionMethods.GZip
});

private readonly ITestOutputHelper output;
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

name it as "_output", same as _httpClient? #Resolved

[Collection("DefaultSettings")]
public class ApisGuruTests
{
private static HttpClient _httpClient = new HttpClient(new HttpClientHandler() {
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

If you have the static constructor, I think it's better to move the assignment to the static constructor. #Resolved


public static IEnumerable<object[]> GetSchemas()
{

Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

remove empty line #Resolved

return jToken;
}
}

Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

remove unused empty line #Resolved

{
output.WriteLine($"Errors parsing {url}");
output.WriteLine(String.Join("\n", diagnostic.Errors));
// Assert.True(false); // Uncomment to identify descriptions with errors.
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

remove #Resolved

Copy link
Member Author

@darrelmiller darrelmiller Mar 12, 2018

Choose a reason for hiding this comment

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

I'd like to leave that. Once we ensure that the smoketests are not run during the automatic build, I think we might re-enable this. #WontFix

[MemberData(nameof(GetSchemas))]
public async Task EnsureThatICouldParse(string url)
{
var stopwatch = new Stopwatch();
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

move the declaration & assignment at the first using of this stopwatch. #Resolved

var response = await _httpClient.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
output.WriteLine($"Couldn't load {url}");
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

It's a test case. it can't understand to output the error message and returns directly.
Please use the assert clause to test the status code.
#WontFix

Copy link
Member Author

@darrelmiller darrelmiller Mar 9, 2018

Choose a reason for hiding this comment

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

These are smoke tests and shouldn't be treated the same way as integration tests. If a URL cannot be resolved from apis.guru that is not a failure of our library, but an issue with an external directory, so I wouldn't want to flag it as an error. #Closed


stopwatch.Start();

var reader = new OpenApiStreamReader(new OpenApiReaderSettings() {
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

what's the meaning of empty {} #Resolved

Copy link
Member Author

@darrelmiller darrelmiller Mar 12, 2018

Choose a reason for hiding this comment

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

Removed. #Resolved

});
var openApiDocument = reader.Read(stream, out var diagnostic);

if (diagnostic.Errors.Count > 0)
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

same as above, it's a test case, please use the assert clause to test the result. #WontFix

Copy link
Member Author

@darrelmiller darrelmiller Mar 9, 2018

Choose a reason for hiding this comment

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

Asserting on the existence of errors in the collection would give erroneous results as many of the OpenAPI descriptions contain spec violations. #Closed

Copy link

@MikeRalphson MikeRalphson Mar 12, 2018

Choose a reason for hiding this comment

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

Hi @darrelmiller - we use multiple validators on the APIs,guru collection, so if this applies to us, we'd certainly appreciate feedback on the spec violations when you have time. #Closed

Copy link
Member Author

@darrelmiller darrelmiller Mar 12, 2018

Choose a reason for hiding this comment

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

@MikeRalphson The two main errors that I am seeing are invalid characters in the component keys and schemas that have a type as an array. I'll get you a more complete list. Also, I know many of the Azure documents have description properties as peers of a $ref. #Resolved

Copy link

@MikeRalphson MikeRalphson Mar 12, 2018

Choose a reason for hiding this comment

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

@darrelmiller many thanks! #Resolved

// Resolve References if requested
switch (_settings.ReferenceResolution)
{
case ReferenceResolutionSetting.ResolveAllReferences:
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

maybe to use the "default: throw ..." is better. #WontFix

Copy link
Member Author

@darrelmiller darrelmiller Mar 9, 2018

Choose a reason for hiding this comment

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

This chunk of code is going to change fairly significantly when adding support for resolving external files, so I'll review this in a future PR. #Closed


public override List<IOpenApiAny> CreateListOfAny()
{
var yamlSequence = _nodeList;
Copy link
Contributor

@xuzhg xuzhg Mar 9, 2018

Choose a reason for hiding this comment

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

yamlSequence is not necessary. Why can't use the _nodeList directly? #Resolved

Copy link
Member Author

@darrelmiller darrelmiller Mar 9, 2018

Choose a reason for hiding this comment

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

Fixed. #Resolved

@darrelmiller
Copy link
Member Author

@PerthCharern Can I get a quick review? I'd like to merge this into the release for @scott-lin

@darrelmiller darrelmiller merged commit bd61abd into master Mar 21, 2018
@darrelmiller darrelmiller deleted the dm/smoketests2 branch March 21, 2018 02:14
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.

Handling body and form parameter reference for V2

3 participants