Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid YAML format in README #45

Open
tyrannosaurusjames opened this issue Oct 4, 2024 · 0 comments
Open

Invalid YAML format in README #45

tyrannosaurusjames opened this issue Oct 4, 2024 · 0 comments

Comments

@tyrannosaurusjames
Copy link
Contributor

The YAML format in the README for adding extra indexed_fields to classes that extend the base class is invalid:

Your\Namespace\Page:
  extensions:
    - Heyday\Elastica\Searchable
  indexed_fields: &page_defaults
    - Title
    - MenuTitle
    - Content
    - MetaDescription

Your\Namespace\OtherPage: # extends Your\Namespace\Page
  indexed_fields:
    <<: *page_defaults
    - BannerHeading
    - BannerCopy
    - SubHeading

This YAML format doesn't appear to be an agreed part of the spec - here is a feature request for a very similar format that was declined: yaml/yaml#35

Attempting to run a dev/build using the format documented here will result in an error like this:

Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException: You cannot define a sequence item when in a mapping at line 68 (near "- BannerHeading"). in /path/vendor/symfony/yaml/Parser.php:146

This question on Stack Overflow also appears to indicate it's not really possible: https://stackoverflow.com/questions/4948933/is-there-a-way-to-alias-anchor-an-array-in-yaml

One answer from that question does give a solution that works (https://stackoverflow.com/a/67265299)

An equivalent format that works would be:

Your\Namespace\Page:
  extensions:
    - Heyday\Elastica\Searchable
  indexed_fields: &page_defaults
    1: Title
    2: MenuTitle
    3: Content
    4: MetaDescription

Your\Namespace\OtherPage: # extends Your\Namespace\Page
  indexed_fields:
    <<: *page_defaults
    5: BannerHeading
    6: BannerCopy
    7: SubHeading

It's a bit of a pain to keep track of the integer keys, but it seems like it is the only way to avoid a lot of copy/paste

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant