英文:
Golang swaggo nullable
问题
我使用的是swaggo/swag v1.8.6。
我该如何设置字段可为空的通知?
我尝试写 extensions:"x-nullable",但没有效果。
type MyStruct struct {
Field1 string `json:"field_id,omitempty" extensions:"x-nullable"`
}
英文:
I use swaggo/swag v1.8.6
how can I set notice that field is nullable?
I tried to write extensions:"x-nullable", but it has no effect
type MyStruct struct {
Field1 string `json:"field_id,omitempty" extensions:"x-nullable"`
}
答案1
得分: 1
我已经创建了一个解决方法,通过在<project_dir>/docs中创建fix.sh文件:
#!/bin/sh
sed -i "s/x-nullable/nullable/g" ./docs/docs.go
sed -i "s/x-omitempty/omitempty/g" ./docs/docs.go
sed -i "s/x-nullable/nullable/g" ./docs/swagger.json
sed -i "s/x-omitempty/omitempty/g" ./docs/swagger.json
sed -i "s/x-nullable/nullable/g" ./docs/swagger.yaml
sed -i "s/x-omitempty/omitempty/g" ./docs/swagger.yaml
然后通过以下命令运行swaggo:
swag init -g cmd/app/main.go && ./docs/fix.sh
英文:
I have made a workaround
by creating fix.sh at <project_dir>/docs
#!/bin/sh
sed -i "s/x-nullable/nullable/g" ./docs/docs.go
sed -i "s/x-omitempty/omitempty/g" ./docs/docs.go
sed -i "s/x-nullable/nullable/g" ./docs/swagger.json
sed -i "s/x-omitempty/omitempty/g" ./docs/swagger.json
sed -i "s/x-nullable/nullable/g" ./docs/swagger.yaml
sed -i "s/x-omitempty/omitempty/g" ./docs/swagger.yaml
and running swaggo by
swag init -g cmd/app/main.go && ./docs/fix.sh
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论