Yaml metadata 

Serialization of your own models is usually configured with t3api annotations (@T3api\Serializer\Groups etc.) directly in the model. It is not possible for classes you do not own - e.g. models of 3rd party extensions (EXT:news) or TYPO3 core. For such classes serialization metadata can be defined in YAML files.

YAML files are read from directories registered in $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerMetadataDirs']. Register your directory in ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerMetadataDirs'] = array_merge(
    $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerMetadataDirs'] ?? [],
    [
        'GeorgRinger\News' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('my_ext')
            . 'Resources/Private/Serializer/GeorgRinger.News',
    ]
);
Copied!

All *.yml files from registered directories are loaded (subdirectories are not scanned) and merged. Name of the file does not matter, but the convention is to use class name with dots, e.g. Domain.Model.News.yml. Top level key of the file is the fully qualified class name. Syntax is the JMS serializer YAML reference.

Example from testing instance (EXT:t3apinews) which exposes properties of \GeorgRinger\News\Domain\Model\News - class extended by API resource \SourceBroker\T3apinews\Domain\Model\News:

GeorgRinger\News\Domain\Model\News:
  properties:
    title:
      groups: [api_get_collection_t3apinews_news, api_get_item_t3apinews_news]
    teaser:
      groups: [api_get_collection_t3apinews_news, api_get_item_t3apinews_news]
    bodytext:
      groups: [api_get_item_t3apinews_news]
    datetime:
      groups: [api_get_collection_t3apinews_news, api_get_item_t3apinews_news]
    categories:
      groups: [api_get_collection_t3apinews_news, api_get_item_t3apinews_news]
      type: 'TYPO3\CMS\Extbase\Persistence\ObjectStorage<SourceBroker\T3apinews\Domain\Model\Category>'
Copied!

With such configuration:

  • bodytext is returned only for item operation (/news/news/{id}), not in collection.
  • categories are serialized as \SourceBroker\T3apinews\Domain\Model\Category (the API resource class), because type points to the extended class instead of \GeorgRinger\News\Domain\Model\Category.

Metadata merging 

YAML metadata are merged with annotations of the class - values from YAML win. If the same key is set in more than one YAML file, files from directories registered later win (array_replace_recursive). It means that you can change metadata delivered by t3api or by other extensions - e.g. remove a property from serialization:

GeorgRinger\News\Domain\Model\News:
  properties:
    teaser:
      exclude: true
Copied!