-
Notifications
You must be signed in to change notification settings - Fork 140
[Notes Internal] Tech Notes Swagger integration
This will be in the next release of QBit. We have come pretty far along.
These are just notes and they are outdated.
Swagger integration is not done. It is in progress.. We are working on some swagger integration. We are not there yet. But we are working on it. The idea being that we can generate a JSON file that can be imported into Swagger UI and then generate clients for endpoints.
Later we will most likely add support for: http://raml.org/
It is not done yet.
Update....
Given these....
@RequestMapping("/sample/service")
public class SampleService {
@RequestMapping("/simple1/")
public String simple1() {
return "simple1";
}
@RequestMapping("/call1/foo/{arg4}/{2}")
public String method1(@RequestParam("arg1") final String arg1,
@HeaderParam("arg2") final int arg2,
@PathVariable final float arg3,
@PathVariable("arg4") final double arg4) {
return sputs(arg1, arg2, arg3, arg4);
}
//"/call2/{2}/{arg4}")
public String method2(final String arg1,
final int arg2,
final float arg3,
final double arg4) {
return sputs(arg1, arg2, arg3, arg4);
}
@RequestMapping("/simple2/path/")
public String simple2(@RequestParam("arg1") final String arg1) {
return "simple2";
}
@RequestMapping("/add/dept/")
public Department addDepartment(final Department department) {
return department;
}
}
package io.advantageous.qbit.meta.swagger;
import java.util.List;
public class Department {
List<Employee> employeeList;
Employee[] employeeArray;
}
package io.advantageous.qbit.meta.swagger;
public class Phone {
String countryCode;
String areaCode;
String digits;
}
package io.advantageous.qbit.meta.swagger;
public class Employee {
Phone phone;
String name;
int age;
long iq;
byte byteA;
Byte byteB;
byte[] byteC;
Byte[] byteD;
float floatA;
Float floatB;
double dA;
Double dB;
}
We are able to generate these:
{
"swagger": "2.0",
"info": {
"contact": {
"name": "Rick Hightower",
"url": "https://github.com/advantageous/qbit",
"email": "rick@rick.com"
},
"license": {
"name": "APACHE 2",
"url": "https://github.com/advantageous/qbit/blob/master/License"
}
},
"host": "localhost:9090",
"basePath": "/servicesEngine",
"schemes": [
"http",
"https",
"wss",
"ws"
],
"consumes": [
"application/json"
],
"definitions": {
"Department": {
"properties": {
"employeeList": {
"type": "array",
"items": {
"$ref": "#/definitions/Employee"
}
},
"employeeArray": {
"type": "array",
"items": {
"$ref": "#/definitions/Employee"
}
}
}
},
"Employee": {
"properties": {
"phone": {
"$ref": "#/definitions/Phone"
},
"name": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32"
},
"iq": {
"type": "integer",
"format": "int64"
},
"byteA": {
"type": "string",
"format": "byte"
},
"byteB": {
"type": "string",
"format": "byte"
},
"byteC": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
},
"byteD": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
},
"floatA": {
"type": "number",
"format": "float"
},
"floatB": {
"type": "number",
"format": "float"
},
"dA": {
"type": "number",
"format": "double"
},
"dB": {
"type": "number",
"format": "double"
}
}
},
"Phone": {
"properties": {
"countryCode": {
"type": "string"
},
"areaCode": {
"type": "string"
},
"digits": {
"type": "string"
}
}
}
},
"produces": [
"application/json"
],
"paths": {
"/call1/foo/{arg4}/{2}": {
"get": {
"operationId": "method1",
"produces": [
"application/json"
],
"parameters": [
{
"name": "arg1",
"in": "query",
"type": "string"
},
{
"name": "arg2",
"in": "header",
"type": "integer"
},
{
"in": "THIS QBIT FEATURE URI POSITIONAL PARAM IS NOT SUPPORTED BY SWAGGER",
"type": "number"
},
{
"name": "arg4",
"in": "path",
"type": "number"
}
],
"responses": {
"200": {
"schema": {
"type": "string"
}
}
}
}
},
"/simple2/path/": {
"get": {
"operationId": "simple2",
"produces": [
"application/json"
],
"parameters": [
{
"name": "arg1",
"in": "query",
"type": "string"
}
],
"responses": {
"200": {
"schema": {
"type": "string"
}
}
}
}
},
"/simple1/": {
"get": {
"operationId": "simple1",
"produces": [
"application/json"
],
"responses": {
"200": {
"schema": {
"type": "string"
}
}
}
}
},
"/add/dept/": {
"get": {
"operationId": "addDepartment",
"produces": [
"application/json"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Department"
}
}
],
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/Department"
}
}
}
}
}
}
}
If you had a service like this:
@RequestMapping("/sample/service")
public class SampleService {
@RequestMapping("/simple1/")
public String simple1() {
return "simple1";
}
@RequestMapping("/call1/foo/{arg4}/{2}")
public String method1(@RequestParam("arg1") final String arg1,
@HeaderParam("arg2") final int arg2,
@PathVariable final float arg3,
@PathVariable("arg4") final double arg4) {
return sputs(arg1, arg2, arg3, arg4);
}
//"/call2/{2}/{arg4}")
public String method2(final String arg1,
final int arg2,
final float arg3,
final double arg4) {
return sputs(arg1, arg2, arg3, arg4);
}
@RequestMapping("/simple2/path/")
public String simple2(@RequestParam("arg1") final String arg1) {
return "simple2";
}
}
Then we can generate a swagger file as so.
{
"swagger": "2.0",
"info": {
"contact": {},
"license": {}
},
"host": "localhost",
"basePath": "/servicesEngineEngine",
"schemes": [
"http",
"https",
"wss",
"ws"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/call1/foo/{arg4}/{2}": {
"get": {
"operationId": "method1",
"produces": [
"application/json"
],
"responses": {
"200": {}
}
}
},
"/simple2/path/": {
"get": {
"operationId": "simple2",
"produces": [
"application/json"
],
"responses": {
"200": {}
}
}
},
"/method2": {
"get": {
"operationId": "method2",
"produces": [
"application/json"
],
"responses": {
"200": {}
}
}
},
"/simple1/": {
"get": {
"operationId": "simple1",
"produces": [
"application/json"
],
"responses": {
"200": {}
}
}
}
}
}
We really just started but there are a few API tools we would like to produce. Swagger being just one.
QBit has its own meta that we use to convert to swagger.
See the class io.advantageous.qbit.meta.swagger.MetaTransformerFromQbitMetaToSwagger
to see progress.
Update...
We are able to convert classes into defintions.
Give this.
public static class Phone {
String countryCode;
String areaCode;
String digits;
}
public static class Employee {
Phone phone;
String name;
int age;
long iq;
byte byteA;
Byte byteB;
byte[] byteC;
Byte[] byteD;
float floatA;
Float floatB;
double dA;
Double dB;
}
public static class Department {
List<Employee> employeeList;
Employee[] employeeArray;
}
We can produce this set of definitions.
{
"Department": {
"properties": {
"employeeList": {
"type": "array",
"items": {
"$ref": "#/definitions/Employee"
}
},
"employeeArray": {
"type": "array",
"items": {
"$ref": "#/definitions/Employee"
}
}
}
},
"Employee": {
"properties": {
"phone": {
"type": "array",
"items": {
"$ref": "#/definitions/Phone"
}
},
"name": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32"
},
"iq": {
"type": "integer",
"format": "int64"
},
"byteA": {
"type": "string",
"format": "byte"
},
"byteB": {
"type": "string",
"format": "byte"
},
"byteC": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
},
"byteD": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
},
"floatA": {
"type": "number",
"format": "float"
},
"floatB": {
"type": "number",
"format": "float"
},
"dA": {
"type": "number",
"format": "double"
},
"dB": {
"type": "number",
"format": "double"
}
}
},
"Phone": {...}
}
QBit Website What is Microservices Architecture?
QBit Java Micorservices lib tutorials
The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
Reactive Programming, Java Microservices, Rick Hightower
Java Microservices Architecture
[Microservice Service Discovery with Consul] (http://www.mammatustech.com/Microservice-Service-Discovery-with-Consul)
Microservices Service Discovery Tutorial with Consul
[Reactive Microservices] (http://www.mammatustech.com/reactive-microservices)
[High Speed Microservices] (http://www.mammatustech.com/high-speed-microservices)
Reactive Microservices Tutorial, using the Reactor
QBit is mentioned in the Restlet blog
All code is written using JetBrains Idea - the best IDE ever!
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting
Tutorials
- QBit tutorials
- Microservices Intro
- Microservice KPI Monitoring
- Microservice Batteries Included
- RESTful APIs
- QBit and Reakt Promises
- Resourceful REST
- Microservices Reactor
- Working with JSON maps and lists
__
Docs
Getting Started
- First REST Microservice
- REST Microservice Part 2
- ServiceQueue
- ServiceBundle
- ServiceEndpointServer
- REST with URI Params
- Simple Single Page App
Basics
- What is QBit?
- Detailed Overview of QBit
- High level overview
- Low-level HTTP and WebSocket
- Low level WebSocket
- HttpClient
- HTTP Request filter
- HTTP Proxy
- Queues and flushing
- Local Proxies
- ServiceQueue remote and local
- ManagedServiceBuilder, consul, StatsD, Swagger support
- Working with Service Pools
- Callback Builders
- Error Handling
- Health System
- Stats System
- Reactor callback coordination
- Early Service Examples
Concepts
REST
Callbacks and Reactor
Event Bus
Advanced
Integration
- Using QBit in Vert.x
- Reactor-Integrating with Cassandra
- Using QBit with Spring Boot
- SolrJ and service pools
- Swagger support
- MDC Support
- Reactive Streams
- Mesos, Docker, Heroku
- DNS SRV
QBit case studies
QBit 2 Roadmap
-- Related Projects
- QBit Reactive Microservices
- Reakt Reactive Java
- Reakt Guava Bridge
- QBit Extensions
- Reactive Microservices
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting