Skip to content

This is a java project build with maven to generate basic CRUD operation REST APIs using Spring Boot and backed with MongoDB

License

Notifications You must be signed in to change notification settings

aashish-aadarsh/rest-service-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RestServiceGenerator

This is a java project build with maven to generate basic CRUD operation REST APIs using Spring Boot and backed with MongoDB

GeneratedStructure:

  1. Generated Project contains basic JWT auth mechanism to protect unauthenticated access.

  2. User, UserRole, UserSecurity, BaseEntity and BaseTransactionalEntity are generated by tool.

  3. Auth Controller and it's depending classes are generated by tool and these are open APIs which does not require authentication, except change password.

  4. Swagger is by default configured and the generated application will run on 8080 port.

  5. 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.
    
  6. 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.   
    

NOTES:

  1. Do not add _id, createdByUser, updatedByUser, isActive, createdDateTime, updatedDateTime and additionalProperties variables as these are defined in BaseEntity and BaseTransactionalEntity.
  2. Follow the naming convention while defining json file and keys.
  3. Please change the connection parameter defined in resources/application.yml.
  4. Do not use space in Application name as it will decide name of SpringBootClass.
  5. Modify the property GENERATE_SUB_RESOURCE in order to generate sub-resource for each domain.
  6. Modify the property ENABLE_HARD_DELETE in order to delete records permanently.
  7. While defining key of a nested json array, append with either s or List. e.g - samples or sampleList.

How to Use :

  1. Download the RestServiceGenerator.zip and extract to some directory.

  2. Go to extracted directory, you will find RestServiceGenerator.jar and properties directory.

  3. Go to properties directory :
    i. Modify generator.properties with desired property value.
    ii. Create the json file for which domain has to be generated in the entity directory. One sample json is provided for reference, you may delete that file.

  4. 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.

  5. Wait till application finishes its execution.

  6. Import the skeleton in Eclipse or IntelliJ studio.

    Enjoy coding. :)

Known Issues

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    

Issues

Feel free to report any issues, change request Here

Credits:

Aashish Aadarsh

LibraryUsed

ApacheVelocity

jsonschema2pojo

About

This is a java project build with maven to generate basic CRUD operation REST APIs using Spring Boot and backed with MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages