What "resource: |" does mean in routes.yaml? - symfony

I'm trying to figure out with Sylius routing, based on Symfony framework. I found that code
sylius_admin_channel:
resource: |
alias: sylius.channel
section: admin
templates: "#SyliusAdmin\\Crud"
except: ['show']
redirect: update
grid: sylius_admin_channel
permission: true
vars:
all:
subheader: sylius.ui.configure_channels_available_in_your_store
templates:
form: "#SyliusAdmin/Channel/_form.html.twig"
index:
icon: share alternate
type: sylius.resource
But I could not find any information what is it | for resource. Any help?
Thanks.

It's the YAML syntax for a multi-line string (that preserves newlines).
So sylius_admin_channel is a mapping that has two keys (resource and type) whose values are both string types.
It can be confusing to see in this instance because the string happens to also be valid YAML. I edited your question to include syntax highlighting for YAML which makes this a little more obvious, visually.
If I didn't know any better, I would have guessed that the | is there in error and resource should actually have a mapping type for its value. If you remove the |, then same symbols that were within that string still produce valid YAML for the whole file, but the value of resource would be a mapping, rather than a string.
Notice the difference in syntax highlighting, compared to the yaml in the question with the | removed:
sylius_admin_channel:
resource:
alias: sylius.channel
section: admin
templates: "#SyliusAdmin\\Crud"
except: ['show']
redirect: update
grid: sylius_admin_channel
permission: true
vars:
all:
subheader: sylius.ui.configure_channels_available_in_your_store
templates:
form: "#SyliusAdmin/Channel/_form.html.twig"
index:
icon: share alternate
type: sylius.resource

Related

Parameter in parameter in services.yml

I am using symfony5 and what I want to achive is to use a parameter in another parameter. Is it possible? Of course I've searchd for it, but did not find a solution. For example:
media:
extendions:
- pdf
path: '%kernel.project_dir%/media/'
incomingPdf:
#path: '%kernel.project_dir%/media/incoming/pdf'
path: '#=parameter("media")["path"]incoming/pdf'
It says, expressions is not allowed in parameters.
In incomingPdf I want to use defined media['path']s value.

Trying to export dynamodb table variables from a serverless stack fails with intrinsic function !Ref

I have a working stack built with servereless framework which includes a dynamodb table (stack was already deployed successfully). I am trying to export the dynamo table's variables (name and arn basically) so these could be used in another stack I have deployed.
To achieve this I have the following:
in serverless.yml:
resources:
Resources:
AqDataTable: ${file(resources/AqDataTable.yml):AqDataTable}
Outputs:
AqDataTableName: ${file(resources/AqDataTable.yml):Outputs.AqDataTableName}
AqDataTableArn: ${file(resources/AqDataTable.yml):Outputs.AqDataTableArn}
(...)
custom:
AqDataTable:
name: !Ref AqDataTable
arn: !GetAtt AqDataTable.Arn
stream_arn: !GetAtt AqDataTable.StreamArn
in resources/AqDataTable.yml:
Outputs:
AqDataTableName:
Value: ${self:custom.AqDataTable.name}
Export:
Name: ${self:custom.AqDataTable.name}-Name
AqDataTableArn:
Value: ${self:custom.AqDataTable.arn}
Export:
Name: ${self:custom.AqDataTable.name}-Arn
When trying to deploy I get the following error:
Serverless Error ---------------------------------------
Trying to populate non string value into a string for variable ${self:custom.AqDataTable.name}. Please make sure the value of the property is a string.
The way I worked around this is by replacing AqDataTable.name value in the serverless.yml custom section from !Ref AqDataTable to a "harder-coded" value: AqDataTable-${self:provider.stage} but obviously this is a bad practice which I would like to avoid.
I'd appreciate any inputs on why this stack format invalidates the !Ref intrinsic function, or better ways to achieve what I am after here.
Many thanks!
In case anyone ever faces this issue:
After going over the docs one more time, apparently what I initially tried to do is not possible. According to CF docs:
For outputs, the value of the Name property of an Export can't use Ref
or GetAtt functions that depend on a resource.
Similarly, the ImportValue function can't include Ref or GetAtt
functions that depend on a resource.

