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

OpenAPI TS generator: no required array means all fields are optional #1018

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

cikzh
Copy link
Contributor

@cikzh cikzh commented Feb 11, 2025

Right now the OpenAPI type generator assumes the absence of a required field means all fields are required, but the opposite is true; no required field, means all fields are optional.

To test

  1. Run the generator on the main branch, should result in no diff
  2. Create a Rust struct with optional fields only e.g.:
struct TestStruct {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[schema(value_type = String, nullable = false)]
    test_field_one: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[schema(value_type = String, nullable = false)]
    test_field_two: Option<String>,
}

and see that the generator generates optional TS interfaces

@cikzh cikzh added the bug Something isn't working label Feb 11, 2025
@cikzh cikzh self-assigned this Feb 11, 2025
@cikzh cikzh requested a review from a team as a code owner February 11, 2025 15:43
@cikzh cikzh changed the title No required array means all fields are optional OpenAPI TS generator: no required array means all fields are optional Feb 11, 2025
Copy link

Sigrid maintainability feedback

💭️ You did not change any files that are measured by Sigrid


View this system in Sigrid

@cikzh cikzh mentioned this pull request Feb 11, 2025
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.77%. Comparing base (5575746) to head (9c063b5).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
frontend/scripts/openapi/generator.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1018   +/-   ##
=======================================
  Coverage   89.77%   89.77%           
=======================================
  Files         248      248           
  Lines       12995    12995           
  Branches     1318     1318           
=======================================
  Hits        11666    11666           
  Misses       1235     1235           
  Partials       94       94           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@oliver3 oliver3 left a comment

Choose a reason for hiding this comment

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

image

Works!

@cikzh cikzh added this pull request to the merge queue Feb 11, 2025
Merged via the queue into main with commit ab43715 Feb 11, 2025
21 checks passed
@cikzh cikzh deleted the openapi-gen-req-bug branch February 11, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants