Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Swagger document different property content for POST and GET requests

已关闭
#8,477 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
openapi, php
领域
api, documentation

调研方向

首先使用 PlaceOpportunityUsage 示例及其 ApiProperty、Groups 和嵌套规范化行为,复现 ApiPlatform 3.2 上 POST 和 GET 操作生成的 Swagger/OpenAPI 输出。跟踪操作 schema 和属性示例的生成方式,然后验证是否能够表示操作特定的 IRI 示例和嵌套属性示例。完成的标准是支持不同的 POST/GET 输出,或明确记录该限制。

由索引模型根据 Issue 内容生成。

描述

We are using ApiPlatform for 2 years to develop our API. Some properties are (denormalized/normalized) different like on write using IRI reference but on read show nested properties instead.

Even we can update and set the iri reference example on the property like:

class PlaceOpportunityUsage extends AbstractEntityHasId
{ 
/** 
* @var PlaceOpportunity|null 
*/ 
#[ORM\ManyToOne(targetEntity: PlaceOpportunity::class)] 
#[ORM\JoinColumn(referencedColumnName: 'id', nullable: false)] 
#[ApiProperty(example: '/api/opportunities/{id}')] 
#[Groups(['OpportunityUsage:write', 'OpportunityUsage:read'])] 
private ?PlaceOpportunity $opportunity = null;

We think ApiPlatform has feature to automatically set the IRI reference and put to property example without explicitly specify. Also when we set example like that, on each request body/response this property appears as large. But some requests normalizing this property as nested and returns nested object like that:

{ 
"@id": "/api/opportunity/usages/10", 
"@type": "PlaceOpportunityUsage", 
"opportunity": { 
"@id": "/api/instant/opportunities/31", 
"@type": "PlaceOpportunity", 
"status": true, 
"place": { 
"@id": "/api/places/2ffeab17-13d8-458a-abf8-f20d3ba7a08f", 
"@type": "Place", 
"name": "Uncle Wingman", 
"id": "2ffeab17-13d8-458a-abf8-f20d3ba7a08f", 
"createdAt": "2025-07-08", 
"updatedAt": "2026-05-11" 
}, 
"dayInterval": [ 
"MONDAY", 
"TUESDAY", 
"FRIDAY", 
"SATURDAY" 
], 
.... 
}, 
.... 
}

I want to show different examples on POST or GET requests. When I remove the #[ApiProperty] attribute on the property, at this time the request shows that property example as http://example.com, because we couldn't find documentation about iris property in the ApiProperty instance, we tought field for setting reference examples this didn't work.

We are using ApiPlatform 3.2, and we cannot update our version yet.

Is there a way to fix this issue?

主要语言
PHP
星标
2.6k
派生
987
平均合并
1 天 8 小时
30 天内合并 PR
90

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

api-platform/core 的其他 Issue

查看 api-platform/core 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。