compojure-api icon indicating copy to clipboard operation
compojure-api copied to clipboard

Generating realistic example values

Open mikera opened this issue 7 years ago • 0 comments

Library Version(s)

1.1.11

Problem

I'm experimenting with compojure-api for documenting a new set of APIs with Prismatic Schema. It;s working well so far, though I have one issue which is not obvious how to resolve - how to generate realistic example values for an input / output schema.

Currently I get Example Values in the swagger UI like this:

{
  "name": "string",
  "description": "string",
  "type": "assetClass1",
  "ownerID": "string"
  "dateCreated": "2018-11-19T01:25:04.282Z",
}

In this case, I need ownerID to be a 64 character hex string which satisfies a custom valid-user-id? predicate, which defined in Schema as something like:

(s/defschema UserID
  (s/constrained s/Str valid-user-id? "Valid User ID"))

However it's not clear how to get compojure-api to generate valid values which satisfy the constraint (The value "string" doesn't....) and display these to the user in the Swagger UI.

Is there a way to do this? Ideally I would like to be able to specify a custom generator for the schema, which I build easily enough with test.check but how do I get that to be reflected in the Swagger UI?

Any help much appreciated!

mikera avatar Nov 19 '18 01:11 mikera