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

YAPI中枚举备注功能,autos是不是不支持,或者在哪能找到文档 #36

Closed
BangXinWei opened this issue Sep 15, 2021 · 12 comments

Comments

@BangXinWei
Copy link

在yapi中,对某个枚举,添加了枚举备注。
运行autos 生成的 yapi-swagger.json 中,enum有对应enumDesc是有的,然而在最终生成的ts枚举中,没有出现。
是不是枚举备注填写的格式不正确?
yapi和autos都没找到相关的文档。

@gogoyqj
Copy link
Owner

gogoyqj commented Sep 16, 2021

@BangXinWei 可以贴一下 swagger.json 内容

@BangXinWei
Copy link
Author

BangXinWei commented Sep 16, 2021

@gogoyqj
---- 是空格

"properties":{
--"id": {
--"type": "string",
--"description": "权限ID",
----"enum": [
----"superAdmin",
----"userManager",
----],
----"enumDesc": "超级管理员权限\n用户管理权限"
--},
}

swagger枚举注释,就是这个"enumDesc"

目前生成的结果是
/*
*superAdmin 权限ID
*/
superAdmin

@BangXinWei
Copy link
Author

BangXinWei commented Sep 16, 2021

还有个问题
number 类型枚举,不会生成对应枚举,字段类型会是number

"properties": {
--“id”: "test",
--"type": "number",
--"description": "test 备注",
----"enum": [
------1,
------2,
------],
--},
}

{test : number} //不会是枚举

number的枚举,不会生成,只会test 的类型 会是number

@gogoyqj
Copy link
Owner

gogoyqj commented Sep 16, 2021

还有个问题
number 类型枚举,不会生成对应枚举,字段类型会是number

"properties": {
--“id”: "test",
--"type": "number",
--"description": "test 备注",
----"enum": [
------1,
------2,
------],
--},
}

{test : number} //不会是枚举

number的枚举,不会生成,只会test 的类型 会是number

这个我验证了,会生成如下结构的 enum:

export enum NoEnum {
    _1 = '1' as any,
    _2 = '2' as any
  }

@gogoyqj
Copy link
Owner

gogoyqj commented Sep 16, 2021

@gogoyqj
---- 是空格

"properties":{
--"id": {
--"type": "string",
--"description": "权限ID",
----"enum": [
----"superAdmin",
----"userManager",
----],
----"enumDesc": "超级管理员权限\n用户管理权限"
--},
}

swagger枚举注释,就是这个"enumDesc"

目前生成的结果是
/*
*superAdmin 权限ID
*/
superAdmin

确实不支持,enumDesc 是 YAPI 自定义的字段

@gogoyqj
Copy link
Owner

gogoyqj commented Sep 16, 2021

@gogoyqj
---- 是空格
"properties":{
--"id": {
--"type": "string",
--"description": "权限ID",
----"enum": [
----"superAdmin",
----"userManager",
----],
----"enumDesc": "超级管理员权限\n用户管理权限"
--},
}
swagger枚举注释,就是这个"enumDesc"
目前生成的结果是
/*
*superAdmin 权限ID
*/
superAdmin

确实不支持,enumDesc 是 YAPI 自定义的字段

倒是可以考虑把 enumDesc 拼凑到 description 一起

@BangXinWei
Copy link
Author

BangXinWei commented Sep 17, 2021

@gogoyqj
---- 是空格
"properties":{
--"id": {
--"type": "string",
--"description": "权限ID",
----"enum": [
----"superAdmin",
----"userManager",
----],
----"enumDesc": "超级管理员权限\n用户管理权限"
--},
}
swagger枚举注释,就是这个"enumDesc"
目前生成的结果是
/*
*superAdmin 权限ID
*/
superAdmin

确实不支持,enumDesc 是 YAPI 自定义的字段

倒是可以考虑把 enumDesc 拼凑到 description 一起

可以
我们这个枚举备注,是按照枚举一样,一行一行的
可以将枚举和备注对应起来,拼在description 里

@BangXinWei
Copy link
Author

还有个问题
number 类型枚举,不会生成对应枚举,字段类型会是number
"properties": {
--“id”: "test",
--"type": "number",
--"description": "test 备注",
----"enum": [
------1,
------2,
------],
--},
}
{test : number} //不会是枚举
number的枚举,不会生成,只会test 的类型 会是number

这个我验证了,会生成如下结构的 enum:

export enum NoEnum {
    _1 = '1' as any,
    _2 = '2' as any
  }

这个我测了下,如果YAPI这个字段是string类型枚举,确实会生成 _enum的枚举。
但是如果该字段是number或者integer类型,是不会生成的

@BangXinWei
Copy link
Author

@gogoyqj 大佬,有时间帮看看啊!主要可能是数字枚举的问题

@gogoyqj
Copy link
Owner

gogoyqj commented Sep 28, 2021

@gogoyqj 大佬,有时间帮看看啊!主要可能是数字枚举的问题

这样的数字枚举在 ts 是非法的,所以不能生成(如以下示例,不知道我有没有 get 到你的意思)

enum A {
  1 = 1,
  2 = 2,
}

@BangXinWei
Copy link
Author

@gogoyqj 大佬,有时间帮看看啊!主要可能是数字枚举的问题

这样的数字枚举在 ts 是非法的,所以不能生成(如以下示例,不知道我有没有 get 到你的意思)

enum A {
  1 = 1,
  2 = 2,
}

生成以下这样的呢,就和字符类型数字枚举一样

enum A {
  _1 = 1,
  _2 = 2,
}

@gogoyqj
Copy link
Owner

gogoyqj commented Sep 28, 2021

@gogoyqj 大佬,有时间帮看看啊!主要可能是数字枚举的问题

这样的数字枚举在 ts 是非法的,所以不能生成(如以下示例,不知道我有没有 get 到你的意思)

enum A {
  1 = 1,
  2 = 2,
}

生成以下这样的呢,就和字符类型数字枚举一样

enum A {
  _1 = 1,
  _2 = 2,
}

现在就是这么生成的,在前边加了一个下划线

@gogoyqj gogoyqj closed this as completed Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants