SlideShare a Scribd company logo
www.cognizant.com
Copyright © 2017 Cognizant
1
Spring boot REST data service code generation using Swagger code gen
Why use Automatic Code Generation?
Automatic Code Generation refers to using programs to generate
code that the user would otherwise have to write themselves.
Automatic code generation has certain advantages over traditional
coding.
• Correctness
• High quality
• Efficient use of the resources
• Quick code generation
• Consistent
• Coding Abstractly
Two step approach.
Two step approach to generate the REST code using swagger code gen.
• Swagger code gen tool reads the table meta data details from DB
schema and generates the YAML file with Open API specs.
• It generates the REST code based on the YAML file.
Methodologies used to generate the code :
• Bottom up approach with online mode
Approach Diagram:
Important code blocks of REST Services to
be generated by the Swagger code gen.
Swagger Custom Code Gen:
Swagger Custom Code Gen:
• Default Swagger CodeGen generates only REST Controller of the
spring boot project. Swagger custom code generator implementation
is required to customize the REST controller, Service and DAO classes.
• Swagger custom CodeGen implementation contain following
important files:
• CustomTemplate Codegen file
• Mustache files
• Configuration files.
• Mustache file acts as templates for code generation.
Detailed steps to generate REST code.
• Deploy the YAML generator jar file to respective server.
• Post a request to the URL of YAML generator with schema name and table name.
o Sample URL: http://vdalhdpedged013.kbm1.loc:2020/codegen
o Input :Sample Request:
{
"schemaName":"CNTCT_PNT_CONSUMER",
"tableName":"CNTCT_PNT"
}
o Output : Swagger YAML file
• Deploy the Custom swagger code gen jar file to the respective server.
o Input : Swagger YAML file
o Include package structures and other configuration details as part of customConfig.json
o Execute the below command
o java -jar targetCustomTemplate-1.0-SNAPSHOT.jar generate -l spring -i swagger.yaml -o test -c customConfig.json
o Output : Spring boot REST data service code.
• Deploy generated Spring boot REST code and test the CURD operations of the Phoenix REST data services.
Next steps..
• Junit test cases implementation with good coverage.
• Preprocessor and post processes of request and response for processing.
• Client stub generation for given service through YAML.
• Open API documentation through YAML file.
• Error and Exception handling.
• REST wrapper generation for given soap code ( This is a huge
implementation).
• Different configuration files Implementation like security, environment
specific configuration (API gate way, service discovery configuration may
require in feature).
• Transaction management code implementation.
• Pom file generation based on dependencies.

More Related Content

PDF
NoSQL design pitfalls with Java
PDF
MongoDB .local Bengaluru 2019: Distributed Transactions: With Great Power Com...
PDF
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
PDF
MongoDB .local Bengaluru 2019: Becoming an Ops Manager Backup Superhero!
PPTX
Cache control directive
PDF
What Does Kubernetes Look Like?: Performance Monitoring & Visualization with ...
PDF
Continuous performance management with Gatling
PDF
Azure functions
NoSQL design pitfalls with Java
MongoDB .local Bengaluru 2019: Distributed Transactions: With Great Power Com...
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
MongoDB .local Bengaluru 2019: Becoming an Ops Manager Backup Superhero!
Cache control directive
What Does Kubernetes Look Like?: Performance Monitoring & Visualization with ...
Continuous performance management with Gatling
Azure functions

What's hot (20)

PDF
Mastering Grails 3 Plugins - Greach 2016
PDF
Rest with grails 3
PDF
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
PDF
SpringMVC
PDF
Brad wood - Integrating MVC Into Legacy [Into The Box 2020]
ODP
Gatling
PDF
MongoDB .local Bengaluru 2019: Realm: The Secret Sauce for Better Mobile Apps
PPTX
React, Flux and more (p1)
PPTX
Gatling
PDF
Web Service Testing using TestComplete
PPTX
Evolution of the REST API
KEY
深入淺出RoR
PPTX
Internals of Steroids Framework
PPTX
React.js - The Dawn of Virtual DOM
PDF
Redux Universal
PDF
Altitude NY 2018: Don't let the weeds overwhelm the garden
PDF
Mastering Grails 3 Plugins - GR8Conf EU 2016
PDF
Vaugham Hong - Embedding JavaScript V8
PDF
Women Who Code Connect 2018 Conference
PDF
Introduction to React, Flux, and Isomorphic Apps
Mastering Grails 3 Plugins - Greach 2016
Rest with grails 3
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
SpringMVC
Brad wood - Integrating MVC Into Legacy [Into The Box 2020]
Gatling
MongoDB .local Bengaluru 2019: Realm: The Secret Sauce for Better Mobile Apps
React, Flux and more (p1)
Gatling
Web Service Testing using TestComplete
Evolution of the REST API
深入淺出RoR
Internals of Steroids Framework
React.js - The Dawn of Virtual DOM
Redux Universal
Altitude NY 2018: Don't let the weeds overwhelm the garden
Mastering Grails 3 Plugins - GR8Conf EU 2016
Vaugham Hong - Embedding JavaScript V8
Women Who Code Connect 2018 Conference
Introduction to React, Flux, and Isomorphic Apps
Ad

Similar to Swagger codegen tool to generate REST services (20)

PPTX
How to generate a rest application - DevFest Vienna 2016
PPTX
Swagger - Making REST APIs friendlier
PDF
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
PPTX
Consuming Restful APIs using Swagger v2.0
PDF
Jcon 2017 How to use Swagger to develop REST applications
PDF
JHipster Beyond CRUD - JHipster Conf' 2019
PPTX
Introducing swagger
PPTX
Rest api code completion for javascript - dotjs 2015
PPTX
API Design first with Swagger
PPTX
Contract driven development
ODP
Introduction to Swagger
PPTX
Swagger APIs for Humans and Robots (Gluecon)
PPTX
Document your rest api using swagger - Devoxx 2015
PDF
Crystal clear service interfaces w/ Swagger/OpenAPI
PDF
Swagger 2.0: Latest and Greatest
PDF
"Design First" APIs with Swagger
PPTX
Another API-Blueprint, RAML and Swagger Comparison
ODP
Developing Microservices using Spring - Beginner's Guide
PPTX
Grails with swagger
PDF
Swagger: Restful documentation that won't put you to sleep
How to generate a rest application - DevFest Vienna 2016
Swagger - Making REST APIs friendlier
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
Consuming Restful APIs using Swagger v2.0
Jcon 2017 How to use Swagger to develop REST applications
JHipster Beyond CRUD - JHipster Conf' 2019
Introducing swagger
Rest api code completion for javascript - dotjs 2015
API Design first with Swagger
Contract driven development
Introduction to Swagger
Swagger APIs for Humans and Robots (Gluecon)
Document your rest api using swagger - Devoxx 2015
Crystal clear service interfaces w/ Swagger/OpenAPI
Swagger 2.0: Latest and Greatest
"Design First" APIs with Swagger
Another API-Blueprint, RAML and Swagger Comparison
Developing Microservices using Spring - Beginner's Guide
Grails with swagger
Swagger: Restful documentation that won't put you to sleep
Ad

Recently uploaded (20)

