[PM-6170] Explore making responses required and nullable#60
Open
lizard-boy wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
4 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile
Comment on lines
+33
to
+37
| public string? Key { get; } | ||
|
|
||
| public string Value { get; set; } | ||
| public string? Value { get; } | ||
|
|
||
| public string Note { get; set; } | ||
| public string? Note { get; } |
There was a problem hiding this comment.
style: Consider if these fields should be nullable. If they are required, remove the '?'
| public DateTime RevisionDate { get; } | ||
|
|
||
| public IEnumerable<SecretResponseInnerProject> Projects { get; set; } | ||
| public IEnumerable<SecretResponseInnerProject>? Projects { get; init; } |
There was a problem hiding this comment.
logic: Using 'init' here might cause issues if Projects need to be modified after initialization
Comment on lines
+7
to
+9
| /// <summary> | ||
| /// | ||
| /// </summary> |
There was a problem hiding this comment.
style: Add a brief description of the class's purpose in the summary
Comment on lines
+24
to
+27
| var notNullableProperties = schema | ||
| .Properties | ||
| .Where(x => !x.Value.Nullable && x.Value.Default == default && !schema.Required.Contains(x.Key)) | ||
| .ToList(); |
There was a problem hiding this comment.
style: Consider using HashSet<string> for schema.Required to improve lookup performance
Comment on lines
+54
to
+59
| var fieldType = field switch | ||
| { | ||
| FieldInfo fieldInfo => fieldInfo.FieldType, | ||
| PropertyInfo propertyInfo => propertyInfo.PropertyType, | ||
| _ => throw new NotSupportedException(), | ||
| }; |
There was a problem hiding this comment.
logic: Handle potential NotSupportedException to prevent unexpected runtime errors
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Type of change
Objective
Explore if we can annotate required fields in responses. We could perhaps take advantage of nullable fields instead but that would require a custom filter and Open API separates nullable from required
Before you submit
dotnet format --verify-no-changes) (required)Greptile Summary
This pull request enhances type safety and API documentation by introducing nullable reference types and a custom schema filter for OpenAPI in the grepdemos/server repository.
RequireNotNullableSchemaFilterinsrc/SharedWeb/Swagger/RequireNotNullableSchemaFilter.csto improve OpenAPI schema generation for non-nullable propertiessrc/Api/SecretsManager/Models/Response/BaseSecretResponseModel.csto use nullable reference types and make properties read-only where appropriatesrc/Api/SecretsManager/Models/Response/SecretResponseModel.cs, potentially impacting default initializationsrc/Api/Utilities/ServiceCollectionExtensions.csto include the new schema filter for enhanced API documentation