Skip to content

Commit

Permalink
update to AsyncAPI 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Jan 12, 2024
1 parent 92d327f commit 2498303
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 87 deletions.
171 changes: 107 additions & 64 deletions demo-asyncapi.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,132 @@
asyncapi: 2.6.0
asyncapi: 3.0.0
channels:
collections/canada-metadata:
notify-canada-metadata:
address: collections/canada-metadata
description: Open Canada sample data
subscribe:
message:
oneOf:
- messageId: message-canada-metadata
payload:
$ref: https://geojson.org/schema/Feature.json
operationId: notify-canada-metadata
collections/canada-surface-weather-obs:
messages:
DefaultMessage:
payload:
$ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml
notify-canada-surface-weather-obs:
address: collections/canada-surface-weather-obs
description: Canada surface weather observations
subscribe:
message:
oneOf:
- messageId: message-canada-surface-weather-obs
payload:
$ref: https://geojson.org/schema/Feature.json
operationId: notify-canada-surface-weather-obs
collections/erddap-demo:
messages:
DefaultMessage:
payload:
$ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml
notify-erddap-demo:
address: collections/erddap-demo
description: ERDDAP demo
subscribe:
message:
oneOf:
- messageId: message-erddap-demo
payload:
$ref: https://geojson.org/schema/Feature.json
operationId: notify-erddap-demo
collections/gdps-temperature:
messages:
DefaultMessage:
payload:
$ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml
notify-gdps-temperature:
address: collections/gdps-temperature
description: Global Deterministic Prediction System sample
subscribe:
message:
oneOf:
- messageId: message-gdps-temperature
payload:
$ref: https://geojson.org/schema/Feature.json
operationId: notify-gdps-temperature
collections/lakes:
messages:
DefaultMessage:
payload:
$ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml
notify-lakes:
address: collections/lakes
description: Large Lakes
subscribe:
message:
oneOf:
- messageId: message-lakes
payload:
$ref: https://geojson.org/schema/Feature.json
operationId: notify-lakes
collections/mapserver_world_map:
messages:
DefaultMessage:
payload:
$ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml
notify-mapserver_world_map:
address: collections/mapserver_world_map
description: MapServer demo WMS world map
subscribe:
message:
oneOf:
- messageId: message-mapserver_world_map
payload:
$ref: https://geojson.org/schema/Feature.json
operationId: notify-mapserver_world_map
collections/obs:
messages:
DefaultMessage:
payload:
$ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml
notify-obs:
address: collections/obs
description: Observations
subscribe:
message:
oneOf:
- messageId: message-obs
payload:
$ref: https://geojson.org/schema/Feature.json
operationId: notify-obs
messages:
DefaultMessage:
payload:
$ref: https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml
defaultContentType: application/json
externalDocs:
url: https://pygeoapi.io
id: http://localhost:5000
info:
contact:
email: you@example.org
name: Kralidis, Tom
url: https://pygeoapi.io
description: pygeoapi OGC API - Pub/Sub demonstration
externalDocs:
url: https://pygeoapi.io
license:
name: CC-BY 4.0 license
url: https://creativecommons.org/licenses/by/4.0/
tags:
- name: geospatial
- name: data
- name: api
title: pygeoapi OGC API - Pub/Sub demonstration
version: 0.15.dev0
operations:
consume-canada-metadata:
action: receive
channel:
$ref: '#/channels/notify-canada-metadata'
consume-canada-surface-weather-obs:
action: receive
channel:
$ref: '#/channels/notify-canada-surface-weather-obs'
consume-erddap-demo:
action: receive
channel:
$ref: '#/channels/notify-erddap-demo'
consume-gdps-temperature:
action: receive
channel:
$ref: '#/channels/notify-gdps-temperature'
consume-lakes:
action: receive
channel:
$ref: '#/channels/notify-lakes'
consume-mapserver_world_map:
action: receive
channel:
$ref: '#/channels/notify-mapserver_world_map'
consume-obs:
action: receive
channel:
$ref: '#/channels/notify-obs'
publish-canada-metadata:
action: send
channel:
$ref: '#/channels/notify-canada-metadata'
publish-canada-surface-weather-obs:
action: send
channel:
$ref: '#/channels/notify-canada-surface-weather-obs'
publish-erddap-demo:
action: send
channel:
$ref: '#/channels/notify-erddap-demo'
publish-gdps-temperature:
action: send
channel:
$ref: '#/channels/notify-gdps-temperature'
publish-lakes:
action: send
channel:
$ref: '#/channels/notify-lakes'
publish-mapserver_world_map:
action: send
channel:
$ref: '#/channels/notify-mapserver_world_map'
publish-obs:
action: send
channel:
$ref: '#/channels/notify-obs'
servers:
production:
description: pygeoapi OGC API - Pub/Sub demonstration
host: localhost:1883
protocol: mqtt
url: mqtt://localhost:1883
tags:
- name: geospatial
- name: data
- name: api
1 change: 1 addition & 0 deletions demo-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,6 @@ resources:
- type: feature
editable: true
name: Elasticsearch
#data: http://localhost:9200/canada-surface-weather.*
data: http://localhost:9200/canada-surface-weather-obs
id_field: id
54 changes: 34 additions & 20 deletions pygeoapi/asyncapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ def gen_asyncapi(cfg: dict) -> dict:
tags = l10n.translate(cfg['metadata']['identification']['keywords'], locale_) # noqa

