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

Compilation Error When Using ref Keyword in Attribute for External File Reference #994

Open
shishidosoichiro opened this issue Nov 18, 2024 · 0 comments

Comments

@shishidosoichiro
Copy link

Describe the bug
When I try to use #[endpoint(request_body = ref("./external.json"))] to reference an external file, as per the Salvo documentation, I encounter a compilation error. It appears that the ref keyword may be causing a conflict, possibly because it's also a reserved word in Rust.

To Reproduce
Steps to reproduce:

  1. Add the following code:
    use salvo::{oapi::extract::JsonBody, prelude::*};
    
    #[endpoint(request_body = ref("./external.json"))]
    async fn hello(name: JsonBody<String>) -> String {
        format!("Hello World, {}", name)
    }
    
    #[tokio::main]
    async fn main() {
        let router = Router::new().get(hello);
        let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
        Server::new(acceptor).serve(router).await;
    }
  2. Run cargo build.
  3. Compilation fails with the following error:
    error: unexpected token, expected type such as String, expected identifier
     --> src/main.rs:3:31
      |
    3 | #[endpoint(request_body = ref("./external.json"))]
      |                               ^^^^^^^^^^^^^^^^^
    

Expected behavior
I expected this code to compile successfully, allowing ref("./external.json") to refer to an external JSON file as the request body.

Screenshots
Not applicable.

Desktop (please complete the following information):

  • OS: [Your OS]
  • Browser: Not applicable
  • Version: Not applicable

Additional context
It seems that ref might be causing a conflict due to its status as a Rust reserved word, but I’m not certain. I’d appreciate any guidance on how best to approach this or if there’s a workaround. Thank you for all the hard work on Salvo—it's a great framework, and any help would be greatly appreciated!

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

1 participant