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

Could not resolve reference: /components/schemas/PathBuf does not exist in document #656

Closed
Narven opened this issue Jun 23, 2023 · 3 comments

Comments

@Narven
Copy link

Narven commented Jun 23, 2023

Could not resolve reference: Could not resolve pointer: /components/schemas/PathBuf does not exist in document

Hi.
I understand the concept of adding stuff to the schemas() and add the derive ToSchema on any struct we might be using. But how i'm I supose to add ToSchema to a PathBuf, or any external lib that I might be using like ByteSize for example ? thanks.

@Narven
Copy link
Author

Narven commented Jul 4, 2023

Any information on this? thanks

@juhaku
Copy link
Owner

juhaku commented Jul 4, 2023

Hey, firstly I am sorry for long latency in reply times.

Recently I have been quite busy, near burn out and just came from 1 week holiday. After all this project is only a free time project without full-time allocation that will also take it's toll. Thanks for understanding.

But in short you can either use the value_type, schema_with, or as attribute with your field e.g.

#[derive(ToSchema)]
struct Item {
    #[schema(value_type = String)]
    path: PathBuf,
}

// .. schema_with, 

#[derive(ToSchema)]
struct Item {
    #[schema(schema_with = String::schema)]
    path: PathBuf,
}

The as attribute would work similar way as serde's serialize_with https://serde.rs/field-attrs.html#serialize_with

#[derive(ToSchema)]
#[schema(as = PathBuf, value_type = String)]
struct MyPath(PathBuf);

struct Item {
    #[schema(inline)]
    path: MyPath
}

If no inline is defined it will consider the type as object and assume that MyPath is actually found from registered schemas.

Note! I am not sure whether the as will work as demonstrated above for the unnamed field structs but it can be used to "override" a schema with another one that might be useful for named structs at least if value_type or schema_with is not feasible solution.

Docs https://docs.rs/utoipa/latest/utoipa/derive.ToSchema.html#named-fields-optional-configuration-options-for-schema say misleadingly with_schema but the correct attribute is schema_with.

Hope these will lead you to the right tracks.

Related to #383 (comment) #330 (comment) #390 #507 (comment)

@Narven
Copy link
Author

Narven commented Jul 4, 2023

Thanks a lot for the reply.

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

2 participants