I made an api with api-platform.
I tried to edit the swagger_ui path '/' to '/docs' according to api-platform documentation and allow '/' redirect to custom twig i made.
The swagger_ui documentation is available in /docs path but also still available in '/' path instead of my custom twig file.
Here is my config :
app/config/packages/api_platform.yaml
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
enable_swagger_ui: true
enable_re_doc: true
enable_docs: true
app/config/routes/api_platform.yaml
api_platform:
resource: .
type: api_platform
prefix: /
app/config/route.yaml
swagger_ui:
path: /docs
controller: api_platform.swagger.action.ui
hello-world:
path: /
controller: App\Controller\HelloController::index
Thanks by advance for your answer, if i haven't be clear, just le me know :)
Try changing
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
enable_swagger_ui: true
enable_re_doc: true
enable_docs: true
with
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
enable_swagger_ui: true
enable_re_doc: true
enable_docs: true
and pay attention to indentation in other files ...
This seems to be broken for now. There's a PR to fix the issue inside Api Platform but it hasn't been merged yet: https://github.com/api-platform/core/pull/2749
Related
I'm using annotations in my project but to redirects using routes.yaml
If exists routing (ex. /home name="home"} that redirect not working:
home-301:
path: /home
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /new-home
permanent: true
I found solution but I thing it is no good practice:
cleared: config/routes/annotations.yaml
and appended to the end of the file config/routes.yaml:
controllers:
resource: ../../src/Controller/
type: annotation
how to do it right?
My solution:
all redirects put in: config/routers/redirects.yaml
and config/routes.yaml:
redirects:
resource: routes/redirects.yaml
annotations:
resource: routes/annotations.yaml
I need to add a requirement for my api route (only allow 3 mgn , user and adm) but i get the error:
MissingMandatoryParametersException
Some mandatory parameters are missing ("role") to generate a URL for route "api_doc".
here is my route:
api_platform:
resource: .
type: api_platform
prefix: /{role}/api
requirements:
role: "mng|adm|user"
should i install or set something?, thank you
already find a solution
if some person need it
api_platform:
resource: .
type: api_platform
prefix: /{app}/api
defaults:
app: take|mngr|drvr
requirements:
app: take|mngr|drvr
thank you
I want use Symfony4 with Vuejs app in the same corner of my server (on the same domaine)
But Sf routing is master and (than VueJs router) generate some 404
mode: 'history',
using the history mode.
Thanks for your tricks ;) .
approach number 1:
routing configuration to have a "jolly" route:
this route MUST be latest to match
jolly_all_in:
path: '/{jolly}'
controller: 'App\Controller\JollyController::allInPrintVueInit'
requirements:
jolly: '.*'
or in this case all your vue route MUST has a prefix "your-vue-route-prefix"
jolly_all_in_with_prefix:
path: '/your-vue-route-prefix/{jolly}'
controller: 'App\Controller\JollyController::allInPrintVueInit'
requirements:
jolly: '.*'
with this approach you must manage your 404 from JS.
approach number 2:
you MUST map all your JS route to symfony route.
example
user_list:
path: '/user'
controller: 'App\Controller\VueController::printVueInit'
user_get:
path: '/user/{id}'
controller: 'App\Controller\VueController::printVueInit'
requirements:
id: '\d+'
[...]:
path: '/.../.../...'
controller: 'App\Controller\VueController::printVueInit'
I'm using FOSRestBundle to manage my api. I already have a running sf2 application, and i want to allow third person to access some of my application features. I configured my api, and it works as expected, i can consume my api route with success
for example :
GET http://my.domain.ldt/api/v1/users
My Api only handle json format, here is my fos_rest configuration :
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
exception_wrapper_handler: My\ApiBundle\Handlers\ApiExceptionWrapperHandler
formats:
json : true
failed_validation: HTTP_BAD_REQUEST
templating_formats:
html: false
xml: false
routing_loader:
default_format: json
include_format: false
exception:
enabled: true
service:
view_handler: my.view_handler
services:
my.json_handler:
class: My\ApiBundle\Handlers\JsonHandler
my.view_handler:
parent: fos_rest.view_handler.default
calls:
- ['registerHandler', [ 'json', ["#my.json_handler", 'createResponse'] ] ]
As i said, my Api works well, but i face a major problem : When i try to access to the main application from my web browser, ( http://my.domain.ldt/, or http://my.domain.ldt/login), i get the following response instead of my classic web page :
An Exception was thrown while handling: No matching accepted Response format could be determined
Why my fos_rest conf applies on my main website ? Is it possible to only set the api conf for the api routes ? Did i miss something ?
The problem is that you forgot to define rules for FOSRestBundle's format listener.
In fact I'm not sure you need this listener as it seems you use json as the default format. The format listener will try to match the Accept header and extract the current request format based on it. So except if you want to support other formats than json for your api, you can just not use it.
In case you want to fix it instead of removing it, you have to update your config with something like:
fos_rest:
format_listener:
enabled: true
rules:
- { path: '^/', priorities: ['json', 'xml', 'html], fallback_format: 'json' }
Of course you can change this rule to have a different rule for your api:
fos_rest:
format_listener:
enabled: true
rules:
- { path: '^/api', fallback_format: 'json' }
- { path: '^/', fallback_format: 'html' }
Here are params.
app/config/parameters.yml
parameters:
test:
enabled: true
validate: true
And this is service which I want to configure with test param from previous file.
MyBundle/Resources/config/services.yml
imports:
- { resource: "parameters.yml" }
parameters:
services:
my.form.type:
class: My\Bundle\Form\Type\MyType
arguments:
- %test%
Import doesn't work this way. How should I do it?
PS I know I can refer to #service_container. But the point is to pass array explicitly via yaml.
you can ommit ...
imports:
- { resource: "parameters.yml" }
parameters:
... parameters.yml should automatically be parsed and the parameters should be available for injection if you surround them with %.
Try:
services:
my.form.type:
class: My\Bundle\Form\Type\MyType
arguments: ["%test%"]
alias: my_form_type