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

OAPI : #[salvo(schema(name = XXX))] expects an identifier instead of a "string" literal #832

Closed
rxdiscovery opened this issue Jul 15, 2024 · 7 comments · Fixed by #847
Closed

Comments

@rxdiscovery
Copy link

rxdiscovery commented Jul 15, 2024

Hello,

Describe the bug :

An error now occurs in new versions of Salvo with OpenAPI :

use salvo::oapi::ToSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
#[salvo(schema(name = "City"))]  //<-- `error: expected identifier`
pub struct CityDTO {
    #[salvo(schema(rename = "id"))]
    pub id: String,
    #[salvo(schema(rename = "name"))]
    pub name: String,
}

gives this error :
error: expected identifier

but by using an identifier instead of a string, it works.

#[salvo(schema(name = City))]

Normally name must take a literal string as parameter instead of an identifier, otherwise it may be confused with variables in the code.

And the weirdest thing is that it works on some names and not others:

Screenshot from 2024-07-15 01-45-13

it works for LoginDTO but not for CityDTO !!

**Salvo version : **

salvo = { version = "0.68.5", features = ["oapi", "jwt-auth", "compression"] }
salvo-oapi = "0.68.5"
@TheAwiteb
Copy link
Contributor

it works for LoginDTO but not for CityDTO !!

I don't think it's a bug, because in the first one you're using #[salvo(symbol(name = "LoginRequest"))] while in the second one using #[salvo(schema(name = "City"))]. There is a diffrence between symbol and schema.

Note

The #[salvo(symbol(name = "LoginRequest"))] will have no effect, because Salvo does not support it.

@rxdiscovery
Copy link
Author

it works for LoginDTO but not for CityDTO !!

I don't think it's a bug, because in the first one you're using #[salvo(symbol(name = "LoginRequest"))] while in the second one using #[salvo(schema(name = "City"))]. There is a diffrence between symbol and schema.

Note

The #[salvo(symbol(name = "LoginRequest"))] will have no effect, because Salvo does not support it.

Thank you very much for your remarks,

Is it normal that #[salvo(schema(name = "City"))] no longer accepts literal strings?

@TheAwiteb
Copy link
Contributor

Is it normal that #[salvo(schema(name = "City"))] no longer accepts literal strings?

It was with #[salvo(schema(symbol = "..."))] but not with name, as you can see here.

Ultimately, Salvo is not stable yet, so you should expect changes like this.

@TheAwiteb
Copy link
Contributor

Should we close this issue? It's not a bug

cc: @rxdiscovery @chrislearn

@rxdiscovery
Copy link
Author

Should we close this issue? It's not a bug

cc: @rxdiscovery @chrislearn

I think it should be kept open, “name” should take a literal string so as not to cause confusion with an already existing type/struct.

@TheAwiteb
Copy link
Contributor

I think it should be kept open, “name” should take a literal string so as not to cause confusion with an already existing type/struct.

@chrislearn What do you think? will Salvo support this? if yes we should open this issue.

For me, I think we should not, I think using identifier only is better.

@chrislearn
Copy link
Member

I think this decision can be left to the users, as they may have different usage preferences.

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

Successfully merging a pull request may close this issue.

3 participants