-
Notifications
You must be signed in to change notification settings - Fork 279
[OpenAPI] Add "type" property with value "object" response schema to fix Infragistics AppBuilder tooling #2283
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/Service.Tests/OpenApiDocumentor/DocumentVerbosityTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Azure.DataApiBuilder.Config.ObjectModel; | ||
using Microsoft.OpenApi.Models; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Azure.DataApiBuilder.Service.Tests.OpenApiIntegration | ||
{ | ||
/// <summary> | ||
/// Integration tests validating that expected properties are present in the OpenApiDocument object. | ||
/// </summary> | ||
[TestCategory(TestCategory.MSSQL)] | ||
[TestClass] | ||
public class DocumentVerbosityTests | ||
{ | ||
private const string CUSTOM_CONFIG = "doc-verbosity.MsSql.json"; | ||
private const string MSSQL_ENVIRONMENT = TestCategory.MSSQL; | ||
private const string MISSING_TYPE_PROPERTY_ERROR = "Response object schema does not include a 'type' property."; | ||
private const string UNEXPECTED_CONTENTS_ERROR = "Unexpected number of response objects to validate."; | ||
|
||
/// <summary> | ||
/// Validates that for the Book entity, 7 response object schemas generated by OpenApiDocumentor | ||
/// contain a 'type' property with value 'object'. | ||
/// | ||
/// Two paths: | ||
/// - "/Books/id/{id}" | ||
/// - 4 operations GET PUT PATCH DELETE | ||
/// - Validate responses that return result contents: | ||
/// GET (200), PUT (200, 201), PATCH (200, 201) | ||
/// - "/Books" | ||
/// - 2 operations GET(all) POST | ||
/// - Validate responses that return result contents: | ||
/// GET (200), POST (201) | ||
/// </summary> | ||
[TestMethod] | ||
public async Task ResponseObjectSchemaIncludesTypeProperty() | ||
{ | ||
// Arrange | ||
Entity entity = new( | ||
Source: new(Object: "books", EntitySourceType.Table, null, null), | ||
GraphQL: new(Singular: null, Plural: null, Enabled: false), | ||
Rest: new(Methods: EntityRestOptions.DEFAULT_SUPPORTED_VERBS), | ||
Permissions: OpenApiTestBootstrap.CreateBasicPermissions(), | ||
Mappings: null, | ||
Relationships: null); | ||
|
||
Dictionary<string, Entity> entities = new() | ||
{ | ||
{ "Book", entity } | ||
}; | ||
|
||
RuntimeEntities runtimeEntities = new(entities); | ||
|
||
// Act - Create OpenApi document | ||
OpenApiDocument openApiDocument = await OpenApiTestBootstrap.GenerateOpenApiDocumentAsync( | ||
runtimeEntities: runtimeEntities, | ||
configFileName: CUSTOM_CONFIG, | ||
databaseEnvironment: MSSQL_ENVIRONMENT); | ||
|
||
// Assert - Validate responses that return result contents: 200, 201 | ||
List<OpenApiResponse> responses = openApiDocument.Paths.Values | ||
.SelectMany(pathObject => pathObject.Operations.Values) | ||
.SelectMany(operation => operation.Responses) | ||
// Responses Dictionary: Key: HttpStatusCode, Value: OpenApiResponse | ||
.Where(pair => pair.Key == "200" || pair.Key == "201") | ||
.Select(pair => pair.Value) | ||
.ToList(); | ||
|
||
// Validate that 7 response object schemas contain a 'type' property with value 'object' | ||
// Test summary describes all 7 expected responses. | ||
Assert.IsTrue( | ||
condition: responses.Count == 7, | ||
message: UNEXPECTED_CONTENTS_ERROR); | ||
|
||
foreach (OpenApiResponse response in responses) | ||
{ | ||
Assert.IsTrue( | ||
condition: response.Content["application/json"].Schema.Type == "object", | ||
message: MISSING_TYPE_PROPERTY_ERROR); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.