From 24983038d282679ceabf488acaaded27eea510b0 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Thu, 11 Jan 2024 22:53:48 -0500 Subject: [PATCH] update to AsyncAPI 3.0.0 --- demo-asyncapi.yml | 171 +++++++++++++++++++------------ demo-config.yml | 1 + pygeoapi/asyncapi.py | 54 ++++++---- pygeoapi/templates/asyncapi.html | 4 +- pygeoapi/util.py | 2 +- 5 files changed, 145 insertions(+), 87 deletions(-) diff --git a/demo-asyncapi.yml b/demo-asyncapi.yml index 9db6155d2..2a2d367fa 100644 --- a/demo-asyncapi.yml +++ b/demo-asyncapi.yml @@ -1,71 +1,55 @@ -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: @@ -73,17 +57,76 @@ info: 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 diff --git a/demo-config.yml b/demo-config.yml index ce39a1060..067ba1dd1 100644 --- a/demo-config.yml +++ b/demo-config.yml @@ -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 diff --git a/pygeoapi/asyncapi.py b/pygeoapi/asyncapi.py index 36d06bbbe..f7f4607a0 100644 --- a/pygeoapi/asyncapi.py +++ b/pygeoapi/asyncapi.py @@ -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': { @@ -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') @@ -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 diff --git a/pygeoapi/templates/asyncapi.html b/pygeoapi/templates/asyncapi.html index e9673a722..d02d04c7a 100644 --- a/pygeoapi/templates/asyncapi.html +++ b/pygeoapi/templates/asyncapi.html @@ -2,11 +2,11 @@ AsyncAPI UI - {{ config['metadata']['identification']['title'] }} - +
- +