The OpenAPI spec allows specifying "example" values for properties in the data model
{
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
},
"required": [
"name"
],
"example": {
"name": "Puma",
"id": 1
}
}https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md...
We should provide this when we can. It will make the example model better. In OpenAPI docs this would also make the "Try it out" feature actually work. Presumably this would be useful for other tools that would use the OpenAPI output.
Examples
Entity references
On node schema "type" is reference to Content type entity.
For any entity reference that references a config entity type like this we could get a sample entity and add the id as example.
Text formats
For text fields we could use a valid text format id for "format"
Is there any pattern we could use here for other field types?
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | Screen Shot 2017-07-02 at 15.07.26.jpg | 153.49 KB | dawehner |
Comments
Comment #2
dawehnerI think we could leverage
\Drupal\Core\Field\FieldItemListInterface::generateSampleItemsquite a bit.I opened up an issue in schemata for that: #2891644: Provide example values in schemata
Comment #3
dawehnerSee this screenshot: https://www.drupal.org/files/issues/Screen%20Shot%202017-07-02%20at%2015...
Comment #4
tedbow@dawehner thanks for filing the related issue. Postponing this but if it can handled in Schemata that would be better. So if that is committed then this issue should be closed.