Skip to content

Latest commit

 

History

History
76 lines (59 loc) · 4.15 KB

File metadata and controls

76 lines (59 loc) · 4.15 KB

Reusable components

Organization schemes

No sub-folders underneath component folders

Component folders do not have sub-folders.

This restriction exists because the OpenAPI CLI considers files with the same basename as the same file, and thus incorrectly builds the distributable OpenAPI spec, even though its composite files are in different folders.

To get around this, I've adopted a loose naming convention:

  • Components which are likely to be reused across multiple contexts have the name $objectName.yaml (camel-cased)
  • Components which are specific to a particular context have the name $context-$objectName.yaml

Items and lists of items

Endpoints will generally operate either on singular items, or lists of items.

I've found it beneficial to create:

  • Response objects for lists and items
  • Request body objects for items, and lists if any paths support them

Read and write variants of items

Items may have fields which are suitable for reading only (they will be returned in a response, but ignored or fatal when passed in the corresponding request body), or for writing only (they will never be returned in a response, but may be passed in the corresponding request body).

Also, items may have a read-only and write-only variant of the same field. It is common for a response to include an item with a fully-populated related item (i.e. a user's role will be retrieved, and be populated with its ID, name and type), but the corresponding request body will only accept the ID.

This distinction exists so that the API implies that the related item cannot be updated via a request to update or create the base item.

  • Fields that are common to the read and write variants will be in schemas/$objectName-fields.yaml
  • Fields for the read variant will be in schemas/$objectName-readableFields.yaml
  • Fields for the write variant will be in schemas/$objectName-writableFields.yaml
  • The actual read and write variants are in schemas/$objectName-{read,write}.yaml
    • Their actual definition will reference the read/write only fields, and then the common fields; e.g. schemas/user-read.yaml