-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial import from internal repo (code mainly by https://github.com/krzpiesiewicz) * Dispatch => HttpClient * SharedService, remove obsolete code * Parser package private * Refactor HttpConfig + separare Flink and Standalone * Tests, example * Cleanup, docs, tests * Review
- Loading branch information
Showing
53 changed files
with
2,352 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM python:3 | ||
RUN pip install flask-smorest | ||
EXPOSE 5000 | ||
ADD app.py / | ||
RUN mkdir /static && flask openapi print > /static/swagger.json | ||
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This is sample service with OpenAPI description. It's implemented in python, as Nussknacker | ||
can integrate with various technologies via enrichers. | ||
|
||
Of course, it's just a stub, not intended for any kind of production usage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import marshmallow as ma | ||
from flask import Flask | ||
from flask.views import MethodView | ||
from flask_smorest import Api, Blueprint | ||
|
||
class Customer: | ||
def __init__(self, id, name, category): | ||
self.name = name | ||
self.id = id | ||
self.category = category | ||
|
||
app = Flask(__name__, static_folder = '/static') | ||
|
||
@app.route('/swagger') | ||
def root(): | ||
return app.send_static_file('swagger.json') | ||
|
||
app.config['API_TITLE'] = 'Customers' | ||
app.config['API_VERSION'] = 'v1' | ||
app.config['OPENAPI_VERSION'] = '3.0.2' | ||
api = Api(app) | ||
|
||
class CustomerSchema(ma.Schema): | ||
id = ma.fields.Int(dump_only=True) | ||
name = ma.fields.String() | ||
category = ma.fields.String() | ||
|
||
class CustomerQueryArgsSchema(ma.Schema): | ||
name = ma.fields.String() | ||
|
||
blp = Blueprint( | ||
'customers', 'customers', url_prefix='/customers', | ||
description='Operations on customers' | ||
) | ||
@blp.route('/<customer_id>') | ||
class CustomerById(MethodView): | ||
|
||
@blp.response(200, CustomerSchema) | ||
@blp.doc(operationId='getCustomer') | ||
def get(self, customer_id): | ||
if customer_id == 10: | ||
return Customer(customer_id, "John Doe", "SILVER") | ||
else: | ||
return Customer(customer_id, "Robert Wright", "GOLD") | ||
|
||
api.register_blueprint(blp) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#This configuration auguments and overrides configuration in docker image | ||
#Here we configure OpenAPI based enricher, which is implemented by python service in customerservice | ||
{ | ||
processTypes.streaming.modelConfig.components.openAPI { | ||
url: "http://customerservice:5000/swagger" | ||
rootUrl: "http://customerservice:5000" | ||
categories: ["Default"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Overview | ||
======== | ||
Nussknacker can use services documented with OpenAPI specification. | ||
We use Swagger to parse OpenAPI, versions 2.x and 3.x are supported | ||
(version 2.x should be considered as deprecated). | ||
|
||
Nussknacker applies following rules when mapping OpenAPI services to enrichers: | ||
- Each operation is mapped to one enricher | ||
- If operationId is configured it's used as enricher name, otherwise we create it as concatenation | ||
of HTTP method, path and parameters (to provide some level of uniqueness) | ||
- Parameters (path, query of header) are used to define enricher parameters | ||
- If specification declares body parameter as object, we expand to parameter list | ||
- We expect operation to define 200/201 response, returned object is the one that is the result of enricher | ||
- We map 404 HTTP code to null value of enricher | ||
- We use `externalDocs.url` to extract documentation link | ||
|
||
Table below describes data types that OpenAPI integration handles: | ||
| OpenAPI Type | OpenAPI Format | Type in Nussknacker | | ||
| ------------- | -------------- | ------------------- | | ||
| boolean | | Boolean | | ||
| string | | String | | ||
| string | date-time | LocalDateTime | | ||
| integer | | Long | | ||
| number | | BigDecimal | | ||
| number | double | Double | | ||
| number | float | Double | | ||
| array | | array | | ||
| map/object | | record | | ||
|
||
OpenAPI integration can handle schema references. | ||
For objects and maps we use `properties` to define structure. | ||
For arrays we use `items` to define type of elements. | ||
|
||
|
||
Configuration | ||
============= | ||
|
||
Sample configuration: | ||
``` | ||
components { | ||
service1: { | ||
type: openAPI | ||
url = "http://myservice.com/swagger" | ||
rootUrl = "http://myservice.com/endpoint" | ||
security { | ||
apikey { | ||
type = "apiKey" | ||
apiKeyValue = "34534asfdasf" | ||
} | ||
} | ||
namePattern: "customer.*" | ||
allowedMethods: ["GET", "POST"] | ||
} | ||
} | ||
``` | ||
|
||
| Parameter | Required | Default | Description | | ||
| ---------- | -------- | ------- | ----------- | | ||
| url | true | | URL with OpenAPI resource | | ||
| rootUrl | false | | Base URL of service, can be used to override value from OpenAPI in NAT settings | | ||
| allowedMethods | false | ["GET"] | Usually only GET services should be used as enrichers are meant to be idempotent and not change data | | ||
| namePattern | false | .* | Regexp for filtering operations by operationId (i.e. enricher name) | | ||
| security | false | | Configuration for [authentication](https://swagger.io/docs/specification/authentication/). Currently only apiKey is supported | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
engine/components/openapi/src/it/resources/application.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
components { | ||
openAPI: { | ||
url = "https://rdb-simpledb.restdb.io/rest/_swagger.json" | ||
rootUrl = "https://rdb-simpledb.restdb.io/rest/" | ||
security { | ||
apikey { | ||
type = "apiKey" | ||
apiKeyValue = "TODO" | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
engine/components/openapi/src/it/resources/customer-swagger.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"paths": { | ||
"/customers/{customer_id}": { | ||
"get": { | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/Customer" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [ | ||
"customers" | ||
], | ||
"operationId": "getCustomer" | ||
}, | ||
"parameters": [ | ||
{ | ||
"in": "path", | ||
"name": "customer_id", | ||
"required": true, | ||
"schema": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"info": { | ||
"title": "Customers", | ||
"version": "v1" | ||
}, | ||
"tags": [ | ||
{ | ||
"name": "customers", | ||
"description": "Operations on customers" | ||
} | ||
], | ||
"openapi": "3.0.2", | ||
"components": { | ||
"schemas": { | ||
"Customer": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"category": { | ||
"type": "string" | ||
}, | ||
"id": { | ||
"type": "integer", | ||
"readOnly": true | ||
} | ||
} | ||
} | ||
}, | ||
"responses": {} | ||
} | ||
} |
Oops, something went wrong.