I am using go-swagger. Is there any way to make attribute in generated swagger have the same order as defined. In generated swagger it is sorted in alphabetical order.
Asked
Active
Viewed 282 times
0
-
See https://goswagger.io/faq/faq_model.html#generated-code-changes-the-order-of-properties-in-struct and https://goswagger.io/use/models/schemas.html#custom-extensions – jub0bs Mar 24 '22 at 08:21
-
@jub0bs where should i put it, it seem doesn't work – BlackLotus Mar 24 '22 at 08:29
-
https://github.com/go-swagger/go-swagger/issues/2202 – medasx Mar 24 '22 at 10:25
-
@medasx wow, so this is an unresolved issue and there is nothing I can do right? – BlackLotus Mar 25 '22 at 02:16
1 Answers
0
To get the order in generated schema you need to add x-order
with number
value within double quotes ("
) or single quotes ('
)
// swagger:parameters SaveAccountRequest
type SaveAccountRequestWrapper struct {
// in:body
Account SaveAccountRequest `json:"body"`
}
type SaveAccountRequest struct {
// This text will appear as description of your request body.
// in:body
// Extensions:
// x-order: "0"
VendorID string `json:"vendorId"`
// Extensions:
// x-order: "1"
VendorName string `json:"vendorName"`
// Extensions:
// x-order: "2"
FullName string `json:"fullName"`
// Extensions:
// x-order: "3"
Source string `json:"source"`
// Extensions:
// x-order: "4"
Skill []string `json:"skill"`
// Extensions:
// x-order: "5"
Phone string `json:"phone"`
// Extensions:
// x-order: "6"
Email string `json:"email"`
// Extensions:
// x-order: "7"
StartDate time.Time `json:"startDate"`
// Extensions:
// x-order: "8"
EndDate time.Time `json:"endDate"`
}

Chandan
- 11,465
- 1
- 6
- 25