Convertin JsonSchema to Doctrine Enties (or Swagger, JSON) - symfony

I've been provided with a large set of JSONSchema (draft 7) describing a model of incoming messages for a SOAP API.
Based on that i have to create/generate PHP/Doctrine entities to save incoming json messages.
Because that is a large set of files, manual work is not an option. I have to build a generator.
I did some research and there are some php libraries that transform JSONSchema to a PHP model, but not to Doctrine entities.
I know there is an ApiPlatrform project - based on Symfony (i use Symfony as well) that has a schema generator tool to generate entities.
API Platform embraces open web standards (Swagger, JSON-LD, GraphQL, Hydra, HAL, JWT, OAuth, HTTP.) but unfortunately it doesn`t support jsonSchema.
Using this generator would be the perfect solution for me because I could go directly from JSONSchema to Doctrine+Symfony entities.
So now I'm looking for the way to transform JSONSchema to , i think it would be best for my project, to Swagger 3 (i could use Swagger later on for my API).
I didn't find any libraries or documentation that will do that.
There are some libraries that can create PHP classes (so far swaggest is best one i think), but none to create entities.
So now i have to options:
1.JSONSchema to e.g Swagger and use ApiPlatform schema generator to create entities
2.I use Swaggest to create PHP model classes and then somehow i convert it to entities
As a third solution i was thinking that maybe there is a way to transfor JSONSchema to mysql database and then create entities from it (there is a symfony/doctrine generator) for that (here im bit afraid of loosing some relations between tables)
Both solutions are good for me , but I think 1 is best.
So my question is , do you guys know any libraries or can you direct me to how to transform JSONSchema to Swagger ?
My goal is to have a generator that creates a nice and clean PHP Doctrine Entities with all relations and preferrably validation without any additional code (some libraries creates a lot of code on top of PHP classes)
Thanks in advance for any help and suggestions

Related

for create operation, form data is used but in Tortoise ORM documentation they are using JSON, what is the best practice?

I'm trying to make a Web App project using FastAPI and Tortoise ORM
I want to create a user(Registration) and mostly the data is Form data which is sent by the front-end and FastAPI docs does tells us how to handle Form data.
But the Example in Tortoise ORM docs (FastAPI Example) uses simple JSON data.
What is the best practice and what should I do?
link to Tortoise ORM and FastAPI example : https://tortoise-orm.readthedocs.io/en/latest/examples/fastapi.html#main-py
PS: Just one suggestion, Should I even use Tortoise ORM or switch to another ORM as Tortoise is still a young project (please also which other ORM I should consider)
If I have written anything wrong please pardon me I'm new to web development.
Thank you for your time and help.
Whether you use Form or JSON depends on which context your data is being submitted from. If it's submitted from a regular web form (i.e. form being submitted as a POST operation), it'll be form data. If you're using a frontend framework or designing an API to be used programmatically, it'll usually be easier and more expressive to use JSON. Neither is "better" (although plain form data can't express hierarchies as easily as JSON), but it depends on the context.
Tortoise ORM should be fine; it's popular. Other options is SQLAlchemy, orm, or possibly SQLModel - which is a new orm built on top of SQLAlchemy by the author of FastAPI - and designed for use with FastAPI.

Creating doctrine's entities on runtime

Situation: My boss ask me if I can create an entity from a json file. Not populating one entity with values from the json, but creating a new entity with its corresponding file, table and relations.
Could anybody give me some documentation, or an example or an starting point?
Edit1:
My bad, Cerad. I have been developing web apps with symfony (with doctrine as ORM) for about 2 years now. I'm used to its workflow. But i have never considerated this request.
No, you cannot.
This is totally against the principles of how doctrine works internally. (Caches, Proxies etc)
What is even the use case?

How to structure models and use Doctrine in Symfony2

I am switching over to Symfony for a project that I am working on but I need a little advice on how to structure the files when it comes to models and using doctrine.
I have a custom framework that I use, which in turns uses the MVC model. Pretty much all of my MYSQL database queries are stored in the models and I access them through the controller.
Now after looking at Symfony2, my interpretation is that "model" files in Symfony are called Servies. Is this correct?
I have also generated a number of Entities that correspond to my MYSQL database. My question here is do I place my custom Doctrine queries inside the Service files or do I create them inside the Entity files?
I'm a little unsure how to structure this.
Thanks
Pretty much all of my MYSQL database queries are stored in the models
That's bad, but I'll mention about it later.
Now after looking at Symfony2, my interpretation is that "model" files in Symfony are called Servies. Is this correct?
Queries should be done in either repositories or in some cases in services.
If your query returns entities, then it should be repository for sure.
My question here is do I place my custom Doctrine queries inside the Service files or do I create them inside the Entity files?
Entities should be plain PHP objects. They shouldn't depend on anything than other entities. Entities actually doesn't even know anything about database. It's pure object oriented business logic.
Again, all DB queries should be in repositories or services.
I would suggest to go through Symfony Book in first place, to get idea of how "the Symfony way" works.
Symfony is not MVC framework:
Symfony2 is really about providing the tools for the Controller part, the View part, but not the Model part [...] Symfony2 is an HTTP framework; it is a Request/Response framework.
And it is great. Symfony allows to make your model as you wish without any restrictions. The Doctrine (ORM and/or DBAL) is a separate set of libraries. You can use any other library, or build your own persistence layer abstraction, or work with native SQL through PDO/MySQLi/etc.
Service is just an object that registered in the container and have some dependencies. Services can doing anything. They can represent your model, but it is not a requirement.
Organizing Your Business Logic (The Symfony Best Practices)
Doctrine ORM Best Practices

Cakephp model->save equivalent in symfony framework without doctrine

I need the equivalent method in symfony framework which is there cakephp model->save() method , I do not want to use doctrine orm I just need cakephp like solution to my problem
What you're looking for (i.e. $model->save()) is called Active Record. Doctrine was using it in version 1.x but it does not anymore since version 2.x. You need to find some ORM which does and use it in your Symfony application. As far as I know you can't use Cake's ORM as a standalone component hence you can't inject it in Symfony so you need to find some other Active Record ORM.
You should give Propel a try (and its integration with Symfony - PropelBundle
)
You need to take time to approach Symfony2, you just can't look for an equivalent for every single thing. Learning how to do things "the Symfony" way will be worth in the mid/long run, because the logic is different between those 2 frameworks in many places you won't be able to reason like this for long.
A great place to start is the Symfony book: http://symfony.com/doc/current/index.html
Without Doctrine, you don't have the notion of "model". Then you can only fall back to save (array) data manually using PDO.

Using Symfony CMF to feed Redis

I'm supposed to make CMF feed a Redis queue which will then be polled by other servers. I'm still learning about CMF and it has become a little overwhelming to understand it. I've been using plain Symfony2 for a while, though.
I understand CMF can save the changes I made in the WYSIWYG editor as XML in the database. How much control do I have over this? Is there any project trying to interface CMF and Redis (or another non-doctrine database)?
I'm guessing I can implement a controller that would fetch these edited fragments from the database and send push them to Redis. But the fragments are in XML. Is there anything already built to fetch this data?
I appreciate any pointers. Thank you.
First lets briefly separate two things, the CMF is a set of components and Bundles that can largely be used independent of each other. All of them are storage agnostic but many currently only ship with support for PHPCR.
PHPCR in turn is a content repository interface for CMS which supports tree structures, full text search etc.
The reference implementation of that is called Jackalope. Jackalope in turn provides different so called "transports". You seem to be looking at the Doctrine DBAL transport for Jackalope which in deed stores XML fragments into an RDBMS. There is another one which uses the Jackrabbit Java server.
At any rate, writing a Redis based transport for Jackalope is probably not what you want. From what I can read is you actually just want a queue stored on Redis? In that case I would just use this Bundle here https://github.com/snc/SncRedisBundle together with standard Symfony2.
If you also want CMS editing capabilities, you can easily add CMF based editing into any Symfony2 project. Of course you would then use Redis for your queue and one of the Jackalope transport layers for storage. So you would be using more than one database. But this is a sensible architecture.

Resources