This is a java project build with maven to generate basic CRUD operation REST APIs using Spring Boot and backed with MongoDB
-
Generated Project contains basic JWT auth mechanism to protect unauthenticated access.
-
User, UserRole, UserSecurity, BaseEntity and BaseTransactionalEntity are generated by tool.
-
Auth Controller and it's depending classes are generated by tool and these are open APIs which does not require authentication, except change password.
-
Swagger is by default configured and the generated application will run on 8080 port.
-
The packages are generated in four category:
1. application - It has sub-packages to store application constant, exception and their handler, service and service impl and utility package. 2. configuration - Configuration containing aop, security and swagger. 3. controller - REST API controller 4. domain - Entities and their corresponding repository in different domain directory.
-
The generated code has below methods for Controller
1. For every json present in entity, corresponding controller, service, serviceImpl, repository and domain class are generated. 2. The controller has by default, getAll(), getByIds(), getAllByPageAble()- with sort , save, update list and deleting based on Ids. 3. If json has list attributes, then for all 1st level list items, create, update and delete of sub-resources are generated.
- Do not add
_id
,createdByUser
,updatedByUser
,isActive
,createdDateTime
,updatedDateTime
andadditionalProperties
variables as these are defined in BaseEntity and BaseTransactionalEntity. - Follow the naming convention while defining json file and keys.
- Please change the connection parameter defined in
resources/application.yml
. - Do not use space in Application name as it will decide name of SpringBootClass.
- Modify the property
GENERATE_SUB_RESOURCE
in order to generate sub-resource for each domain. - Modify the property
ENABLE_HARD_DELETE
in order to delete records permanently. - While defining key of a nested json array, append with either
s
orList
. e.g -samples or sampleList
.
-
Download the RestServiceGenerator.zip and extract to some directory.
-
Go to extracted directory, you will find
RestServiceGenerator.jar
andproperties
directory. -
Go to
properties
directory :
i. Modifygenerator.properties
with desired property value.
ii. Create thejson
file for which domain has to be generated in the entity directory. One sample json is provided for reference, you may delete that file. -
Open command prompt and change directory where jar file is present and execute below command.
java -jar RestServiceGenerator.jar
Make sure jar and properties directory are present in same directory.
-
Wait till application finishes its execution.
-
Import the skeleton in Eclipse or IntelliJ studio.
Enjoy coding. :)
1. While sending JSON for POST operation, the `_id` field of nested entities
should be sent from client ( UUID.randomUUID() ) in json otherwise,
mongo will not be able to create an ObjectId for nested entities.
2. Usage of Setter and Getter annotation is not possible with private access modifier
Feel free to report any issues, change request Here