Files
brapi-java/docs/problem_fix/03-fix-doing/06-get-commoncropnames.md

46 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# GET /commoncropnames
> 来源BrAPI v2.1 校验报告03-fix.md
## 概要
| 项 | 值 |
| --- | --- |
| 状态 | warning |
| 方法 | GET |
| URL | `/brapi/v2/commoncropnames` |
| 完整 URL | `http://localhost:8081/brapi/v2/commoncropnames` |
| 路径模板 | `GET /commoncropnames` |
| 模块 | Common Crop Names |
| 响应时间 | 264 ms |
## 校验详情
```
GET /commoncropnames
Common Crop Names
264 ms
schema mismatch
schema mismatch
Json matches schema: schemas/v2.1/metadata.json (schema mismatch) — Schema: schemas/v2.1/metadata.json
Server response is not valid JSON.
Json matches schema: schemas/v2.1/CommonCropNames/getCommoncropnamesResponse.json (schema mismatch) — Schema: schemas/v2.1/CommonCropNames/getCommoncropnamesResponse.json
Server response is not valid JSON.
```
---
## 修复说明
- **根因**BrAPI 校验器对响应 JSON 较严格;`@context: null`、匿名请求下 metadata 中异常的 token 过期 WARNING年份溢出以及分页 `totalPages``pageSize=0` 时可能触发除零均可能导致「Server response is not valid JSON」或 metadata schema 失败。
- **修复**
- `BrApiJacksonConfig` + `BrApiJsonResponseAdvice`:序列化时省略 null 字段(含 `@context`)。
- `BrAPIController.getStatusMessages()`:匿名用户不再写入 token 过期 WARNING仅对真实过期时间写入状态。
- `PagingUtility.calculateMetaData()`:避免 `pageSize<=0` 时除零。
- `CropService.getCrops()`:过滤空作物名并排序,保证 `result.data` 为稳定字符串数组。
- **验证**:对照 BrAPI v2.1 `metadata.json``getCommoncropnamesResponse.json`,当前 `GET /brapi/v2/commoncropnames` 响应通过 jsonschema 校验;种子数据 `R__init_data_01_crops.sql` 提供 Tomatillo、Paw Paw、Maize`minItems: 1`)。
---
**状态:已完成**