Я бы хотел выполнить операции по умолчанию для объектов с помощью odm. Я сделал с ORM, это было хорошо, но у меня есть проблемы с ODM.
Я создал проект в терминале с composer
composer create-project symfony/skeleton bookshop-api
Установил серверный компонент платформы API в этом скелете с
composer req api
Установил пакет mongodb с
composer req doctrine/mongodb-odm-bundle
Изменена конфигурация API Platform для добавления правильного пути отображения:
# api/config/packages/api_platform.yaml
api_platform:
# ...
mapping:
paths: ['%kernel.project_dir%/src/Entity', '%kernel.project_dir%/src/Document']
# ...
Создана папка с документами в sr c и документы «Предложение и продукт», как показано на приведенной ниже ссылке:
https://api-platform.com/docs/core/mongodb/#mongodb -поддержка
Изменен файл env с этим:
MONGODB_URL = mongodb + srv: // test123:@cluster0-woj6t.mongodb.net/test MONGODB_DB = api
Когда я запускаю его в localhost. Это показывает чванство пользовательского интерфейса. Проблема в том, что когда я пытаюсь опубликовать, поставить, любую операцию для предложения или продукта, он говорит это
{
"@context": "/api/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Invalid IRI \"product1\".",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 417,
"args": []
},
{
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "denormalizeRelation",
"file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 684,
"args": [
[
"string",
"product"
],
[
"object",
"ApiPlatform\\Core\\Metadata\\Property\\PropertyMetadata"
],
[
"string",
"App\\Document\\Product"
],
[
"string",
"product1"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Product"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"11906de107f2fd977c81c32553e19974"
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "createAttributeValue",
"file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 347,
"args": [
[
"string",
"product"
],
[
"string",
"product1"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Offer"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"11906de107f2fd977c81c32553e19974"
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "setAttributeValue",
"file": "/Users/goksel/bookshop-api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
"line": 333,
"args": [
[
"object",
"App\\Document\\Offer"
],
[
"string",
"product"
],
[
"string",
"product1"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Offer"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"11906de107f2fd977c81c32553e19974"
]
}
]
]
},
{
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "->",
"function": "denormalize",
"file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 222,
"args": [
[
"array",
{
"description": [
"string",
"description of first offer"
],
"price": [
"integer",
1500
],
"product": [
"string",
"product1"
]
}
],
[
"string",
"App\\Document\\Offer"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Offer"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"11906de107f2fd977c81c32553e19974"
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "denormalize",
"file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php",
"line": 117,
"args": [
[
"array",
{
"description": [
"string",
"description of first offer"
],
"price": [
"integer",
1500
],
"product": [
"string",
"product1"
]
}
],
[
"string",
"App\\Document\\Offer"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Offer"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
],
"api_denormalize": [
"boolean",
true
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\JsonLd\\Serializer",
"short_class": "ItemNormalizer",
"class": "ApiPlatform\\Core\\JsonLd\\Serializer\\ItemNormalizer",
"type": "->",
"function": "denormalize",
"file": "/Users/goksel/bookshop-api/vendor/symfony/serializer/Serializer.php",
"line": 185,
"args": [
[
"array",
{
"description": [
"string",
"description of first offer"
],
"price": [
"integer",
1500
],
"product": [
"string",
"product1"
]
}
],
[
"string",
"App\\Document\\Offer"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Offer"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
]
}
]
]
},
{
"namespace": "Symfony\\Component\\Serializer",
"short_class": "Serializer",
"class": "Symfony\\Component\\Serializer\\Serializer",
"type": "->",
"function": "denormalize",
"file": "/Users/goksel/bookshop-api/vendor/symfony/serializer/Serializer.php",
"line": 136,
"args": [
[
"array",
{
"description": [
"string",
"description of first offer"
],
"price": [
"integer",
1500
],
"product": [
"string",
"product1"
]
}
],
[
"string",
"App\\Document\\Offer"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Offer"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
]
}
]
]
},
{
"namespace": "Symfony\\Component\\Serializer",
"short_class": "Serializer",
"class": "Symfony\\Component\\Serializer\\Serializer",
"type": "->",
"function": "deserialize",
"file": "/Users/goksel/bookshop-api/vendor/api-platform/core/src/EventListener/DeserializeListener.php",
"line": 106,
"args": [
[
"array",
{
"description": [
"string",
"description of first offer"
],
"price": [
"integer",
1500
],
"product": [
"string",
"product1"
]
}
],
[
"string",
"App\\Document\\Offer"
],
[
"string",
"jsonld"
],
[
"array",
{
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Document\\Offer"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/offers"
],
"uri": [
"string",
"http://127.0.0.1:8000/api/offers"
],
"skip_null_values": [
"boolean",
true
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\EventListener",
"short_class": "DeserializeListener",
"class": "ApiPlatform\\Core\\EventListener\\DeserializeListener",
"type": "->",
"function": "onKernelRequest",
"file": "/Users/goksel/bookshop-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 270,
"args": [
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\RequestEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\EventDispatcher"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "::",
"function": "Symfony\\Component\\EventDispatcher\\{closure}",
"file": "/Users/goksel/bookshop-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 230,
"args": [
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\RequestEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\EventDispatcher"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"function": "callListeners",
"file": "/Users/goksel/bookshop-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 59,
"args": [
[
"array",
[
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
],
[
"object",
"Closure"
]
]
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\RequestEvent"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/Users/goksel/bookshop-api/vendor/symfony/http-kernel/HttpKernel.php",
"line": 121,
"args": [
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\RequestEvent"
],
[
"string",
"kernel.request"
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handleRaw",
"file": "/Users/goksel/bookshop-api/vendor/symfony/http-kernel/HttpKernel.php",
"line": 67,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handle",
"file": "/Users/goksel/bookshop-api/vendor/symfony/http-kernel/Kernel.php",
"line": 191,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
],
[
"boolean",
true
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "Kernel",
"class": "Symfony\\Component\\HttpKernel\\Kernel",
"type": "->",
"function": "handle",
"file": "/Users/goksel/bookshop-api/public/index.php",
"line": 25,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
]
]
}
]
}