Skip to content

Commit eb43548

Browse files
committed
[contrib] fix generated swagger issue for pointer fields
1 parent a453fe2 commit eb43548

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

contrib/swagger/swagger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Loop:
299299
)
300300
}
301301

302-
if p.Tag.Optional {
302+
if p.Tag.Optional || p.Optional {
303303
wrapFuncChain = wrapFuncChain.Add(
304304
func(schema *spec.Schema) *spec.Schema {
305305
spacer := ""

contrib/swagger/swagger_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ var _ = Describe("ToSwaggerDefinition", func() {
121121
// W []string `json:"w"`
122122
// TT [][]string `json:"tt"`
123123
// }
124+
// type sampleRes struct {
125+
// Out1 int `json:"out1"`
126+
// Out2 string `json:"out2"`
127+
// Sub subRes `json:"sub"`
128+
// Subs []subRes `json:"subs"`
129+
// XSub *subRes `json:"xSub"`
130+
// }
124131

125132
d := swagger.ToSwaggerDefinition(ps.Contracts[0].Request.Message)
126133
props := d.Properties.ToOrderedSchemaItems()
@@ -152,6 +159,9 @@ var _ = Describe("ToSwaggerDefinition", func() {
152159
Expect(props[3].Name).To(Equal("subs"))
153160
Expect(props[3].SchemaProps.Type[0]).To(Equal("array"))
154161
Expect(props[3].SchemaProps.Items.Schema.Ref.String()).To(Equal("#/definitions/subRes"))
162+
Expect(props[4].Name).To(Equal("xSub"))
163+
Expect(props[4].SchemaProps.Ref.String()).To(Equal("#/definitions/subRes"))
164+
Expect(props[4].SchemaProps.Description).To(Equal("[Optional]"))
155165
})
156166

157167
It("Check Request for Contract[1].Response (anotherRes)", func() {

0 commit comments

Comments
 (0)