postbuild_model_test.go 867 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package swagger
  2. import "testing"
  3. type Boat struct {
  4. Length int `json:"-"` // on default, this makes the fields not required
  5. Weight int `json:"-"`
  6. }
  7. // PostBuildModel is from swagger.ModelBuildable
  8. func (b Boat) PostBuildModel(m *Model) *Model {
  9. // override required
  10. m.Required = []string{"Length", "Weight"}
  11. // add model property (just to test is can be added; is this a real usecase?)
  12. extraType := "string"
  13. m.Properties.Put("extra", ModelProperty{
  14. Description: "extra description",
  15. DataTypeFields: DataTypeFields{
  16. Type: &extraType,
  17. },
  18. })
  19. return m
  20. }
  21. func TestCustomPostModelBuilde(t *testing.T) {
  22. testJsonFromStruct(t, Boat{}, `{
  23. "swagger.Boat": {
  24. "id": "swagger.Boat",
  25. "required": [
  26. "Length",
  27. "Weight"
  28. ],
  29. "properties": {
  30. "extra": {
  31. "type": "string",
  32. "description": "extra description"
  33. }
  34. }
  35. }
  36. }`)
  37. }