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

Generated httpmock Then.ok & .json_body_obj compile issues #637

Open
jayvdb opened this issue Dec 3, 2023 · 7 comments
Open

Generated httpmock Then.ok & .json_body_obj compile issues #637

jayvdb opened this issue Dec 3, 2023 · 7 comments

Comments

@jayvdb
Copy link
Contributor

jayvdb commented Dec 3, 2023

When I attempt to compile the generated output, I see

error[E0308]: mismatched types
   --> src/propolis_server_httpmock.rs:302:39
    |
302 |             Self(self.0.json_body_obj(value))
    |                         ------------- ^^^^^ expected `&_`, found `InstanceStateRequested`
    |                         |
    |                         arguments to this method are incorrect
    |
    = note: expected reference `&_`
                    found enum `propolis_server_builder::types::InstanceStateRequested`
note: method defined here
   --> /home/jayvdb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/httpmock-0.6.8/src/api/spec.rs:534:12
    |
534 |     pub fn json_body_obj<'a, T>(self, body: &T) -> Self
    |            ^^^^^^^^^^^^^
help: consider borrowing here
    |
302 |             Self(self.0.json_body_obj(&value))
    |                                       +

Some errors have detailed explanations: E0308, E0433.
For more information about an error, try `rustc --explain E0308`.

when I add & as suggested, I get errors like

error[E0277]: the trait bound `&propolis_server_builder::types::InstanceStateMonitorRequest: Deserialize<'_>` is not satisfied
   --> src/propolis_server_httpmock.rs:356:39
    |
356 |             Self(self.0.json_body_obj(&value))
    |                         ------------- ^^^^^^ the trait `Deserialize<'_>` is not implemented for `&propolis_server_builder::types::InstanceStateMonitorRequest`
    |                         |
    |                         required by a bound introduced by this call
    |
note: required by a bound in `When::json_body_obj`
   --> /home/jayvdb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/httpmock-0.6.8/src/api/spec.rs:536:24
    |
534 |     pub fn json_body_obj<'a, T>(self, body: &T) -> Self
    |            ------------- required by a bound in this associated function
535 |     where
536 |         T: Serialize + Deserialize<'a>,
    |                        ^^^^^^^^^^^^^^^ required by this bound in `When::json_body_obj`
help: consider removing the leading `&`-reference
    |
356 -             Self(self.0.json_body_obj(&value))
356 +             Self(self.0.json_body_obj(value))
    |

This is a rabbit hole, as adding #derive[serde::Deserialize, serde::Serialize] then requires Client has those traits, etc.

@jayvdb
Copy link
Contributor Author

jayvdb commented Dec 3, 2023

See #638 - the two commented out mods in progenitor-impl/tests/output/src/lib.rs are because of this.

Maybe it is because I chose to use the _builder client for the httpmock generation..?

@ahl
Copy link
Collaborator

ahl commented Dec 5, 2023

Thanks for this; I'll look into it.

@ahl
Copy link
Collaborator

ahl commented Dec 7, 2023

        pub fn body(self, value: types::InstanceStateRequested) -> Self {
            Self(self.0.json_body_obj(value))
        }

All the other fn body have value: &types::.... I haven't looked into what makes this one different.

@jayvdb jayvdb changed the title httpmock OperationParameterType::Type compile issues httpmock Then.ok & .json_body_obj compile issues Dec 8, 2023
@jayvdb jayvdb changed the title httpmock Then.ok & .json_body_obj compile issues Generated httpmock Then.ok & .json_body_obj compile issues Dec 8, 2023
@jayvdb
Copy link
Contributor Author

jayvdb commented Dec 8, 2023

Then buildomat case is quite different

error[E0308]: mismatched types
    --> src/buildomat_httpmock.rs:37:36
     |
37   |                     .json_body_obj(value),
     |                      ------------- ^^^^^ expected `&_`, found `()`
     |                      |
     |                      arguments to this method are incorrect
     |
     = note: expected reference `&_`
                found unit type `()`
note: method defined here
    --> /home/jayvdb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/httpmock-0.6.8/src/api/spec.rs:1034:12
     |
1034 |     pub fn json_body_obj<T>(self, body: &T) -> Self
     |            ^^^^^^^^^^^^^
help: consider borrowing here
     |
37   |                     .json_body_obj(&value),
     |                                    +

The generated code is clearly problematic with arg definition value: ()

        pub fn ok(self, value: ()) -> Self {
            Self(
                self.0
                    .status(200u16)
                    .header("content-type", "application/json")
                    .json_body_obj(value),
            )
        }

@jayvdb
Copy link
Contributor Author

jayvdb commented Dec 8, 2023

The current buildomat openapi looks strange, and it is fixed by updating the spec - #643

Updating propolis-server.json doesnt help - same error.

@jayvdb
Copy link
Contributor Author

jayvdb commented Dec 8, 2023

The buildomat spec piece causing the problem was intentionally added in 75b224c , and null is valid in enums according to https://swagger.io/docs/specification/data-models/enums/#nullable , so this needs to be supported by the httpmock generator.

@ahl
Copy link
Collaborator

ahl commented Dec 8, 2023

The current buildomat openapi looks strange, and it is fixed by updating the spec - #643

Odd as it might be, it's valid OpenAPI so I don't want to lose the validation of its oddness. In other words, we don't want to change the inputs to fix the tests!

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