I wanted to implement versioning of endpoints for my project.. turns out the FOSRestBundle implementation is not quite clear so I wanted to implement like follow:
Symfony 5.4
FOSRestBundle 3
see below annotation.yaml file:
v2_controllers:
resource: ../../src/Controller/V2/
type: annotation
prefix: /v2
name_prefix: 'api_v2_'
controllers:
resource: ../../src/Controller/
type: annotation
name_prefix: 'api_'
kernel:
resource: ../../src/Kernel.php
type: annotation
when I run this command php bin/console debug:router --show-controllers
I get the following result:
..
..
...
api_offer_list GET ANY ANY /offer-list/{productId}/{pageType}/ App\Controller\V2\OfferListV2Controller::offerListAction()
api_v2_offer_list GET ANY ANY /v2/offer-list/{productId}/{pageType}/ App\Controller\V2\OfferListV2Controller::offerListAction()
...
..
You can see that the new version is also overriding the older endpoint for some weird reasons
and finally here's my fos_rest.yaml config:
# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
param_fetcher_listener: true
Inside the controller directory, you need to create two separate directories, one for v1 and the other for v2 and this should solve the problem.
Controller/
v1/
v2/
Related
I'm using OAS3 generator for Java as a Maven plugin to generate POJOs, controllers, delegates etc for my APIs with the Mustache templates from the openapi-generator repository: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache
I'm trying to edit this template so that the "#Controller" annotation is generated only if a condition is met. I've searched for multiple solutions for this and one of them was using "vendorExtensions".
I've made the following contract with x-generateController vendorExtension:
openapi: 3.0.0
info:
title: User API
description: API for user changes
contact:
name: xxx
url: xxx
email: xxx
license:
name: xxx
url: xxx
version: 1.0.0
tags:
- name: user
x-generateController: True
paths:
/users:
...
And then in the Mustache template file I have put the following:
{{#vendorExtensions.x-generateController}}
#Controller("{{classname}}")
{{/vendorExtensions.x-generateController}}
The generator works just fine without this condition but it seems like it doesn't take into account x-generateController. In fact, if I try to just place it as a comment like this:
// {{vendorExtensions.x-generateController}}
I get only "// " and an empty space. I've also tried putting it at the "endpoint level" and not in the "info level" and the problem is the same.
Is there anything more that I should've done in the configuration? Is there any alternative for a condition in the Mustache template?
Suppose I have an OpenAPI 3 document describing API Foo as follows:
openapi: 3.0.0
info:
version: '1'
title: Foo
paths:
/foo:
get:
responses:
200:
description: A Foo
post:
responses:
201:
description: Foo created
In another OpenAPI document for API Bar, I would like to reference only the GET /foo operation from API Foo. The OpenAPI docs talk a little about referencing a whole path. However, if I do the following:
openapi: 3.0.0
info:
version: '1'
title: Bar
paths:
/foo:
$ref: 'foo.yaml#/paths/~1foo'
I naturally get both the GET and the POST in API Bar, since only the path is referenced, not the method.
I tried this:
openapi: 3.0.0
info:
version: '1'
title: Bar
paths:
/foo:
get:
$ref: 'foo.yaml#/paths/~1foo/get'
But this gives errors like should NOT have additional properties additionalProperty: $ref and should have required property 'responses' missingProperty: responses in various tools, so it doesn't seem to be supported.
Is there a way to accomplish this? I should note that the real request is much more complicated, hence the desire to de-duplicate. If possible I would like to avoid filling in many child objects of get with individual $refs.
OpenAPI doesn't have a way to $ref an individual operation (get/post/etc.), you can only $ref an entire path.
You can propose syntax enhancements in the OpenAPI Specification repository:
https://github.com/OAI/OpenAPI-Specification/issues
I'm trying to use Ambassador prefix_regex and regex_rewrite.
I want both this routes prefixes:
/my/route/<something>
/api/v1/my/route/<something>
will be mapped to:
/my/route/<something>
This is what I was trying to use:
apiVersion: ambassador/v2
kind: Mapping
prefix_regex: true
prefix: (/api/v1)?/my/route
regex_rewrite:
pattern: "/api/v1/my/route/(.*)"
substitution: "/my/route/\\1"
Using the regex_rewrite with regular prefix works as expected
Using prefix_regex with regular rewrite works as expected
but together I receive 404 from the envoy.
Any ideas?
I'm using Ambassador 1.7.0 version
Resolved by adding /.* at the end of the prefix.
prefix: (/api/v1)?/my/route/.*
It looks like prefix_regex adds automatically $ at the end of the prefix, which means we need to specify the full path of the mapping and not just the prefix.
Console command debug:router show absolutely ALL resources, from all installed Bundles (entity marked with #ApiResource())
How to configure different prefixes for different bundles?
Or selectively disable resources.
App ignored any path in resource: config/routes/api_platform.yaml
api_platform:
resource: .
type: api_platform
prefix: /api
With default config config/packages/api_platform.yaml
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
https://github.com/api-platform/core/blob/5882990beaf75675170efb54384bf44c3534dd1b/src/Bridge/Symfony/Routing/ApiLoader.php
For type: api_platform resource: . not used
Automatic resource loading can only be disabled completely
doctrine:
enabled: false
Does anyone know if SAM templates support Lifecycleconfigruation settings? I see within standard cloudformation definitions you can define the lifecycle of objects like:
BucketName: "Mys3Bucket"
LifecycleConfiguration:
Rules:
- AbortIncompleteMultipartUpload:
DaysAfterInitiation: 7
Status: Enabled
- ExpirationInDays: 14
...
But this seems to fail when used in a SAM template. Am I doing something wrong or is this not part of the serverless application model definition?
It works for me using the SAM CLI 1.15.0, although documentation seems sparse (hence my landing on this question while trying to figure it out).
The SAM template snippet below successfully creates a bucket and sets an appropriate lifecycle rule.
Resources:
Bucket1:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Sub "${BucketName}"
AccessControl: Private
VersioningConfiguration:
Status: Enabled
LifecycleConfiguration:
Rules:
- ExpirationInDays: 6
Status: Enabled