我需要从另一个模式内部引用这个学生模式:
{
"type": "record",
"namespace": "data.add",
"name": "Student",
"fields": [
{
"name": "Name",
"type": "string"
},
{
"name": "Age",
"type": "int"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是需要引用Student 的父地址架构:
{
"type": "record",
"namespace": "data.add",
"name": "Address",
"fields": [
{
"name": "student",
"type": "Student"
}
]
}
Run Code Online (Sandbox Code Playgroud)
当我使用 Gradle 和 Avro 插件构建时,上面的内容会引发错误。两个架构都位于同一文件夹中。
我有这两个 avsc 文件,第一个文件引用了第二个文件,但是当尝试使用 avrogen 进行编译时,会返回错误并且不会生成架构。
错误:
Exception occurred. Undefined name: AnalogProperty at 'fields[0].type.items.fields[2].type.fields[0].type'
Run Code Online (Sandbox Code Playgroud)
AVSC 1
"doc": "Measurement Type, Analog or Discrete",
"name": "AnalogProperties",
"type": {
"fields": [
{
"doc": "",
"name": "RealPower",
"type": "AnalogProperty"
}
}
Run Code Online (Sandbox Code Playgroud)
AVSC 2
{
"name": "AnalogProperty",
"namespace": "Kafka.AvroSchemas",
"doc": "AnalogProperty object",
"type": "record",
"fields": [{
"doc": "Circuit from requested topology.",
"name": "cValue",
"type": "double"
},
{
"doc": "Circuit from requested topology.",
"name": "cTimestamp",
"type": "string"
},
]
}
Run Code Online (Sandbox Code Playgroud) 我现在正在使用 avro .avsc 模式,我喜欢在示例中进行格式化:
{
"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number", "type": ["int", "null"]},
{"name": "favorite_color", "type": ["string", "null"]}
]
}
Run Code Online (Sandbox Code Playgroud)
我特指的是单行字段定义{"name": "name", "type": "string"}
。
我想在 vscode 中编辑和格式化我的架构,但它不断包装字段,例如
{
"name": "name",
"type": "string"
}
Run Code Online (Sandbox Code Playgroud)
我尝试配置默认的 json 格式化程序并使用beautify
扩展名setting.json
,但没有成功
"[json]": {
"editor.tabSize": 2,
"editor.wordWrap": "off",
"editor.defaultFormatter": "vscode.json-language-features",
// "editor.defaultFormatter": "HookyQR.beautify"
},
"html.format.wrapAttributes": "preserve",
"beautify.config": {
"indent_size": 2,
"indent_char": " ",
"preserve_newlines": true,
"space_in_paren": true,
"space_in_empty_paren": true,
"wrap_attributes": "preserve", …
Run Code Online (Sandbox Code Playgroud)