GREsau / okapi

OpenAPI (AKA Swagger) document generation for Rust projects
MIT License
606 stars 110 forks source link

Cannot build project with okapi as dependency #58

Closed NightlySide closed 2 years ago

NightlySide commented 3 years ago

I'm trying to setup okapi for rocket 0.5.0-rc.1. My Cargo.toml file is the following:

[package]
name = "food-organizer"
version = "0.1.0"
edition = "2018"

[dependencies]
# Env
dotenv = "0.15.0"

# Web server
rocket = { version = "0.5.0-rc.1", features=["tls", "json"] }
rocket_cors = "0.5.2"

# API documentation
okapi = "0.7.0-alpha-1"
rocket_okapi = { version = "0.8.0-alpha-1"}
schemars = { version = "0.8.6", features = ["preserve_order"] }

# Scraper
reqwest = "0.11.4"
scraper = "0.12.0"

# Serialisation
serde = "1.0.130"
serde_json = "1.0.68"

# Utils
regex = "1.5.4"
jsonwebtoken = "7.2.0"
chrono = "0.4.19"
bcrypt = "0.10.1"

# OpenSSL
openssl = {version="0.10.36", features=["vendored"]}

# DB driver
diesel = { version = "1.4.8", features = ["sqlite"] }

[patch.crates-io]
rocket = { git = 'https://github.com/SergioBenitez/Rocket', branch = "v0.5-rc" }
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors.git", branch = "master" }
rocket_okapi = { git = "https://github.com/GREsau/okapi", branch = "master" }
okapi = { git = "https://github.com/GREsau/okapi", branch = "master" }

I'm trying to build and I get the same error again and again, like if okapi wasn't using rocket 0.5 :

   Compiling rocket_okapi v0.8.0-alpha-1 (https://github.com/GREsau/okapi?branch=master#867e5061)
error[E0432]: unresolved import `rocket::response::content::Custom`
 --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/handlers/content.rs:2:24
  |
2 | use rocket::response::{content::Custom, Responder};
  |                        ^^^^^^^^^^^^^^^ no `Custom` in `response::content`

error[E0432]: unresolved import `rocket::response::content::Custom`
 --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/handlers/openapi.rs:3:5
  |
3 | use rocket::response::content::Custom;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `Custom` in `response::content`

error[E0412]: cannot find type `Css` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:217:27
    |
217 | response_content_wrapper!(Css, "text/css");
    |                           ^^^ not found in `rocket::response::content`

error[E0412]: cannot find type `Custom` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:218:27
    |
218 | response_content_wrapper!(Custom, "*/*");
    |                           ^^^^^^ not found in `rocket::response::content`
    |
help: consider importing this struct
    |
1   | use rocket::response::status::Custom;
    |

error[E0412]: cannot find type `Html` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:219:27
    |
219 | response_content_wrapper!(Html, "text/html");
    |                           ^^^^ not found in `rocket::response::content`

error[E0412]: cannot find type `JavaScript` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:220:27
    |
220 |   response_content_wrapper!(JavaScript, "application/javascript");
    |                             ^^^^^^^^^^ help: a struct with a similar name exists: `RawJavaScript`
    |
   ::: /home/alexandre/.cargo/git/checkouts/rocket-8bf16d9ca7e90bdc/e382bc5/core/lib/src/response/content.rs:69:1
    |
69  | / ctrs! {
70  | |     // FIXME: Add a note that this is _not_ `serde::Json`.
71  | |     RawJson: JSON, "JSON", "application/json",
72  | |     RawXml: XML, "XML", "text/xml",
...   |
77  | |     RawJavaScript: JavaScript, "JavaScript", "application/javascript"
78  | | }
    | |_- similarly named struct `RawJavaScript` defined here

error[E0412]: cannot find type `Json` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:221:27
    |
221 | response_content_wrapper!(Json, "application/json");
    |                           ^^^^ not found in `rocket::response::content`
    |
help: consider importing one of these items
    |
1   | use crate::request::from_data_impls::Json;
    |
1   | use rocket::serde::json::Json;
    |

error[E0412]: cannot find type `MsgPack` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:222:27
    |
222 | response_content_wrapper!(MsgPack, "application/msgpack");
    |                           ^^^^^^^ not found in `rocket::response::content`

error[E0412]: cannot find type `Plain` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:223:27
    |
223 | response_content_wrapper!(Plain, "text/plain");
    |                           ^^^^^ not found in `rocket::response::content`

error[E0412]: cannot find type `Xml` in module `rocket::response::content`
   --> /home/alexandre/.cargo/git/checkouts/okapi-727e9b4b9c217cbb/867e506/rocket-okapi/src/response/responder_impls.rs:224:27
    |
224 | response_content_wrapper!(Xml, "text/xml");
    |                           ^^^ not found in `rocket::response::content`

Some errors have detailed explanations: E0412, E0432.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `rocket_okapi` due to 10 previous errors

Does anyone have an idea about how I can make this work?

ralpha commented 3 years ago

This is because you are using different versions of the same crate. Okapi (master branch) is currently build for Rocket 0.5.0-rc.1. But you are using Rocket 0.5.0-rc (git branch) and these are different versions. So you force the compiler to use a version of Rocket that okapi is not implemented for. This line changes the rocket version to force use 0.5.0-rc (git branch)

[patch.crates-io]
rocket = { git = 'https://github.com/SergioBenitez/Rocket', branch = "v0.5-rc" }

Also note that Rocket 0.5.0-rc.1 and Rocket 0.5.0-rc (git branch) are not the same internally. Some things are moved, added and changed since 0.5.0-rc.1.

So to solve this, make sure you use the same version. So for rocket-okapi this should be 0.5.0-rc.1 so your code should also use this version. If you really want to use rocket-okapi with Rocket 0.5.0-rc (git branch) then you have to vendor/fork rocket-okapi and change the Cargo.toml to use your version of Rocket. Note that this might not work correctly because some things changed in rocket. (same for rocket-okapi-codegen )

This should be solved once Rocket has its 0.5.0 release out, but who know when that is going to happen...

ralpha commented 2 years ago

If the above did not fix the issue, let me know and reopen the issue. But I'm fairly sure the 'version' mismatch is the problem.