You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error: proc macro panicked
--> src/main.rs:2:1
|
2 | typify::import_types!("./src/devContainer.base.schema.json");| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: not yet implemented: invalid (or unexpected) schema:
{
"description": "Indicates whether a GPU is required. The string \"optional\" indicates that a GPU is optional. An object value can be used to configure more detailed requirements.",
"type": [
"boolean",
"string"
],
"enum": [
true,
false,
"optional"
]
}
error: could not compile `foo` (bin "foo") due to 1 previous error
Message: multiple implied types for an un-typed enum {Boolean, String} [Bool(true), Bool(false), String("optional")]
Location: typify-impl/src/convert.rs:2044
Currently we don't handle multiple datatypes for a single value--we're failing in two different ways depending on whether the type field is present.
What we should ideally produce is something like this:
pubenumGpu{True,False,Optional,}
But what about Serialize and Deserialize? There's no serde derive annotations we can use to coax this into something reasonable; we'll need to generate something custom:
implSerializeforGpu{fnserialize<S>(&self,serializer:S) -> Result<S::Ok,S::Error>whereS: serde::Serializer,{matchself{Gpu::False => serializer.serialize_bool(false),Gpu::True => serializer.serialize_bool(true),Gpu::Optional => serializer.serialize_str("optional"),}}}impl<'de>Deserialize<'de>forGpu{fndeserialize<D>(deserializer:D) -> Result<Self,D::Error>whereD: serde::Deserializer<'de>,{structGpuVisitor;impl<'de> serde::de::Visitor<'de>forGpuVisitor{typeValue = Gpu;fnexpecting(&self,formatter:&mut std::fmt::Formatter) -> std::fmt::Result{
formatter.write_str("a boolean or the string 'optional'")}fnvisit_bool<E>(self,value:bool) -> Result<Self::Value,E>whereE: serde::de::Error,{if value {Ok(Gpu::True)}else{Ok(Gpu::False)}}fnvisit_str<E>(self,value:&str) -> Result<Self::Value,E>whereE: serde::de::Error,{if value == "optional"{Ok(Gpu::Optional)}else{Err(E::custom(format!("invalid string value '{}', expected 'optional'",
value
)))}}}
deserializer.deserialize_any(GpuVisitor)}}
We'll also need a custom implementation of schemars::JsonSchema, but that's relatively straightforward.
There isn't currently a simple augmentation to the internal data structures that accommodate this kind of customized Serialize/Deserialize. Note that this is pretty similar to #230.
Activity
ahl commentedon Oct 8, 2025
There are some simpler cases that also fail:
{ "title": "gpu", "type": [ "boolean", "string" ], "enum": [ true, false, "optional" ] }Produces this:
And
{ "title": "gpu", "enum": [ true, false, "optional" ] }Produces this:
Currently we don't handle multiple datatypes for a single value--we're failing in two different ways depending on whether the
typefield is present.What we should ideally produce is something like this:
But what about
SerializeandDeserialize? There's noserdederive annotations we can use to coax this into something reasonable; we'll need to generate something custom:We'll also need a custom implementation of
schemars::JsonSchema, but that's relatively straightforward.There isn't currently a simple augmentation to the internal data structures that accommodate this kind of customized
Serialize/Deserialize. Note that this is pretty similar to #230.