u = cfg['pubsub']['broker']['url']
url = remove_url_auth(u)
protocol = urlparse(u).scheme
up = urlparse(u)
protocol = up.scheme
url = remove_url_auth(u).replace(f'{protocol}://', '')

a = {
'asyncapi': '2.6.0',
'asyncapi': '3.0.0',
'id': cfg['server']['url'],
'defaultContentType': 'application/json',
'info': {
Expand All @@ -86,20 +87,21 @@ def gen_asyncapi(cfg: dict) -> dict:
'name': cfg['metadata']['contact']['name'],
'url': cfg['metadata']['contact']['url'],
'email': cfg['metadata']['contact']['email']
}
},
'tags': [{'name': tag} for tag in tags],
'externalDocs': {
'url': cfg['metadata']['identification']['url']
},
},
'servers': {
'production': {
'url': url,
'host': url,
'protocol': protocol,
'description': description
}
},
'channels': {},
'tags': [{'name': tag} for tag in tags],
'externalDocs': {
'url': cfg['metadata']['identification']['url']
}
'operations': {}
}

LOGGER.debug('Generating channels foreach collection')
Expand All @@ -111,21 +113,33 @@ def gen_asyncapi(cfg: dict) -> dict:
title = l10n.translate(value['title'], locale_)
channel = {
'description': title,
'subscribe': {
'operationId': f'notify-{key}',
'message': {
'oneOf': [{
'messageId': f'message-{key}',
'payload': {
#'type': 'object',
'$ref': 'https://geojson.org/schema/Feature.json'
}
}]
'address': f'collections/{key}',
'messages': {
'DefaultMessage': {
'payload': {
'$ref': 'https://raw.githubusercontent.com/opengeospatial/ogcapi-environmental-data-retrieval/master/extensions/pubsub/openapi/schemas/pubsub-message-payload-schema.yaml' # noqa
}
}
}
}

operation = {
f'publish-{key}': {
'action': 'send',
'channel': {
'$ref': f'#/channels/notify-{key}'
}
},
f'consume-{key}': {
'action': 'receive',
'channel': {
'$ref': f'#/channels/notify-{key}'
}
}
}

a['channels'][f'collections/{key}'] = channel
a['channels'][f'notify-{key}'] = channel
a['operations'].update(operation)

return a

Expand Down
4 changes: 2 additions & 2 deletions pygeoapi/templates/asyncapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<html>
<head>
<title>AsyncAPI UI - {{ config['metadata']['identification']['title'] }}</title>
<link rel="stylesheet" href="https://unpkg.com/@asyncapi/react-component@1.0.0-next.47/styles/default.min.css">
<link rel="stylesheet" href="https://unpkg.com/@asyncapi/react-component@1.2.11/styles/default.min.css">
</head>
<body>
<div id="asyncapi"></div>
<script src="https://unpkg.com/@asyncapi/react-component@1.0.0-next.47/browser/standalone/index.js"></script>
<script src="https://unpkg.com/@asyncapi/react-component@1.2.11/browser/standalone/index.js"></script>
<script>
AsyncApiStandalone.render({
schema: {
Expand Down
2 changes: 1 addition & 1 deletion pygeoapi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ def transform_bbox(bbox: list, from_crs: str, to_crs: str) -> list:

def remove_url_auth(url: str) -> str:
"""
Provide a RFC1738 URL without embedded authentification
Provide a RFC1738 URL without embedded authentication
:param url: RFC1738 URL
Expand Down

0 comments on commit 2498303

Please sign in to comment.