如何使用flask_restplus定义字典字段以在使用swagger codegen生成的go代码中使用?
时间:2024-04-14
浏览:214
作者:佚名
一分耕耘,一分收获!既然打开了这篇文章《如何使用flask_restplus定义字典字段以在使用swagger codegen生成的go代码中使用?》,就坚持看下去吧!文中内容包含等等知识点...希望你能在阅读本文后,能真真实实学到知识或者帮你解决心中的疑惑,也欢迎大佬或者新人朋友们多留言评论,多给建议!谢谢!
我使用 swagger cli 生成 go 代码来调用我的 flask 应用程序。 swagger codegen 将使用 flask_restplus 模型定义的 fields.raw 类型转换为 go 中的 *interface{}
在go中将值赋给*interface{}类型的字段会返回
prog.go:18:26:无法使用notebook_spec_secrets(类型 map[string]string) 作为赋值中的类型 *interface {}:*interface {} 是指向接口的指针,而不是接口
你可以在这里测试一下 https://play.golang.org/p/sfe9qr-72_g
一个快速而肮脏的修复将通过 swagger cli 更改生成的代码并进行更改
notebookspec *接口{}
到
notebookspec 接口{}
是否可以将字典转换为go中的*interface{}? (我的google搜索显示go中指向接口的指针无效并且逻辑上不正确)
如何使用flask-restplus定义字典字段
run_definition = api.model('Run definition',
{
'notebook_spec_secrets':
fields.Raw(required=False,
example={
"eventhub_source_cs": "Endpoint=sb://xxxx.servicebus.windows.net/;SharedAccessKeyName=xxxx;SharedAccessKey=xxxx=;EntityPath=sourceeh",
"eventhub_destination_cs": "Endpoint=sb://xxxx.servicebus.windows.net/;SharedAccessKeyName=xxxx;SharedAccessKey=xxxx=;EntityPath=desteh",
"adl2_destination_oauth2_clientid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"adl2_destination_oauth2_clientsecret": "xxxx=",
"adl2_destination_oauth2_tenantid": "xxxx=",
"adl2_destination_cs": "abfss://<file-system-name>@<storage-account-name>.dfs.core.windows.net/folder1",
})})解决方案
我不确定为什么它会生成一个指向接口的指针,但仍然可以通过将映射显式转换为 interface{} 然后获取地址来分配给它
那:
notebook_spec_secrets := map[string]string{
"eventhub_source_cs": "1",
"eventhub_destination_cs": "2",
"adl2_destination_oauth2_clientid": "3",
"adl2_destination_oauth2_clientsecret": "4",
"adl2_destination_oauth2_tenantid": "5",
"adl2_destination_cs": "6",
}
var nssi interface{} = notebook_spec_secrets
definition.NotebookSpec = &nssi
https://play.golang.org/p/rHrMH_jF_oS
理论要掌握,实操不能落!以上关于《如何使用flask_restplus定义字典字段以在使用swagger codegen生成的go代码中使用?》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
站内热门
最新文章
热门专题
