symfony - 发布后的 api 平台错误 提供的值无效(IRI 无效?)
问题描述
在带有 axios 的 vuejs 应用程序中工作,我有一些数据结构如下:
{
...
surgeries: [],//array of object
patientDiseases: [
{
date: a javascrtipt date,
disease: /api/diseases/#id //This is a valid IRI provided by the api in a select
}
] //array of object
}
当我发布这个数据集 api-platform 的响应是 Invalid value provided (invalid IRI?)
这是堆栈跟踪
{
"@context": "\/api\/contexts\/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Invalid value provided (invalid IRI?).",
"trace": [{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\api-platform\\core\\src\\Serializer\\AbstractItemNormalizer.php",
"line": 177,
"args": []
}, {
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "-\u003E",
"function": "setAttributeValue",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\symfony\\serializer\\Normalizer\\AbstractObjectNormalizer.php",
"line": 261,
"args": [
["object", "App\\Entity\\Disease"],
["integer", 0],
["string", "\/api\/diseases\/4"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "-\u003E",
"function": "denormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\api-platform\\core\\src\\Serializer\\AbstractItemNormalizer.php",
"line": 132,
"args": [
["string", "\/api\/diseases\/4"],
["string", "App\\Entity\\Disease"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "-\u003E",
"function": "denormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\api-platform\\core\\src\\Serializer\\ItemNormalizer.php",
"line": 43,
"args": [
["string", "\/api\/diseases\/4"],
["string", "App\\Entity\\Disease"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "ItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\ItemNormalizer",
"type": "-\u003E",
"function": "denormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\symfony\\serializer\\Serializer.php",
"line": 177,
"args": [
["string", "\/api\/diseases\/4"],
["string", "App\\Entity\\Disease"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "Symfony\\Component\\Serializer",
"short_class": "Serializer",
"class": "Symfony\\Component\\Serializer\\Serializer",
"type": "-\u003E",
"function": "denormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\symfony\\serializer\\Normalizer\\AbstractObjectNormalizer.php",
"line": 334,
"args": [
["string", "\/api\/diseases\/4"],
["string", "App\\Entity\\Disease"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "-\u003E",
"function": "validateAndDenormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\symfony\\serializer\\Normalizer\\AbstractObjectNormalizer.php",
"line": 259,
"args": [
["string", "App\\Entity\\PatientDisease"],
["string", "disease"],
["string", "\/api\/diseases\/4"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "-\u003E",
"function": "denormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\symfony\\serializer\\Serializer.php",
"line": 177,
"args": [
["array", {
"patient": ["array", []],
"date": ["string", "2018-11-27T13:03:00.000Z"],
"disease": ["string", "\/api\/diseases\/4"]
}],
["string", "App\\Entity\\PatientDisease"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "Symfony\\Component\\Serializer",
"short_class": "Serializer",
"class": "Symfony\\Component\\Serializer\\Serializer",
"type": "-\u003E",
"function": "denormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\api-platform\\core\\src\\Serializer\\AbstractItemNormalizer.php",
"line": 307,
"args": [
["array", {
"patient": ["array", []],
"date": ["string", "2018-11-27T13:03:00.000Z"],
"disease": ["string", "\/api\/diseases\/4"]
}],
["string", "App\\Entity\\PatientDisease"],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "-\u003E",
"function": "denormalizeRelation",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\api-platform\\core\\src\\Serializer\\AbstractItemNormalizer.php",
"line": 272,
"args": [
["string", "patientDiseases"],
["object", "ApiPlatform\\Core\\Metadata\\Property\\PropertyMetadata"],
["string", "App\\Entity\\PatientDisease"],
["array", {
"patient": ["array", []],
"date": ["string", "2018-11-27T13:03:00.000Z"],
"disease": ["string", "\/api\/diseases\/4"]
}],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", true],
"resource_class": ["string", "App\\Entity\\PatientDisease"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "-\u003E",
"function": "denormalizeCollection",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\api-platform\\core\\src\\Serializer\\AbstractItemNormalizer.php",
"line": 204,
"args": [
["string", "patientDiseases"],
["object", "ApiPlatform\\Core\\Metadata\\Property\\PropertyMetadata"],
["object", "Symfony\\Component\\PropertyInfo\\Type"],
["string", "App\\Entity\\PatientDisease"],
["array", [
["array", {
"patient": ["array", []],
"date": ["string", "2018-11-27T13:03:00.000Z"],
"disease": ["string", "\/api\/diseases\/4"]
}]
]],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", false],
"resource_class": ["string", "App\\Entity\\Patient"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "-\u003E",
"function": "setAttributeValue",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\symfony\\serializer\\Normalizer\\AbstractObjectNormalizer.php",
"line": 261,
"args": [
["object", "App\\Entity\\Patient"],
["string", "patientDiseases"],
["array", [
["array", {
"patient": ["array", []],
"date": ["string", "2018-11-27T13:03:00.000Z"],
"disease": ["string", "\/api\/diseases\/4"]
}]
]],
["string", "json"],
["array", {
"groups": ["array", [
["string", "patient"]
]],
"collection_operation_name": ["string", "post"],
"operation_type": ["string", "collection"],
"api_allow_update": ["boolean", false],
"resource_class": ["string", "App\\Entity\\Patient"],
"request_uri": ["string", "\/api\/patients"],
"uri": ["string", "http:\/\/localhost:8000\/api\/patients"],
"api_denormalize": ["boolean", true],
"cache_key": ["string", "e83f0aaf1c78a8d5386bc220724081e1"]
}]
]
}, {
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "-\u003E",
"function": "denormalize",
"file": "G:\\6.programacion\\from git\\Veterinaria\\vendor\\api-platform\\core\\src\\Serializer\\AbstractItemNormalizer.php",
"line": 132,
"args": [
["array", {
"name": ["string", "perro"],
"age": ["integer", 8],
"specie": ["string", "\/api\/species\/1"],
"breed": ["string", "\/api\/breeds\/1"],
"birthdate": ["string", "2018-11-07T13:03:00.000Z"],
"entrydate": ["string", "2018-11-23T13:03:03.182Z"],
"gender": ["string", "\/api\/genders\/1"],
"temperament": ["string", "\/api\/temperaments\/1"],
"chip": ["string", "asdasd2asd"],
"coatType": ["string", "\/api\/coat_types\/1"],
"coatColor": ["string", "\/api\/coat_colors\/1"],
"details": ["string", "m.cxvczxjkcxzvjklczv"],
"status": ["string", "\/api\/status_patients\/1"],
"client": ["array", {
"name": ["string", "Juan"],
"lastName": ["string", "Alberto"],
"secondSurname": ["string", "Asdasd"],
"email": ["string", "asdasd@asdasd.as"],
"phone1": ["string", "234234"],
"phone2": ["string", "24234"],
"clientType": ["string", "\/api\/client_types\/1"],
"sector": ["string", "\/api\/sectors\/1"],
"identificationCard": ["string", "98989898989"],
"address": ["string", "sdfsdfsdfs sdf sd5f sd"]
}],
"isActive": ["boolean", true],
"surgeries": ["array", [
["array", {
"name": ["string", "sdfa fsdf"],
"date": ["string", "2018-11-30T13:03:00.000Z"],
"patient": ["array", []]
}],
["array", {
"name": ["string", "sdfa fsdf"],
"date": ["string", "2018-11-30T13:03:00.000Z"],
"patient": ["array", []]
}],
["array", {
"name": ["string", "sdfa fsdf"],
"date": ["string", "2018-11-30T13:03:00.000Z"],
"patient": ["array", []]
}],
["array", {
"name": ["string", "sdfa fsdf"],
"date": ["string", "2018-11-30T13:03:00.000Z"],
"patient": ["array", []]
}]
]],
"patientDiseases": ["array", [
["array", {
"patient": ["array", []],
"date": ["string", "2018-11-27T13:03:00.000Z"],
"disease": ["string", "\/api\/diseases\/4"]
}]
]]
}],
["string", "App\\Entity\\Patient"],
["string", "json"],
如您所见,IRI 存在于数组的每个对象的请求中,但 api-platform 仍然引发 Invalid IRI 错误。
实体配置有级联持久选项
您对我如何解决这种情况有什么建议吗?
提前致谢
解决方案
你能找到这种行为的原因吗?我只是面临着同样的问题。
$ composer info
api-platform/core v2.3.5 Build a fully-featured hypermedia or GraphQL API in minutes
symfony/serializer v4.2.2 Symfony Serializer Component
如果(在您的示例中)surgeries
是 ManyToMany 关系,您可以轻松使用 IRI 并创建实体。如果patientDiseases
是 OneToMany(实际上也是 ManyToMany,但有额外的属性),在对象集合内部使用 IRI 会返回上述异常。对象规范化看起来很奇怪:
["object", "App\\Entity\\Disease"], -> $object
["integer", 0], -> $attribute, but here it uses key 0 from array/collection instead of 'disease'?!
["string", "\/api\/diseases\/4"], -> $value
经过多次尝试,我已经能够找到一种解决方法。此处具有预期名称的实体PatientDisease
必须定义为 ApiResource 并至少具有强制性的 GET itemOperation(这很容易成为始终返回“未找到”的虚拟控制器)。然后 ApiPlatform 可能会更好地理解对象集合的格式,并成功创建新的嵌入式实体。
我不知道这是预期的行为还是错误。但我希望这对其他人也有帮助:-)
推荐阅读
- php - 致命错误:未捕获的错误:找不到类“Elementor\Controls_Manager”
- android - 关闭父活动时出现 BiometricPrompt onAuthenticationSucceeded 错误
- python - 从 Igraph 的 community_infomap 返回码长
- python - 运算符两侧具有相同数据框的 for 循环
- regex - 项目之间文本的正则表达式
- java - 如何在 Java 中自动生成内部循环
- python-3.x - Twilio Python Whatsapp api
- vue.js - 当在 webpack 中使用 vue.esm-bundler.js 时,Vue 3 供应商捆绑包因 @babel/parser/lib 而膨胀
- clang - 当尝试在 Linux 系统上使用 release/10.x 和 master 分支上的 llvm-10.0 构建 Halide 时,面临以下问题
- python - 尝试对输入应用渐变时出错