How to define symfony routes with seperating "-" between 2 parameters?

I have a symfony routing defined:
route_name:
path: /foo/{slug}-{jobId}
slug: can be bar-92-test-123
jobId: integer
What are the right regular expressions for slug and jobId for Symfony to handle the route correctly?
Normally the following regular expression can cover your need:
(.*)-(\d+)$
So it seems the last $ sign can solve your issue as well.
It works with the following requirements:
requirements:
slug: '([a-z0-9]+[-]?)+'
jobId: '\d+'

Cannot import resource error, FosRestBundle Throws InvalidArgumentException

Hello i have a strange problem, while using FostRestBundle.
First error is :
InvalidArgumentException: Every parent controller must have get{SINGULAR}Action($id) method
where {SINGULAR} is a singular form of associated object
And the second one :
Cannot import resource "/home/a15net/public_html/game/src/ATL/ContentBundle/Resources/config/api_routing.yml" from "/home/a15net/public_html/game/app/config/routing.yml".
I'v checked my all "YAML" files but there was no indent problems.
Tried to update composer twice nothing helped.
Edit : Config.yml > http://goo.gl/dqCAu
You have to remove the 'type' from this import statement fro your routing.yml
atl_content_api:
resource: "#ATLContentBundle/Resources/config/api_routing.yml"
Inside the api_routing.yml you can specify the rest type for each controller like,
acme_user_rest:
resource: Acme\UserBundle\Controller\UserRestController
prefix: /api
type: rest
this blog will help you to implement the sme
--- NOT --- SOLUTION :
If a route has a parent route, you must not put "type:rest" to it. You have to use "type:rest" only in parent routes.
Sample :
catalogs:
type: rest
prefix: api
resource: ATL\CatalogBundle\Controller\API\CatalogsController
options:
expose: true
taxonomy:
parent: catalogs
resource: ATL\CatalogBundle\Controller\API\TaxonomyController
options:
expose: true
I will not choose this as correct answer until more comments and other solution suggestions writed.
Edit
When you remove type:rest from children route, it is not a rest route anymore.

"You cannot define a mapping item when in a sequence" when running phpunit in symfony

I'm getting the following errors when I try to run phpunit on my symfony project:
$ phpunit -c app
1) [...]\DefaultControllerTest::testIndex
Symfony\Component\Config\Exception\FileLoaderLoadException: Cannot import resource "/srv/http/typeform/app/config/config.yml" from "/srv/http/typeform/app/config/config_dev.yml".
/srv/http/typeform/vendor/symfony/src/Symfony/Component/Config/Loader/FileLoader.php:89
[...]
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11
Caused by
Symfony\Component\Yaml\Exception\ParseException: You cannot define a mapping item when in a sequence in "\/srv\/http\/typeform\/app\/config\/config.yml"
/usr/share/pear/Symfony/Component/Yaml/Parser.php:116
[...]
/srv/http/typeform/app/bootstrap.php.cache:520
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11
It seems that it crash when I call static::createClient();
Here's my config_test.yml
imports:
- { resource: config_dev.yml }
The errors you are getting suggest that the app is failing to parse your 'config.yml' because "You cannot define a mapping item when in a sequence".
This means that in a yml file when defining array values you cannot provide both mapping entries in the form "key: value" and sequence entries in the form "- item" - all values must be either one or the other form.
So, this is ok:
group:
key: value
key: value
This is also ok:
group:
- item
- item
This is not ok:
group:
key: value
- item
The errors suggest that there is an occurrence of the last form in your config.yml, although if this is the case it ought to cause problems running your app in the browser and not just under phpunit.
Additionally, to redbirdo's answer, you should be aware that you might need to use - under the required tag's items. For example:
UserLogin:
type: "object"
required:
- email
- password
security:
basicAuth: [] .......

Resources