Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire.API.UserMap & Brig.API.Public: Fix Swagger docs #1350

Merged
merged 5 commits into from
Feb 3, 2021

Conversation

akshaymankar
Copy link
Member

@akshaymankar akshaymankar commented Feb 2, 2021

For WIre.API.UserMap:
The examples generated by swagger will not be nice, but it is very difficult to
get it right, unless we want to add explicit examples everywhere. Perhaps we can
use Arbitrary and some DerivingVia strategy to generate those. But for now, it
doesn't seem like it is worth it.

The examples generated by swagger will not be nice, but it is very difficult to
get it right, unless we want to add explicit examples everywhere. Perhaps we can
use Arbitrary and some DerivingVia strategy to generate those. But for now, it
doesn't seem like it is worth it.
@akshaymankar
Copy link
Member Author

Example generated by swagger-ui:

{
  "additionalProp1": {
    "additionalProp1": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ],
    "additionalProp2": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ],
    "additionalProp3": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ]
  },
  "additionalProp2": {
    "additionalProp1": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ],
    "additionalProp2": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ],
    "additionalProp3": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ]
  },
  "additionalProp3": {
    "additionalProp1": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ],
    "additionalProp2": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ],
    "additionalProp3": [
      {
        "id": "string",
        "type": "temporary",
        "time": "2016-07-22T00:00:00Z",
        "class": "phone",
        "label": "string",
        "cookie": "string",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "string"
      }
    ]
  }
}

@akshaymankar
Copy link
Member Author

Related issue in swagger2: GetShopTV/swagger2#136

@akshaymankar akshaymankar changed the title Wire.API.UserMap: Fix Swagger docs Wire.API.UserMap & Brig.API.Public: Fix Swagger docs Feb 2, 2021
@jschaul
Copy link
Member

jschaul commented Feb 2, 2021

additionalProp3 is not clear. Can we go the example route to indicate what this is (user id? or qualified user id? client id?)

@akshaymankar
Copy link
Member Author

additionalProp3 is not clear. Can we go the example route to indicate what this is (user id? or qualified user id? client id?)

Yes, the example is broken. This is a limitation of swagger2. It is not possible to model data like this. To get around this either we have to start writing examples of all the types that can appear in a map, or just rely on type names and descriptions to figure out what additionalPropN means. I went the route of just documenting it here. Maybe I should've been less lazy and just used the arbitrary instances. This might make me mess with generators and randomness (as we don't want to do IO to get examples), but maybe I can pull it off. It is a meeting full day for me so maybe I will give a shot now.

By default swagger-ui would generate "additionalProp1", "additionalProp2" .. for
keys in each `Map` type. To get around this we provide examples explicitly. This
results in weirdly named domains like '8v16tdys.s' being generated as well as
empty lists but it seems to be better than "additionalProp1". This causes some
of the lists in the examples to be empty, which is not very helpful as an
example, perhaps there is a way to tweak this.
@akshaymankar
Copy link
Member Author

This is only slightly better but also uglier:

{
  "q.w403.qx8l": {
    "00000001-0000-0000-0000-000200000002": [
      {
        "cookie": "",
        "time": "1864-05-09T00:25:43.381Z",
        "id": "1",
        "type": "legalhold",
        "label": ""
      }
    ],
    "00000001-0000-0001-0000-000100000002": []
  },
  "s3.5nz.5eseu02.k": {
    "00000001-0000-0001-0000-000200000002": [],
    "00000000-0000-0000-0000-000200000002": [
      {
        "cookie": "",
        "time": "1864-05-09T12:12:47.740Z",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "",
        "id": "0",
        "type": "permanent",
        "class": "phone",
        "label": ""
      },
      {
        "time": "1864-05-09T17:16:12.806Z",
        "id": "0",
        "type": "legalhold",
        "class": "desktop",
        "label": ""
      }
    ],
    "00000000-0000-0002-0000-000000000002": []
  },
  "6eu8.w8l-8110": {
    "00000001-0000-0002-0000-000200000001": [
      {
        "cookie": "",
        "time": "1864-05-09T05:15:26.563Z",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "",
        "id": "1",
        "type": "temporary",
        "label": ""
      }
    ],
    "00000001-0000-0000-0000-000200000002": [
      {
        "cookie": "",
        "time": "1864-05-09T02:36:33.750Z",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "",
        "id": "1",
        "type": "permanent",
        "label": ""
      }
    ]
  },
  "8v16tdys.s": {},
  "2e23p.f-q.l0.za5w99eeys0t8": {
    "00000001-0000-0000-0000-000000000001": [],
    "00000000-0000-0001-0000-000000000001": [],
    "00000000-0000-0000-0000-000000000000": [],
    "00000000-0000-0000-0000-000100000000": [],
    "00000001-0000-0001-0000-000100000000": [],
    "00000001-0000-0001-0000-000000000001": [],
    "00000000-0000-0001-0000-000000000000": []
  },
  "n22.e017j": {
    "00000001-0000-0000-0000-000000000001": [],
    "00000002-0000-0002-0000-000100000001": [
      {
        "time": "1864-05-09T19:47:20.053Z",
        "model": "",
        "id": "0",
        "type": "permanent",
        "class": "legalhold",
        "label": ""
      },
      {
        "cookie": "",
        "time": "1864-05-09T05:51:56.398Z",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "id": "1",
        "type": "permanent",
        "class": "legalhold",
        "label": ""
      }
    ],
    "00000002-0000-0002-0000-000200000000": [
      {
        "cookie": "",
        "time": "1864-05-09T09:36:28.408Z",
        "location": {
          "lat": 0,
          "lon": 0
        },
        "model": "",
        "id": "0",
        "type": "temporary",
        "class": "desktop"
      },
      {
        "cookie": "",
        "time": "1864-05-09T03:19:23.186Z",
        "model": "",
        "id": "1",
        "type": "permanent",
        "class": "tablet",
        "label": ""
      }
    ]
  },
  "b.c911viwc": {}
}

@akshaymankar
Copy link
Member Author

@jschaul I think it is enough bikeshedding on this, I'll pick whichever solution you like.

@akshaymankar akshaymankar merged commit cb51b01 into develop Feb 3, 2021
@akshaymankar akshaymankar deleted the akshaymankar/better-swagger branch February 3, 2021 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants