-
Notifications
You must be signed in to change notification settings - Fork 65
makes collection responses reusable #157
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
16 commits
Select commit
Hold shift + click to select a range
71c3441
- moves the count response to a component
baywet 5cb18b7
- updates integration test files for count response reuse
baywet 3cf4404
- moves collections responses to schemas
baywet b587843
- updates integrations test files for collection resposne schemas
baywet fabcd9f
- makes collections responses resuable
baywet b1f356d
- updates integration test files for reusable collection responses
baywet 2bf5570
- adds support for response reuse for entityset
baywet b1d2f7f
- updates integration test files for response reuse for entityset
baywet 582d389
- fixes a bug where collection cast response would be wrong
baywet 16a306c
- updates integration test files for collection cast response reusable
baywet 1b20d9a
- adds response reuse for ref
baywet 6d165e5
- updates integration test files for ref response reuse
baywet 38edb5a
- updates unit tests after response reuse
baywet 274e559
- updates integration test files for response reuse
baywet ae866e7
- adds unit tests for collection responses reuse
baywet e93b7a4
- pr feedback
baywet 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
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 |
---|---|---|
|
@@ -62,10 +62,27 @@ public static IDictionary<string, OpenApiResponse> CreateResponses(this ODataCon | |
{ | ||
Utils.CheckArgumentNull(context, nameof(context)); | ||
|
||
return new Dictionary<string, OpenApiResponse> | ||
var responses = new Dictionary<string, OpenApiResponse> | ||
{ | ||
{ "error", CreateErrorResponse() } | ||
}; | ||
|
||
if(context.Settings.EnableDollarCountPath) | ||
{ | ||
responses[Constants.DollarCountSchemaName] = CreateCountResponse(); | ||
} | ||
|
||
responses = responses.Concat(context.GetAllCollectionEntityTypes() | ||
.Select(x => new KeyValuePair<string, OpenApiResponse>( | ||
$"{(x is IEdmEntityType eType ? eType.FullName() : x.FullTypeName())}{Constants.CollectionSchemaSuffix}", | ||
CreateCollectionResponse(x))) | ||
.Where(x => !responses.ContainsKey(x.Key))) | ||
.ToDictionary(x => x.Key, x => x.Value); | ||
|
||
if(context.HasAnyNonContainedCollections()) | ||
responses[$"String{Constants.CollectionSchemaSuffix}"] = CreateCollectionResponse("String"); | ||
|
||
return responses; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -165,6 +182,61 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp | |
return responses; | ||
} | ||
|
||
private static OpenApiResponse CreateCollectionResponse(IEdmStructuredType structuredType) | ||
{ | ||
var entityType = structuredType as IEdmEntityType; | ||
return CreateCollectionResponse(entityType?.FullName() ?? structuredType.FullTypeName()); | ||
} | ||
private static OpenApiResponse CreateCollectionResponse(string typeName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be remove this private static method and put the codes directly into the above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No because this method is called twice |
||
{ | ||
return new OpenApiResponse | ||
{ | ||
Description = "Retrieved collection", | ||
Content = new Dictionary<string, OpenApiMediaType> | ||
{ | ||
{ | ||
Constants.ApplicationJsonMediaType, | ||
new OpenApiMediaType | ||
{ | ||
Schema = new OpenApiSchema | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.Schema, | ||
Id = $"{typeName}{Constants.CollectionSchemaSuffix}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private static OpenApiResponse CreateCountResponse() | ||
{ | ||
OpenApiSchema schema = new() | ||
{ | ||
Reference = new() { | ||
Type = ReferenceType.Schema, | ||
Id = Constants.DollarCountSchemaName | ||
} | ||
}; | ||
return new OpenApiResponse | ||
{ | ||
Description = "The count of the resource", | ||
Content = new Dictionary<string, OpenApiMediaType> | ||
{ | ||
{ | ||
"text/plain", | ||
new OpenApiMediaType | ||
{ | ||
Schema = schema | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private static OpenApiResponse CreateErrorResponse() | ||
{ | ||
return new OpenApiResponse | ||
|
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
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
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
Oops, something went wrong.
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.