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?

CommentFileSizeAuthor
#3 Screen Shot 2017-07-02 at 15.07.26.jpg153.49 KBdawehner

Comments

tedbow created an issue. See original summary.

dawehner’s picture

I think we could leverage \Drupal\Core\Field\FieldItemListInterface::generateSampleItems quite a bit.

I opened up an issue in schemata for that: #2891644: Provide example values in schemata

dawehner’s picture

tedbow’s picture

Status: Active » Postponed

@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.