插件 jsonschema2pojo:属性按要求显示,但它们应该是可选的
Plugin jsonschema2pojo: Properties are shown as required but they should be optional
我有一个 personschema,例如这两个字段:
"name": {
"title": "Last name",
"type": "string",
"minLength": 1,
"isRequired" : true
}
"birthday": {
"title": "Date of birth",
"$ref": "resource:schema/general/dateSchema.json",
"isRequired" : true
},
"birthCountry": {
"$ref": "resource:schema/general/countrySchema.json",
"title": "Country of birth",
"isRequired" : true
}
然后我有另一个扩展人员模式的模式。在此模式中,我希望这两个属性(birthCountry 和 birthday)是可选的,只有名称是必需的。我已经试过了:
{
"$schema": "http://json-schema.org/draft/2019-09/schema",
"title": "Other Schema",
"type": "object",
"javaType": "..json_schema_model.dto.OtherSchema",
"description": "Other Schema Description",
"extendsJavaClass": "..json_schema_model.dto.PersonSchema",
"allOf": [{
"required": [
"name"
],
"$ref": "resource:schema/general/personSchema.json"
}
但不幸的是,在 API-文档中,它们仍然被标记为强制性的。
问题是属性只能在child classes中添加而不能修改,所以我重新安排了class结构来修改决定一个值是否是强制的只能由 child classes 自己决定。另请注意,与 $refs 一起的同级值将被忽略。要向 $ref 添加属性,您需要将其包装到 allOf.
我有一个 personschema,例如这两个字段:
"name": {
"title": "Last name",
"type": "string",
"minLength": 1,
"isRequired" : true
}
"birthday": {
"title": "Date of birth",
"$ref": "resource:schema/general/dateSchema.json",
"isRequired" : true
},
"birthCountry": {
"$ref": "resource:schema/general/countrySchema.json",
"title": "Country of birth",
"isRequired" : true
}
然后我有另一个扩展人员模式的模式。在此模式中,我希望这两个属性(birthCountry 和 birthday)是可选的,只有名称是必需的。我已经试过了:
{
"$schema": "http://json-schema.org/draft/2019-09/schema",
"title": "Other Schema",
"type": "object",
"javaType": "..json_schema_model.dto.OtherSchema",
"description": "Other Schema Description",
"extendsJavaClass": "..json_schema_model.dto.PersonSchema",
"allOf": [{
"required": [
"name"
],
"$ref": "resource:schema/general/personSchema.json"
}
但不幸的是,在 API-文档中,它们仍然被标记为强制性的。
问题是属性只能在child classes中添加而不能修改,所以我重新安排了class结构来修改决定一个值是否是强制的只能由 child classes 自己决定。另请注意,与 $refs 一起的同级值将被忽略。要向 $ref 添加属性,您需要将其包装到 allOf.