Skip to content

Add lint for nullable request and response bodies - #32

Merged
sunshowers merged 2 commits into
mainfrom
sunshowers/spr/add-lint-for-nullable-request-and-response-bodies
Nov 1, 2026
Merged

sunshowers merged 2 commits into
mainfrom
sunshowers/spr/add-lint-for-nullable-request-and-response-bodies

Conversation

@sunshowers

Copy link
Copy Markdown
Contributor

This is not idiomatic -- see oxidecomputer/dropshot#669 and oxidecomputer/omicron#11623 for more discussion.

Comment thread README.md Outdated
Comment on lines +294 to +295
Alternatively, if `None` means that the resource doesn't exist, return a 404 Not
Found error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might put this case first?

If None is meant to indicate that the resource doesn't exist, consider returning 404 Not Found instead. ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, reversed the order of recommendations.

Comment thread README.md Outdated
Alternatively, if `None` means that the resource doesn't exist, return a 404 Not
Found error.

The same applies to request bodies: rather than `TypedBody<Option<MyParams>>`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little interesting. Option is obviously overloaded in serde/serde_json to mean "maybe present" or "could be null", but it may not be unreasonable to have an optional POST body (even though it's not something dropshot supports well today). That said, I think this is the right restriction given the current capabilities.

Also, this specific phrasing ("the same applies") may make more sense after the "make your Option a struct field" rather than after "None = 404"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option is obviously overloaded in serde/serde_json to mean "maybe present" or "could be null", but it may not be unreasonable to have an optional POST body (even though it's not something dropshot supports well today).

Hmm, from the openapi-lint perspective (which only works on OpenAPI documents, not Rust code) this would be represented as "required": false and not "nullable": true, right? So I don't think this change makes that worse in any way. Unless I'm missing something?

@sunshowers

Copy link
Copy Markdown
Contributor Author

Thanks. Going to land this, then patch it in to all the repos in the omicron crativerse.

@sunshowers
sunshowers merged commit 619147c into main Nov 1, 2026
4 checks passed
@sunshowers
sunshowers deleted the sunshowers/spr/add-lint-for-nullable-request-and-response-bodies branch November 1, 2026 00:14
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