OAPI : #[salvo(schema(name = XXX))] expects an identifier instead of a "string" literal
rxdiscovery opened this issue · 7 comments
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:
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"
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.
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 betweensymbol
andschema
.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?
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.
Should we close this issue? It's not a bug
Should we close this issue? It's not a bug
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.
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.
I think this decision can be left to the users, as they may have different usage preferences.