fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
858 stars 131 forks source link

Add `schemars::JsonSchema` behind feature-gate `schemars` to derive JSON-schemas #349

Closed sivizius closed 10 months ago

sivizius commented 10 months ago

Outside the crate schemars, the trait JsonSchema can only implemented on owned types due to the orphan rule. So if JsonSchema is required to be implemented for a type in an API, e.g. aide, those types have to be basically copied and #[derive(JsonSchema)] as well as some serde-remote/wrapper-magic applied. This PR avoids all of this by optionally deriving JsonSchema if used with feature schemars.

fussybeaver commented 10 months ago

There was a similar request some time ago for a different crate: https://github.com/juhaku/utoipa

https://github.com/fussybeaver/bollard/issues/289

I believe the author ended up forking bollard for his/her purpose.

The main problem is that we already abide by an existing json schema spec: https://github.com/moby/moby/blob/master/api/swagger.yaml - even if we did decide to support a second spec, you would need to amend the templates that generate the code.

Unfortunately, I'm not that keen to support it, because you could just be using the original schema to get the same benefits, and bollard maintainers would need to maintain quite a bit of code for effectively a duplicated specification. But happy to discuss any workarounds that may help integrate your project.

fussybeaver commented 10 months ago

Closing for now