netwo-io / apistos

Actix-web wrapper for automatic OpenAPI 3.0 documentation generation.
MIT License
138 stars 5 forks source link

expected type, found module *** not a type #129

Open futugyou opened 2 months ago

futugyou commented 2 months ago

I have a struct like this, and it was working normally.

#[derive(Debug, Default, Validate, Serialize, Deserialize)]
pub struct AnimalInsertRequest {
    #[serde(with = "date_format", default)]
    pub rescue_date: Option<DateTime<Utc>>,
}

but when add 'JsonSchema' like this

#[derive(Debug, Default, Validate, Serialize, Deserialize, ApiComponent, JsonSchema)]
pub struct AnimalInsertRequest {
    #[serde(with = "date_format", default)]
    pub rescue_date: Option<DateTime<Utc>>,
}

it show an error,

error[E0573]: expected type, found module `date_format`
#[serde(with = "date_format", default)]
                  ^^^^^^^^^^^^^ not a type

what can i do with this error

rlebran commented 2 months ago

Hi, thanks for the report ! What version of apistos / schemars do you use ? This is most likely an issue on schemars side and not directly related to apistos. Just in case, please make sure your serde version match the one provided by schemars, it could explain the issue.

futugyou commented 2 months ago
schemars = { package = "apistos-schemars", version = "0.8", features = [
    "chrono",
    "uuid1",
    "url",
    "rust_decimal",
] }
apistos = { version = "0.3", features = [
    "extras",
    "qs_query",
    "rapidoc",
    "redoc",
    "swagger-ui",
] }

Reference here

I also tried the default features, same error.

schemars = { package = "apistos-schemars", version = "0.8" }
apistos = { version = "0.3" }

And i found another question, this is metrics endpoint.

#[get("/metrics")]
#[api_operation(summary = "health check")]
pub(crate) async fn metrics(metrics_handle: ThinData<PrometheusHandle>) -> impl Responder {
    metrics_handle.render()
}

ThinData in actix-web 4.9 PrometheusHandle in metrics-exporter-prometheus 0.15.3

this code show an error

no function or associated item named `required` found for struct `ThinData<PrometheusHandle>` in the current scope
function or associated item not found in `ThinData<PrometheusHandle>`
rlebran commented 1 month ago

Hi, I still can't figure out the issue.

About this snippet: `#[get("/metrics")]

[api_operation(summary = "health check")]

pub(crate) async fn metrics(metrics_handle: ThinData) -> impl Responder { metrics_handle.render() }`