go-swagger icon indicating copy to clipboard operation
go-swagger copied to clipboard

Example values on map keys instead of "AdditionalProp"

Open lurainsin opened this issue 8 years ago • 2 comments

I got a model like that

//swagger:model
type User struct {
        ...
	Exam  map[string]ExamResult `json:"exam"`
        ...
}

When I generate the json, I get

      ...
      "exam": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/ExamResult"
          },
          "x-go-name": "Exam"
        },
       ...

and the "Example Value" on swagger-ui is

  "exam": {
    "additionalProp1": {
      ...
    },
    "additionalProp2": {
      ...
    },
    "additionalProp3": {
      ...
    }
  },

From the documentation I cannot get how can I customize the keyset of the map. I want, if it's possible, to choose how many keys are shown in the example, and specify which keys to use, cause "additionalProp1-3" is quite misleading.

Is it possible?

Thank you for the great work

Environment

swagger version: 0.13 go version: 1.10 OS: OSX 10.13.3

lurainsin avatar Mar 20 '18 10:03 lurainsin

Any updates on this?

abhishp avatar Apr 06 '20 09:04 abhishp

Here is a workaround that I use.

Say I have a map[string]bool which three possible keys: "escalated", "acknowledged" and "taken", and I annotate it with an example comment like below.

// example: { "escalated": true, "acknowledged": false, "taken": false }

The idea here is that, in OpenAPI, a map basically is treated as an object. So you can provide an example JSON to demo your map.

YuanliangYu avatar Aug 17 '22 22:08 YuanliangYu