|
30 | 30 |
|
31 | 31 |
|
32 | 32 | def get_attribute_schema_class_for_kind(kind: str) -> type[AttributeSchema]: |
33 | | - attribute_schema_class_by_kind: dict[str, type[AttributeSchema]] = { |
34 | | - "NumberPool": NumberPoolSchema, |
35 | | - "Text": TextAttributeSchema, |
36 | | - "TextArea": TextAttributeSchema, |
37 | | - "Number": NumberAttributeSchema, |
38 | | - } |
39 | 33 | return attribute_schema_class_by_kind.get(kind, AttributeSchema) |
40 | 34 |
|
41 | 35 |
|
42 | 36 | class AttributeSchema(GeneratedAttributeSchema): |
43 | 37 | _sort_by: list[str] = ["name"] |
44 | 38 | _enum_class: type[enum.Enum] | None = None |
45 | 39 |
|
| 40 | + @classmethod |
| 41 | + def model_json_schema(cls, *args: Any, **kwargs: Any) -> dict[str, Any]: |
| 42 | + schema = super().model_json_schema(*args, **kwargs) |
| 43 | + |
| 44 | + # Build conditional schema based on attribute_schema_class_by_kind mapping |
| 45 | + # This override allows people using the Yaml language server to get the correct mappings |
| 46 | + # for the parameters when selecting the appropriate kind |
| 47 | + schema["allOf"] = [] |
| 48 | + for kind, schema_class in attribute_schema_class_by_kind.items(): |
| 49 | + schema["allOf"].append( |
| 50 | + { |
| 51 | + "if": {"properties": {"kind": {"const": kind}}}, |
| 52 | + "then": {"properties": {"parameters": {"$ref": f"#/definitions/{schema_class.__name__}"}}}, |
| 53 | + } |
| 54 | + ) |
| 55 | + |
| 56 | + return schema |
| 57 | + |
46 | 58 | @property |
47 | 59 | def is_attribute(self) -> bool: |
48 | 60 | return True |
@@ -247,3 +259,11 @@ class NumberAttributeSchema(AttributeSchema): |
247 | 259 | description="Extra parameters specific to number attributes", |
248 | 260 | json_schema_extra={"update": UpdateSupport.VALIDATE_CONSTRAINT.value}, |
249 | 261 | ) |
| 262 | + |
| 263 | + |
| 264 | +attribute_schema_class_by_kind: dict[str, type[AttributeSchema]] = { |
| 265 | + "NumberPool": NumberPoolSchema, |
| 266 | + "Text": TextAttributeSchema, |
| 267 | + "TextArea": TextAttributeSchema, |
| 268 | + "Number": NumberAttributeSchema, |
| 269 | +} |
0 commit comments