api-platform.com 相关问题

此标记应用于与API平台相关的所有问题,这是一个用于创建API优先Web项目的框架。 API平台包含一组工具,可轻松构建功能齐全的超媒体API(现代格式,文档,授权,过滤,订购,缓存,测试......)以及支撑客户端应用程序。它建立在Symfony组件(PHP)和React(JavaScript)之上。

api_platform 产生错误“没有找到 uri [/index/_doc/_search] 和方法 [POST] 的处理程序”

当尝试通过 fos_elastica-bundle (v6.0.0) 将 elasticsearch (v7.9.3) 实现到我的 Symfony (v5.3.10) - App with api_platform (v2.6.6) 中时,我不断收到此错误: “{”错误&quo...

回答 2 投票 0

Symfony Api 平台:通过自定义实体方法对结果进行排序

在我的 Symfony Api 平台项目中,我有一个实体社区,其中有一个自定义方法 getTotalMembers(),该方法返回社区中的成员数量。然而,当我尝试订购结果时,它

回答 1 投票 0

Doctrine查询扩展按同表的相关实体过滤

我正在我的 Symfony 项目上使用 API 平台。 我有 3 个表: account / user / account_user 一个帐户可以有一个父帐户。 当我 GET /accounts 时,我需要返回所有具有

回答 1 投票 0

Api 平台 - 生产环境构建失败:未找到 nuxt

我使用API平台3.2。 我正在使用 Nuxt 部署 API 平台应用程序,当我运行命令时: SERVER_NAME=您的域名.example.com \ APP_SECRET=ChangeMe \ POSTGRES_PASSWORD=ChangeMe \

回答 1 投票 0

向实体添加关系会导致奇怪的 ORM 映射错误

在 Symfony Api 平台应用程序中,使用 Maker Bundle 将关系字段“Owner”添加到“Community”实体导致所有“Get”api 调用返回相同的错误。 ...

回答 2 投票 0

为什么我在 symfony 中遇到虚拟属性错误?

我有这个实体 我有这个实体 <?php namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; #[ApiResource( normalizationContext: ["groups" => ["contact", "contact_read"]], denormalizationContext: ["groups" => ["contact", "contact_write"]] )] #[ORM\Entity] class Contact { // ... #[ORM\OneToMany(targetEntity: Email::class, mappedBy: "contact")] #[Groups(["contact"])] private $emails; // ... public function __construct() { $this->emails = new ArrayCollection(); } // ... public function getEmails() { return $this->emails; } // ... } 我想添加虚拟财产 #[Groups(["contact"])] public function getPrimaryEmail() { $criteria = Criteria::create()->where(Criteria::expr()->eq("is_primary", true)); $matches = $this->emails->matching($criteria); return ($matches->count()) ? $matches->first()->getAccount() : null; } 并且它有效......但如果方法的名称是getEmail(),则无效 #[Groups(["contact"])] public function getEmail() { $criteria = Criteria::create()->where(Criteria::expr()->eq("is_primary", true)); $matches = $this->emails->matching($criteria); return ($matches->count()) ? $matches->first()->getAccount() : null; } 在这种情况下我会收到此错误 多对关系的意外不可迭代值 这是为什么呢?有没有办法让方法保持getEmail()? 我正在使用 API Platform 3.2.10 和 symfony 6.4.1 完全错误: { "@id": "/errors/400", "@type": "hydra:Error", "title": "An error occurred", "detail": "Unexpected non-iterable value for to-many relation.", "status": 400, "type": "/errors/400", "trace": [ { "file": "vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php", "line": 192, "function": "getAttributeValue", "class": "ApiPlatform\\Serializer\\AbstractItemNormalizer", "type": "->" }, { "file": "vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php", "line": 171, "function": "normalize", "class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer", "type": "->" }, { "file": "vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php", "line": 111, "function": "normalize", "class": "ApiPlatform\\Serializer\\AbstractItemNormalizer", "type": "->" }, { "file": "vendor/symfony/serializer/Debug/TraceableNormalizer.php", "line": 58, "function": "normalize", "class": "ApiPlatform\\JsonLd\\Serializer\\ItemNormalizer", "type": "->" }, { "file": "vendor/symfony/serializer/Serializer.php", "line": 159, "function": "normalize", "class": "Symfony\\Component\\Serializer\\Debug\\TraceableNormalizer", "type": "->" }, { "file": "vendor/api-platform/core/src/Hydra/Serializer/CollectionNormalizer.php", "line": 91, "function": "normalize", "class": "Symfony\\Component\\Serializer\\Serializer", "type": "->" }, { "file": "vendor/api-platform/core/src/Serializer/AbstractCollectionNormalizer.php", "line": 106, "function": "getItemsData", "class": "ApiPlatform\\Hydra\\Serializer\\CollectionNormalizer", "type": "->" }, { "file": "vendor/api-platform/core/src/Hydra/Serializer/PartialCollectionViewNormalizer.php", "line": 50, "function": "normalize", "class": "ApiPlatform\\Serializer\\AbstractCollectionNormalizer", "type": "->" }, { "file": "vendor/api-platform/core/src/Hydra/Serializer/CollectionFiltersNormalizer.php", "line": 91, "function": "normalize", "class": "ApiPlatform\\Hydra\\Serializer\\PartialCollectionViewNormalizer", "type": "->" }, { "file": "vendor/symfony/serializer/Debug/TraceableNormalizer.php", "line": 58, "function": "normalize", "class": "ApiPlatform\\Hydra\\Serializer\\CollectionFiltersNormalizer", "type": "->" }, { "file": "vendor/symfony/serializer/Serializer.php", "line": 159, "function": "normalize", "class": "Symfony\\Component\\Serializer\\Debug\\TraceableNormalizer", "type": "->" }, { "file": "vendor/symfony/serializer/Serializer.php", "line": 138, "function": "normalize", "class": "Symfony\\Component\\Serializer\\Serializer", "type": "->" }, { "file": "vendor/symfony/serializer/Debug/TraceableSerializer.php", "line": 47, "function": "serialize", "class": "Symfony\\Component\\Serializer\\Serializer", "type": "->" }, { "file": "vendor/api-platform/core/src/State/Processor/SerializeProcessor.php", "line": 65, "function": "serialize", "class": "Symfony\\Component\\Serializer\\Debug\\TraceableSerializer", "type": "->" }, { "file": "vendor/api-platform/core/src/State/Processor/WriteProcessor.php", "line": 42, "function": "process", "class": "ApiPlatform\\State\\Processor\\SerializeProcessor", "type": "->" }, { "file": "vendor/api-platform/core/src/Symfony/Controller/MainController.php", "line": 111, "function": "process", "class": "ApiPlatform\\State\\Processor\\WriteProcessor", "type": "->" }, { "file": "vendor/symfony/http-kernel/HttpKernel.php", "line": 181, "function": "__invoke", "class": "ApiPlatform\\Symfony\\Controller\\MainController", "type": "->" }, { "file": "vendor/symfony/http-kernel/HttpKernel.php", "line": 76, "function": "handleRaw", "class": "Symfony\\Component\\HttpKernel\\HttpKernel", "type": "->" }, { "file": "vendor/symfony/http-kernel/Kernel.php", "line": 197, "function": "handle", "class": "Symfony\\Component\\HttpKernel\\HttpKernel", "type": "->" }, { "file": "vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php", "line": 35, "function": "handle", "class": "Symfony\\Component\\HttpKernel\\Kernel", "type": "->" }, { "file": "vendor/autoload_runtime.php", "line": 29, "function": "run", "class": "Symfony\\Component\\Runtime\\Runner\\Symfony\\HttpKernelRunner", "type": "->" }, { "file": "public/index.php", "line": 5, "function": "require_once" } ], "hydra:title": "An error occurred", "hydra:description": "Unexpected non-iterable value for to-many relation." } 可能是因为 symfony 序列化器在规范化过程中将 getEmail 确定为 emails 属性的访问器,从而导致类型不匹配,因为 getEmail 返回单个对象,而 emails 是一个集合。 为了避免这些“晚期”错误,您可以通过向每个属性、方法参数和返回添加严格类型来改进代码。 它仍然会失败,但会给你更容易理解的错误消息。 <?php namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; #[ApiResource( normalizationContext: ["groups" => ["contact", "contact_read"]], denormalizationContext: ["groups" => ["contact", "contact_write"]] )] #[ORM\Entity] class Contact { // ... /** * @var Collection|Email[] */ #[ORM\OneToMany(targetEntity: Email::class, mappedBy: "contact")] #[Groups(["contact"])] private Collection $emails; // ... public function __construct() { $this->emails = new ArrayCollection(); } // ... /** * @return Collection|Email[] */ public function getEmails(): Collection { return $this->emails; } // ... #[Groups(["contact"])] public function getEmail(): ?Email { $criteria = Criteria::create()->where(Criteria::expr()->eq("is_primary", true)); $matches = $this->emails->matching($criteria); return ($matches->count()) ? $matches->first() : null; } }

回答 1 投票 0

Apiplatform 忽略组上下文

apiplatform 序列化程序完全忽略“groups”属性。 下面的代码: 控制器: $response = $this->serializer->deserialize($params, User::class, 'json'); 返回 $this->json($

回答 1 投票 0

在uri中使用两个标识符

我得到了一个在日期时间列上分区的表。 如果我让 ApiPlateform 获取项目,查询将检查所有分区以找到该项目。 我希望能够发送日期...

回答 1 投票 0

在 API 平台上的自定义状态提供程序中添加自定义 http 标头的最佳方式

我在 API 平台上与 CustomStateProviders 合作,以这种方式装饰返回 DTO(“表示”),我喜欢它(隐藏一些字段,...) 我使用标准的 ApiPlatform\Doctrine\Orm\St...

回答 1 投票 0

Api 平台防止 IRI @ID 为空时序列化

简短的问题:我希望能够序列化还没有 ID 的 ApiResource。 我最近从 v2.6 升级到 api-platform v3.2。过去有用的“功能”之一是我可以

回答 1 投票 0

API平台不返回实体的属性

我使用 API Platform 2.7 来实现非常简单的 API;到目前为止,我的 PoC 看起来像这样: 我使用 API Platform 2.7 来实现非常简单的 API;到目前为止,我的 PoC 看起来像这样: <?php namespace App\Entity; use ApiPlatform\Core\Annotation\ApiProperty; use ApiPlatform\Core\Annotation\ApiResource; use App\Entity\Embeddable\DbConfig; use App\Entity\Embeddable\E1000Structure; use App\Validator\Constraints AS PvetAssert; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Softspring\DoctrineTemplates\Entity\Traits\AutoId; use Softspring\DoctrineTemplates\Entity\Traits\TimestampMarks; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity(repositoryClass="App\Repository\PlantRepository") * @ORM\Table(name="plant") * @ORM\HasLifecycleCallbacks() * @ORM\Cache(region="small_cache", usage="NONSTRICT_READ_WRITE") * @ORM\EntityListeners({"App\Entity\EventListener\PlantCacheClearListener"}) * * @ApiResource( * normalizationContext={"groups"={"plant:read"}}, * denormalizationContext={"groups"={"plant:write"}}, * attributes={"security_post_denormalize"="is_granted('ROLE_ADMIN') or (user != null and user.client == object.client)"}, * ) */ class Plant { const MAP_LEVEL2_NO = 0 ; // No existe el mapa nivel 2 const MAP_LEVEL2_TRACKERS = 1 ; // Nivel 2 representa trackers, los recuadros principales se buscarán mediante la columna TR const MAP_LEVEL2_STRINGBOXES = 2 ; // Nivel 2 representa stringboxes, los recuadros principales se buscarán mediante la columna SB const NO_OPTION = 0; const NORMAL = 1; const QUARTILE = 2; const TEN_MIN = 10; const FIFTEEN_MIN = 15; const STANDARD_WEEK = 0; const AMERICAN_WEEK = 1; use AutoId; use TimestampMarks; use Traits\Key; /** * @ORM\Column(type="string", nullable=true) * @Assert\NotBlank() * * @Groups({"plant:read", "plant:write"}) */ protected ?string $name = null; /** * @ORM\ManyToOne(targetEntity="Client", inversedBy="plants") * @ORM\JoinColumn(name="client_id", referencedColumnName="id", onDelete="CASCADE") * * @Groups({"plant:read", "plant:write"}) * @ApiProperty(readableLink=false, writableLink=false) */ protected ?Client $client = null; /** * @ORM\Column(type="string", nullable=false, length=100, options={"fixed":true}) * @Assert\NotBlank() * * @Groups({"plant:read", "plant:write"}) */ protected ?string $timezone = null; [...] } 请求该资源时会返回这三个字段;现在我已经从类中删除了 normalizationContext 和 denormalizationContext 注释,并且字段上的注释认为这样应该返回整个实体(或者至少尝试直到遇到序列化问题),但事实并非如此。 回复仅包括: { "@id": "/api/plants/24", "@type": "Plant" }, 我是否误解了docs? 当操作中没有上下文组,但属性有组时,它们不会被序列化。 您有三个选择: 将组添加到操作的上下文中 从属性中删除所有组 将“默认”组添加到属性

回答 1 投票 0

使用附加数据扩展 ApiPlatforms GetCollection 操作 JsonLd 响应

Symfony 6、Api 平台 3、Php 8 我有 Symfony-Doctrine 实体,已使用 Api-Platform 的 ApiResource 注释对其进行了注释,并且我正在使用 GetCollection 操作,该操作的作用是...

回答 1 投票 0

重置密码 API Platform 3.x - 初始化前不得访问

API Platform 的文档没有提供关于此的很好的文档,这是我发现的唯一的东西,但这不起作用:https://api-platform.com/docs/core/messenger/#using-messenger-带输入-

回答 1 投票 0

优化 Symfony API 中默认值的响应过滤(例如 isActive)

寻求有关在 Symfony 中优化响应过滤的指导,重点是实现默认值,例如将 isActive 设置为 true。尽管付出了努力,我当前的解决方案仍然不够理想

回答 1 投票 0

Symfony API 平台:如何从 Postman 请求获取 application/json 格式

当我使用 API Platform 向我的 CRUD API 发送请求时,我收到以下内容 { "@context": "/symfony_test_server/public/apip/contexts/User", “@id”:“/

回答 1 投票 0

具有用户角色的 Api 平台搜索过滤器

我尝试使用 Api 平台 SearchFilter 以及 User.php 实体中 json PostgreSQL 列角色的精确值: #[ApiFilter(SearchFilter::class, 属性: ['角色' => '精确'] #[ORM\Col...

回答 1 投票 0

API 平台:在请求声明为无状态时使用了会话

我启动了 Symfony 演示并使用 MakerBundle 创建了一个新的 API 资源。 $ php bin/console make:entity --api-resource 现在我可以导航到 /api 来查看我的新资源。 GET 请求...

回答 1 投票 0

使用api platform/admin和react-admin生成管理界面时出错

确实,我正在使用api平台使用Symfony开发api。但是,当我想使用 api platform/admin 和 react-admin 生成管理界面时,我在控制台中收到此错误: @api-

回答 1 投票 0

使用 api-platform/admin 时出现问题

我来寻求你的帮助。事实上,我正在使用 api 平台与 Symfony 一起开发 api。但是,当我想使用 api platform/admin 和 react-admin 生成管理界面时,我建议...

回答 1 投票 0

VichUploaderBundle ContentUrl 未显示在响应正文 Symfony 7 上

vich_上传者: 数据库驱动程序:orm 元数据: 类型:属性 映射: 媒体对象: uri_前缀:/media upload_destination: '%kernel.project_dir%/public/media' # 会仁...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.