PDF
2025_AIFG_Akane_Kikuchi_Empathy_Design.PDF
PDF
Trends That Shape Graphic Design Services
PPTX
2. Competency Based Interviewing - September'16.pptx
PDF
How Animation is Used by Sports Teams and Leagues
PPT
EthicsNotesSTUDENTCOPYfghhnmncssssx sjsjsj
PPTX
22CDH01-V3-UNIT-I INTRODUCITON TO EXTENDED REALITY
PDF
intro_to_rust.pptx_123456789012446789.pdf
PDF
The Basics of Presentation Design eBook by VerdanaBold
PDF
321 LIBRARY DESIGN.pdf43354445t6556t5656
PDF
trenching-standard-drawings procedure rev
PPT
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
PPTX
UI UX Elective Course S1 Sistem Informasi RPS.pptx
PPTX
Necrosgwjskdnbsjdmdndmkdndndnmdndndkdmdndkdkndmdmis.pptx
PPTX
Presentation1.pptxnmnmnmnjhjhkjkjkkjkjjk
PPTX
a group casestudy on architectural aesthetic and beauty
PDF
SOUND-NOTE-ARCHITECT-MOHIUDDIN AKHAND SMUCT
PDF
Social Media USAGE .............................................................
PDF
2025CategoryRanking of technology university
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PPTX
Evolution_of_Computing_Presentation (1).pptx
2025_AIFG_Akane_Kikuchi_Empathy_Design.PDF
Trends That Shape Graphic Design Services
2. Competency Based Interviewing - September'16.pptx
How Animation is Used by Sports Teams and Leagues
EthicsNotesSTUDENTCOPYfghhnmncssssx sjsjsj
22CDH01-V3-UNIT-I INTRODUCITON TO EXTENDED REALITY
intro_to_rust.pptx_123456789012446789.pdf
The Basics of Presentation Design eBook by VerdanaBold
321 LIBRARY DESIGN.pdf43354445t6556t5656
trenching-standard-drawings procedure rev
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
UI UX Elective Course S1 Sistem Informasi RPS.pptx
Necrosgwjskdnbsjdmdndmkdndndnmdndndkdmdndkdkndmdmis.pptx
Presentation1.pptxnmnmnmnjhjhkjkjkkjkjjk
a group casestudy on architectural aesthetic and beauty
SOUND-NOTE-ARCHITECT-MOHIUDDIN AKHAND SMUCT
Social Media USAGE .............................................................
2025CategoryRanking of technology university
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
Evolution_of_Computing_Presentation (1).pptx

Swagger codegen tool to generate REST services

  • 1. www.cognizant.com Copyright © 2017 Cognizant 1 Spring boot REST data service code generation using Swagger code gen
  • 2. Why use Automatic Code Generation? Automatic Code Generation refers to using programs to generate code that the user would otherwise have to write themselves. Automatic code generation has certain advantages over traditional coding. • Correctness • High quality • Efficient use of the resources • Quick code generation • Consistent • Coding Abstractly
  • 3. Two step approach. Two step approach to generate the REST code using swagger code gen. • Swagger code gen tool reads the table meta data details from DB schema and generates the YAML file with Open API specs. • It generates the REST code based on the YAML file. Methodologies used to generate the code : • Bottom up approach with online mode
  • 5. Important code blocks of REST Services to be generated by the Swagger code gen.
  • 7. Swagger Custom Code Gen: • Default Swagger CodeGen generates only REST Controller of the spring boot project. Swagger custom code generator implementation is required to customize the REST controller, Service and DAO classes. • Swagger custom CodeGen implementation contain following important files: • CustomTemplate Codegen file • Mustache files • Configuration files. • Mustache file acts as templates for code generation.
  • 8. Detailed steps to generate REST code. • Deploy the YAML generator jar file to respective server. • Post a request to the URL of YAML generator with schema name and table name. o Sample URL: http://vdalhdpedged013.kbm1.loc:2020/codegen o Input :Sample Request: { "schemaName":"CNTCT_PNT_CONSUMER", "tableName":"CNTCT_PNT" } o Output : Swagger YAML file • Deploy the Custom swagger code gen jar file to the respective server. o Input : Swagger YAML file o Include package structures and other configuration details as part of customConfig.json o Execute the below command o java -jar targetCustomTemplate-1.0-SNAPSHOT.jar generate -l spring -i swagger.yaml -o test -c customConfig.json o Output : Spring boot REST data service code. • Deploy generated Spring boot REST code and test the CURD operations of the Phoenix REST data services.
  • 9. Next steps.. • Junit test cases implementation with good coverage. • Preprocessor and post processes of request and response for processing. • Client stub generation for given service through YAML. • Open API documentation through YAML file. • Error and Exception handling. • REST wrapper generation for given soap code ( This is a huge implementation). • Different configuration files Implementation like security, environment specific configuration (API gate way, service discovery configuration may require in feature). • Transaction management code implementation. • Pom file generation based on dependencies.