Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lizard-boy
Copy link

@lizard-boy lizard-boy commented Oct 19, 2024

Type of change

- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

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

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

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.

  • Added RequireNotNullableSchemaFilter in src/SharedWeb/Swagger/RequireNotNullableSchemaFilter.cs to improve OpenAPI schema generation for non-nullable properties
  • Modified src/Api/SecretsManager/Models/Response/BaseSecretResponseModel.cs to use nullable reference types and make properties read-only where appropriate
  • Removed parameterless constructor from src/Api/SecretsManager/Models/Response/SecretResponseModel.cs, potentially impacting default initialization
  • Updated Swagger configuration in src/Api/Utilities/ServiceCollectionExtensions.cs to include the new schema filter for enhanced API documentation

Copy link

@greptile-apps greptile-apps bot left a 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

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; }
Copy link

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; }
Copy link

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

Comment on lines +7 to +9
/// <summary>
///
/// </summary>
Copy link

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

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();
Copy link

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

Comment on lines +54 to +59
var fieldType = field switch
{
FieldInfo fieldInfo => fieldInfo.FieldType,
PropertyInfo propertyInfo => propertyInfo.PropertyType,
_ => throw new NotSupportedException(),
};
Copy link

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

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.

2 participants