-
Notifications
You must be signed in to change notification settings - Fork 0
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
[PM-6170] Explore making responses required and nullable #60
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider if these fields should be nullable. If they are required, remove the '?'
|
||
public IEnumerable<SecretResponseInnerProject> Projects { get; set; } | ||
public IEnumerable<SecretResponseInnerProject>? Projects { get; init; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Using 'init' here might cause issues if Projects need to be modified after initialization
/// <summary> | ||
/// | ||
/// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Add a brief description of the class's purpose in the summary
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using HashSet<string>
for schema.Required
to improve lookup performance
var fieldType = field switch | ||
{ | ||
FieldInfo fieldInfo => fieldInfo.FieldType, | ||
PropertyInfo propertyInfo => propertyInfo.PropertyType, | ||
_ => throw new NotSupportedException(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Handle potential NotSupportedException
to prevent unexpected runtime errors
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.
RequireNotNullableSchemaFilter
insrc/SharedWeb/Swagger/RequireNotNullableSchemaFilter.cs
to improve OpenAPI schema generation for non-nullable propertiessrc/Api/SecretsManager/Models/Response/BaseSecretResponseModel.cs
to use nullable reference types and make properties read-only where appropriatesrc/Api/SecretsManager/Models/Response/SecretResponseModel.cs
, potentially impacting default initializationsrc/Api/Utilities/ServiceCollectionExtensions.cs
to include the new schema filter for enhanced API documentation