Jane v5.3: Performances, Authentication & OpenAPI 2!
Two months after v5.2 and four months after v5.0, we are releasing v5.3 with focus on three things:
Section intitulée performancePerformance
Before, generating a really big OpenAPI schema was very long. We even had issues where the generation took more than 40 minutes! Thanks to @lyrixx & @bastnic who took time to dig into Jane’s generation process and turned those 40 minutes into just 20 seconds!
We also deprecated the NormalizerFactory
replaced by JaneObjectNormalizer
which will load needed Normalizers only when needed. This change can have a really huge impact on schemas with a lot of models (In the related PR, with 509 Normalizers we go from 57ms to 3.5ms during class autoload).
You can see more details into the related PR:
- GH#197 Local cache for Reference contents;
- GH#210 Added JaneObjectNormalizer to lazy-load Normalizer when needed;
- GH#227 Fixing JSON Pointer being created too much time.
Section intitulée authentication-supportAuthentication support
OpenAPI has a securitySchemes
field to describe authentication and authorization schemes. With v5.3 we introduced support for authentication types http
& apiKey
(oauth2
is a bit harder to implement, but we’re open to contribution if you want to give it a try!).
In your schema, you’ll have the following description:
securityDefinitions:
Bearer:
type: http
scheme: Bearer
ApiKey:
type: apiKey
in: query
name: api_key
Jane will now generate:
BearerAuthentication
forBearer
scheme which will inject a given token in an HTTP Header (see: related example);ApiKeyAuthentication
forApiKey
scheme which will inject aapi_key
query parameter with your token to all requests (see: related example).
And to use them, you have to do the following:
$httpClient = new Psr18Client();
// setup your HttpClient ...
$client = Client::create($httpClient, new BearerAuthentication('token')); // with Bearer auth
$client = Client::create($httpClient, new ApiKeyAuthentication('apiKey')); // with ApiKey auth
And after that, all your requests will be authenticated! 🔓🎉
Next step is to support authentication scopes on Jane generated endpoints to allow you to have multiple security schemes and Jane choose the right one to use!
Section intitulée openapi-2-backportOpenAPI 2 backport
Before v5.3, OpenAPI 2 was only supported on the v4.x branch and it was such a pain to maintain. To make it easier to maintain and to use, we moved the component to the master
branch as open-api-2
component! We even splitted all features that are in common with OpenAPI 3 to allow OpenAPI 2 to take advantage of OpenAPI 3 enhancements at no cost (including performance & Authentication support 😉).
Here is a diff to show the related changes you have to do in your composer.json
:
"require": {
- "jane-php/open-api-runtime": "^4",
+ "jane-php/open-api-runtime": "^5",
},
"require-dev": {
- "jane-php/open-api": "^4",
+ "jane-php/open-api-2": "^5",
},
As a result of this change, jane-php/open-api
component is now deprecated and should be replaced by jane-php/open-api-3
, on our next major version (v6
) it will be removed. And the v4.x and all related tags are also deprecated and should be replaced by jane-php/open-api-2
component.
Here is a diff to show the related changes you have to do in your composer.json
:
"require-dev": {
- "jane-php/open-api": "^5",
+ "jane-php/open-api-3": "^5",
},
—
We also had other fixes and improvements, you can see the complete list on the v5.3 release page.
Feel free to try it out and if you have any questions, our repository issues are open: https://github.com/janephp/janephp/issues
Commentaires et discussions
Jane 5.0 has been released! 🍾
Jane is a set of libraries to generate models & API clients based on OpenApi specs. It will generate everything you need to use your API such as endpoints and related exceptions if needed. As a reminder, OpenApi…
par Baptiste Leduc
Nos articles sur le même sujet
Ces clients ont profité de notre expertise
JoliCode a formé l’équipe de développement d’Evaneos aux bonnes pratiques pour l’écriture de tests unitaires efficaces et utiles. Nous en avons également profité pour mettre en place une plateforme d’intégration continue pour accompagner l’évolution de la plateforme.
En tant que joaillier 100 % numérique, l’équipe de Courbet Paris a souhaité se doter d’une plateforme eCommerce, capable d’offrir une expérience moderne qui revalorise l’acte d’achat de produits de joaillerie sur internet. JoliCode a accompagné leur équipe en développant une plateforme robuste, mais aussi évolutive, afin de répondre aux enjeux business…
Groupama Épargne Salariale digitalise son expérience client en leur permettant d’effectuer leurs versements d’épargne salariale en ligne. L’application offre aux entreprises une interface web claire et dynamique, composé d’un tunnel de versement complet : import des salariés via fichier Excel, rappel des contrats souscrits et des plans disponibles, …