Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

fix: interface & class required parameters #112

Closed vcing closed 4 years ago

vcing commented 4 years ago

Fixes #106 使用validationModel中的required和配置中的strictNullChecks一起来判断是否必填项 该方案改动较小,从规范来看最好还是在IPropDef中增加required字段.

Manweill commented 4 years ago

@vcing 其实以上功能我都没有使用过,只要整体没有影响,也不影响其他得功能,然后又合理,我都乐意合并进去

xxbld commented 3 years ago

从生成代码的结果来看,这是一个破坏性的改动!! @vcing @Manweill 这个改动的会影响从低版本升级,后端并不一定会配合添加required 建议修改strictNullChecks 类型 true | false | ‘required’,来做判断 以便兼容之前的 strictNullChecks:true 我之前用的0.10

Manweill commented 3 years ago

@xxbld 能贴一下影响的代码看下吗?最好有前后的生成结果。如果不方便公开的话,可以直接私发我邮件或者TG.

xxbld commented 3 years ago

后台没写 required ,但是使用了strictNullChecks:true

//之前结果( interface 或class ) strictNullChecks:true  
interface AA{
  prop : string
}
//之后结果 strictNullChecks:true 由于没有required验证 , 全部会变成 ?:
interface AA{
  prop ?: string
}
vcing commented 3 years ago

确实会产生这种影响, 但是也正是要解决的问题. 之前的 strictNullChecks 是会无视文档required标示的.只根据strictNullChecks来设置optional mark. 现在的代码是会优先根据文档required标示来设置. 如果文档没有标示那么 canNull就永远是true 也就是一直会加optional mark. 提交的时候也想过这个方案不是最合适的. 但是是改动最小可以解决bug的. strictNullChecks 增加类型 'required' 我觉得可以, 只在 'required' 下从文档获取 required标示.

Manweill commented 3 years ago

@vcing @xxbld 跟我记忆有点偏差,我印象中,在没合并这个PR 之前是,如果strictNullChecks :true, 那会按照required来写来生成是否有问号,如果,如果是false,则都是可空。也有可能是我自己就记错了,我可能需要找个时间来整理一下并且看一下代码。如果你们有时间的话,也可以看下

Manweill commented 3 years ago

@vcing @xxbld 看了目前的代码,跟我记忆有初入... 那这个方案,改成 strictNullChecks:true ,则按required 来判断,strictNullChecks:false或者等null,则都是可空

xxbld commented 3 years ago

@Manweill 之前只有请求参数(params)是严格按照requrired来生成的,interface 和class 不是; 可以看git log