Skip to content

[PM-6170] Explore making responses required and nullable#60

Open
lizard-boy wants to merge 2 commits into
mainfrom
ps/explore-required
Open

[PM-6170] Explore making responses required and nullable#60
lizard-boy wants to merge 2 commits into
mainfrom
ps/explore-required

Conversation

@lizard-boy

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

Copy link
Copy Markdown

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

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

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
Copy Markdown

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 DateTime RevisionDate { get; }

public IEnumerable<SecretResponseInnerProject> Projects { get; set; }
public IEnumerable<SecretResponseInnerProject>? Projects { get; init; }

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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