Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ Environment variables that can be used to configure the container or the environ
| GUNICORN_CMD_ARGS | Command-line arguments for configuring Gunicorn, a Python WSGI HTTP Server. | ☐ |
| CORS_ORIGINS | Indicates whether the response can be shared with requesting code from the given origins (passed as a comma separated string) | ☐ |
| CORS_HEADERS | Indicates what headers should be supported with cross-origin requests (passed as a comma separated string) | ☐ |
| JINJA2_TEMPLATES | Path to a folder with jinja2 templates to override the default templates used by the API. See template section for details | ☐ |
| OPENAPI_METADATA_PATH | Path to an alternative OpenAPI metadata json file. It need to have the same fields as the openapi/openapi_metadata.py file. | ☐ |
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the mechanism to inject the JINJA templates and json files into the docker container?


## OpenAPI metadata

To load your own metadata file, mount your new openapi metadata json file, with the same structure and key as the default one, found in openapi_default_files, and point the environment variable `OPENAPI_METADATA_PATH` to the new file. If you mount your folder to the same as the default one, make sure to not overwrite files you have not replaced.

## JINJA2_TEMPLATES

The jinja2 folder must container the following files:

- dataset_metadata_template.j2: this is the metadata template for the observation collection.

### dataset_metadata_template.j2

The current jinja2 filters will be replaced. It's important to use the json j2 filter when inserting these strings.

- spatial_extent
- temporal_extent
- url_base
- url_conformance
- url_docs

All url fields are dynamically generated based on the request url base.

To load a custom template, mount a folder with your new template in to the container and set the `JINJA2_TEMPLATES` environment variable to point your new folder.

## Prerequisites of running locally

Expand Down
25 changes: 9 additions & 16 deletions api/openapi/openapi_metadata.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
openapi_metadata = {
"title": "EDR Observations API Europe EUMETNET",
"description": (
"OGC EDR API data service for European meteorological observations from EUMETNET,"
" co-funded by the European Union."
),
"contact": {
"name": "EUMETNET",
"url": "https://www.eumetnet.eu/about-us/",
"email": "[email protected]",
},
"license_info": {
"name": "CC-BY-4.0",
"url": "https://creativecommons.org/licenses/by/4.0/",
},
}
import os
import json

with open(
os.getenv("OPENAPI_METADATA_PATH", "/app/openapi_default_files/openapi_metadata.json"),
"r",
) as file:
openapi_metadata = json.load(file)
print(openapi_metadata)
13 changes: 13 additions & 0 deletions api/openapi_default_files/openapi_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "EDR Observations API Europe EUMETNET",
"description": "OGC EDR API data service for European meteorological observations from EUMETNET, co-funded by the European Union.",
"contact": {
"name": "EUMETNET",
"url": "https://www.eumetnet.eu/about-us/",
"email": "[email protected]"
},
"license_info": {
"name": "CC-BY-4.0",
"url": "https://creativecommons.org/licenses/by/4.0/"
}
}
3 changes: 2 additions & 1 deletion api/routers/feature.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from typing import Annotated

import datastore_pb2 as dstore
Expand All @@ -23,7 +24,7 @@

router = APIRouter(prefix="/collections/observations")

env = Environment(loader=FileSystemLoader("templates"), autoescape=select_autoescape())
env = Environment(loader=FileSystemLoader(os.getenv("JINJA2_TEMPLATES", "templates")), autoescape=select_autoescape())


@router.get(
Expand Down
Loading