sensorthings-validator

Crates.iosensorthings-validator
lib.rssensorthings-validator
version0.4.1
created_at2025-11-16 04:38:18.433446+00
updated_at2026-01-10 05:58:12.441993+00
descriptionA Rust CLI tool that validates SensorThings API endpoints and responses.
homepage
repositoryhttps://codeberg.org/Cooperatief-Meten-Natuurlijk-UA/sensorthings-validator
max_upload_size
id1935180
size1,001,993
(meten-natuurlijk)

documentation

README

SensorThings Validator

Crates.io
Docs.rs
License: MIT

Overview

This project is a Rust-based validator for the OGC SensorThings API.
Its purpose is to automatically check endpoints of a SensorThings server for required and optional fields, validate write operations, and provide both human‑readable console summaries and machine‑readable JSON output.

✨ Features

  • Validates all standard SensorThings API entities:
    • Things
    • Locations
    • Datastreams
    • MultiDatastreams
    • Sensors
    • ObservedProperties
    • Observations
    • FeaturesOfInterest
    • TaskingCapabilities
    • Tasks
  • Ensures required fields are present.
  • Optionally checks for optional fields.
  • Supports STAplus extensions (Authors, Campaigns).
  • Validates write operations (POST/GET roundtrip).
  • Prints a summary table with ✅/❌ status per endpoint.
  • Exports results to validation_result.json including arrays of missing required/optional fields.

📂 Project Structure

src/
├── app.rs             // Application orchestration
├── cli.rs             // CLI argument definitions
├── config.rs          // Configuration and settings
├── endpoints.rs       // GET validation fields
├── error.rs           // Custom error type and handling
├── lib.rs             // Library entrypoint
├── main.rs            // CLI entrypoint
├── output_console.rs  // Console summary output
├── output_json.rs     // JSON export output
├── read_validator.rs  // Read checks (GET validation)
├── result.rs          // Result struct and helpers
├── write_validator.rs // Write checks (POST/GET roundtrip)
└── writer_payloads.rs // Minimal payloads per entity

📦 Installation

git clone https://codeberg.org/Cooperatief-Meten-Natuurlijk-UA/sensorthings-validator.git
cd sensorthings-validator
cargo build --release

🚀 Quickstart

Run the validator against a SensorThings service:

sensorthings-validator --host api.example.com --port 80

⚙️ Usage

Usage: sensorthings-validator [OPTIONS]

Options:
      --protocol <PROTOCOL>   Protocol of the SensorThings API [default: http]
                              [possible values: http, https]
      --host <HOST>           Host of the SensorThings API [default: localhost]
      --port <PORT>           Port of the SensorThings API [default: 8080]
      --prefix <PREFIX>       Optional URL path prefix [default: ""]
      --check-optional        Check optional fields as well as required ones
      --check-sta-plus        Enable STAplus validation (extra endpoints and fields)
      --check-write           Enable write validation (POST/GET roundtrip checks)
  -h, --help                  Print help
  -V, --version               Print version

The protocol, host, port, and optional prefix are combined into a base URL of the form:

<protocol>://<host>:<port>/<prefix>

Examples

# Validate against a local instance
sensorthings-validator --host localhost --port 8080

# Validate against a remote server and include optional fields
sensorthings-validator --host api.example.com --port 80 --check-optional

# Validate STAplus extensions
sensorthings-validator --host api.example.com --port 80 --check-sta-plus

# Validate write operations (POST/GET roundtrip)
sensorthings-validator --host api.example.com --port 80 --check-write

# Validate with a custom prefix
sensorthings-validator --host api.example.com --port 443 --prefix api/v1

# Validate using HTTPS
sensorthings-validator --protocol https --host secure.example.com --port 443 --prefix api/v2

📊 Example Output

Console summary

Read Validation Summary:
Entity               Path   Body   Path Msg                  Body Msg
Things               ✅      ✅      HTTP 200 OK               All required fields present
Observations         ✅      ❌      HTTP 200 OK               Missing required fields [author, campaign]

JSON export (validation_result.json)

{
  "base_url": "http://localhost:3000",
  "read": {
    "check_type": "Read",
    "results": [
      {
        "name": "Observations",
        "path_ok": true,
        "body_ok": false,
        "path_msg": "HTTP 200 OK",
        "body_msg": "Missing required fields",
        "missing_required": ["author", "campaign"],
        "missing_optional": []
      }
    ]
  },
  "write": null
}

🧪 Testing

Run the test suite with:

cargo test

📄 License

SPDX-License-Identifier: MIT
Copyright (c) 2025 Egon Kastelijn

Commit count: 22

cargo fmt