Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the request and response parameter types are Date, I hope to customize the format. #610

Open
Star-Forever-007 opened this issue Sep 19, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@Star-Forever-007
Copy link

Star-Forever-007 commented Sep 19, 2023

Summary(关于这个pr的描述)

When the request and response parameters include Date types, regardless of java.sql.Date, joda.DateTime, LocalDate, LocalDateTime, or other date types, they are currently all returned as Strings in the yyyy-MM-dd HH:mm:ss format.
当请求参数以及响应参数中有Date类型,不论java.sql.Date , joda.DateTime, LocalDate, LocalDateTime 等日期类型,现在均返回string及 yyyy-MM-dd HH:mm:ss 格式

Basic example(pr的用例)

@DaTa
public class RequestUserParam{
private Date createTime;
private Date updateTime;
}

@DaTa
public class ResponseUserVo{
private Date createTime;
private Date updateTime;
}
All date types are String and cannot be changed.
所有日期类型均为string并不可变更

Motivation(提出这个pr目的)

During implementation, we support various inputs such as yDuring implementation, we support various inputs such as y-dd HH:mm while the response parameter date types are uniformly standardized to be returned as timestamps. Therefore, there is a discrepancy between the generated documentation's response parameters and the actual requests.

It is expected that the date type can be customized with user-defined types and formats.
Example:
我们在实施的过程中,输入支持 yyyy-MM-dd HH:mm:ss 或时间戳等多种输入,而响应参数的日期类型则统一规范了返回为时间戳,故而生成文档的响应参数与真实请求出现了差异

期望日期类型可以自定义类型及格式
例:

dateFormat:{
    type: "timestamp / string",
    fortmat: "yyyy/MM/dd HH:mm:ss"
}

When the dateFormat type is set to timestamp, it should return a long type; other formats can be customized.
当dateFormat type为 timestamp时,则返回long类型,其他可以自定义格式

@Star-Forever-007 Star-Forever-007 added the enhancement New feature or request label Sep 19, 2023
@shalousun
Copy link
Collaborator

shalousun commented Sep 19, 2023

@Star-Forever-007
This is too complex. I think it would be sufficient to support the time type annotations of the JSON library. For interfaces, time can only be of two types: string/long. As for the intermediate class casting, we do not have the technology to support it, which makes it complex for users and also complicates the maintenance of Smart-Doc's code.
这样太复杂了,我觉得也就是支持下json库时间类型注解就可以了,时间对于接口就只能是string/long两种类型。至于中间写类强转的我们没有支持的技术,用户用起来复杂,smart-doc代码维护也复杂

@Star-Forever-007
Copy link
Author

Star-Forever-007 commented Sep 20, 2023

下图是我们使用spring boot默认继承的jackson下对全局日期类型的配置,但仅对java.util.Date有效,为此我们也进行了独立的补充,补充这里就不再做赘述了,
image
json库时间类型的注解,如果这样的话,所有的bean实体都需要加注解,实际上我们更期望有一个默认的,注解是特殊场景下标注的,这样能够满足默认和独立双重需要
个人的想法不知道是否符合你们的要求,
即: smart-doc.json 中增加如下配置,可选,文档输出时有则优先使用,没有则走原始逻辑
dateFormat:{
type: "timestamp / string",
fortmat: "yyyy/MM/dd HH:mm:ss"
}
格式优先级: bean上的jackson/fastjson日期类型注解 > smart-doc.json#dateFormat > 兜底默认
个人感觉:最高级别的实施复杂度高于后两个次两级的,具体你们在这里更有经验,看看是否可以规划版本进行实施。

@shalousun shalousun changed the title 请求参数以及响应参数类型是Date类型时,希望可以自定义格式 When the request and response parameter types are Date, I hope to customize the format. Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants