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

Allow Query to take an Option<T> type #636

Open
zephraph opened this issue Apr 4, 2023 · 0 comments
Open

Allow Query to take an Option<T> type #636

zephraph opened this issue Apr 4, 2023 · 0 comments
Assignees

Comments

@zephraph
Copy link
Contributor

zephraph commented Apr 4, 2023

In Oxide's V1 API we have endpoint definitions like the following

#[endpoint {
    method = GET,
    path = "/v1/disks/{disk}",
    tags = ["disks"]
}]
async fn disk_view(
    rqctx: RequestContext<Arc<ServerContext>>,
    path_params: Path<params::DiskPath>,
    query_params: Query<params::OptionalProjectSelector>,
) -> Result<HttpResponseOk<Disk>, HttpError> { ... }

Note that the query_params definition takes a params::OptionalProjectSelector. That OptionalProjectSelector is just a wrapper for ProjectSelector with an Option and #[serde(flatten)] in the definition. It's a whole lot of noise that could be avoided if Query<Option<params::ProjectSelector>> was valid. Unfortunately if we try that we get this gem

Optional query panic
process stderr:thread 'main' panicked at 'invalid type Object(
    SchemaObject {
        metadata: Some(
            Metadata {
                id: None,
                title: Some(
                    "Nullable_ProjectSelector",
                ),
                description: None,
                default: None,
                deprecated: false,
                read_only: false,
                write_only: false,
                examples: [],
            },
        ),
        instance_type: None,
        format: None,
        enum_values: None,
        const_value: None,
        subschemas: Some(
            SubschemaValidation {
                all_of: Some(
                    [
                        Object(
                            SchemaObject {
                                metadata: None,
                                instance_type: None,
                                format: None,
                                enum_values: None,
                                const_value: None,
                                subschemas: None,
                                number: None,
                                string: None,
                                array: None,
                                object: None,
                                reference: Some(
                                    "#/components/schemas/ProjectSelector",
                                ),
                                extensions: {},
                            },
                        ),
                    ],
                ),
                any_of: None,
                one_of: None,
                not: None,
                if_schema: None,
                then_schema: None,
                else_schema: None,
            },
        ),
        number: None,
        string: None,
        array: None,
        extensions: {
            "nullable": Bool(true),
        },
    },
)', /Users/just-be/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ccce224/dropshot/src/schema_util.rs:134:20

This is somewhat related to #635 that that ultimately both Body and Query would be improved by taking Option types.

@ahl ahl self-assigned this Apr 17, 2023
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

No branches or pull requests

2 participants