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

Most returned struct fields are wrapped in Option #6

Open
johnbatty opened this issue Aug 1, 2022 · 0 comments
Open

Most returned struct fields are wrapped in Option #6

johnbatty opened this issue Aug 1, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@johnbatty
Copy link
Collaborator

Most returned struct fields are wrapped in Option.

Example:

pub struct WikiPage {
    pub wiki_page_create_or_update_parameters: [WikiPageCreateOrUpdateParameters],
    pub git_item_path: Option<String>,
    pub id: Option<i32>,
    pub is_non_conformant: Option<bool>,
    pub is_parent_page: Option<bool>,
    pub order: Option<i32>,
    pub path: Option<String>,
    pub remote_url: Option<String>,
    pub sub_pages: Vec<WikiPage>,
    pub url: Option<String>,
}

This makes it tedious/verbose to access these field values, as you either need to check for Some(value) or make liberal use of unwrap().

The code generator does the Option wrapping because the OpenAPI spec does not mark these fields as "mandatory", even though many of them will always be present. For example, in the definition above it is safe to assume that every WikiPage will have an id field.

The current code generator does have the ability to remove the Option wrapper for specific struct fields that are known to always be present (see patch_definition_required_fields()). I have done this by trial and error for a small number of structs that I care about. This must be done with care because if a response does not contain a field that is always expected (not an Option), then the deserialization fails.

If you have specific structs that have Options that you think could be removed then add a comment to this issue and I'll look into fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant