Skip to content

Commit

Permalink
refactor!: remove schemars
Browse files Browse the repository at this point in the history
I think we'll just use the pre-built schemas for stac-server
  • Loading branch information
gadomski committed Apr 27, 2024
1 parent e72f231 commit fa0a39b
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 173 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
- "-p stac -F reqwest"
- "-p stac-api"
- "-p stac -p stac-api -F geo"
- "-p stac -p stac-api -F schemars"
- "-p stac-async"
- "-p stac-cli --no-default-features"
- "-p stac-validate"
Expand Down Expand Up @@ -53,15 +52,15 @@ jobs:
- name: Set up Rust cache
uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test --no-default-features -F reqwest -F geo -F schemars
run: cargo test --no-default-features -F reqwest -F geo
test-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Set up Rust cache
uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test --no-default-features -F reqwest -F geo -F schemars
run: cargo test --no-default-features -F reqwest -F geo
build:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions stac-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Removed

- `schemars` feature ([#245](https://github.com/stac-utils/stac-rs/pull/245))

## [0.3.3] - 2024-04-07

### Added
Expand Down
3 changes: 1 addition & 2 deletions stac-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ categories = ["science", "data-structures", "web-programming"]

[features]
geo = ["dep:geo", "stac/geo"]
schemars = ["dep:schemars", "stac/schemars"]

[dependencies]
geo = { version = "0.28", optional = true }
schemars = { version = "0.8", optional = true }
geojson = "0.24"
serde = "1"
serde_json = "1"
serde_urlencoded = "0.7"
Expand Down
10 changes: 1 addition & 9 deletions stac-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,14 @@ To use the library in your project:
stac-api = "0.3"
```

**stac-api** has two optional features.
**stac-api** has one optional feature.
`geo` enables `Search::match`:

```toml
[dependencies]
stac-api = { version = "0.3", features = ["geo"] }
```

`schemars`, can be used to generate [jsonschema](https://json-schema.org/) documents for the API structures.
This is useful for auto-generating OpenAPI documentation:

```toml
[dependencies]
stac-api = { version = "0.3", features = ["schemars"] }
```

## Examples

```rust
Expand Down
1 change: 0 additions & 1 deletion stac-api/src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use stac::{Collection, Link, Links};

/// Object containing an array of collections and an array of links.
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Collections {
/// The [Collection] objects in the [stac::Catalog].
pub collections: Vec<Collection>,
Expand Down
1 change: 0 additions & 1 deletion stac-api/src/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub const ITEM_SEARCH_URI: &str = "https://api.stacspec.org/v1.0.0/item-search";
/// implementations - and not "just" a specific API / server, the server has to
/// declare the conformance classes it implements and conforms to.
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Conformance {
/// The conformance classes it implements and conforms to.
#[serde(rename = "conformsTo")]
Expand Down
4 changes: 4 additions & 0 deletions stac-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub enum Error {
#[error("cannot convert cql2-json to strings")]
CannotConvertCql2JsonToString(Map<String, Value>),

/// [geojson::Error]
#[error(transparent)]
GeoJson(#[from] geojson::Error),

/// [std::num::ParseIntError]
#[error(transparent)]
ParseIntError(#[from] std::num::ParseIntError),
Expand Down
1 change: 0 additions & 1 deletion stac-api/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::{
/// specification provides a mechanism for clients to request that servers to
/// explicitly include or exclude certain fields.
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Fields {
/// Fields to include.
#[serde(skip_serializing_if = "Vec::is_empty")]
Expand Down
1 change: 0 additions & 1 deletion stac-api/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde_json::{Map, Value};
/// The language of the filter expression.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "filter-lang", content = "filter")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum Filter {
/// `cql2-text`
#[serde(rename = "cql2-text")]
Expand Down
2 changes: 0 additions & 2 deletions stac-api/src/item_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const ITEM_COLLECTION_TYPE: &str = "FeatureCollection";
/// not be. Defined by the [itemcollection
/// fragment](https://github.com/radiantearth/stac-api-spec/blob/main/fragments/itemcollection/README.md).
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ItemCollection {
#[serde(
deserialize_with = "deserialize_type",
Expand Down Expand Up @@ -50,7 +49,6 @@ pub struct ItemCollection {
///
/// Part of the [context extension](https://github.com/stac-api-extensions/context).
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Context {
/// The count of results returned by this response. Equal to the cardinality
/// of features array.
Expand Down
2 changes: 0 additions & 2 deletions stac-api/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::collections::HashMap;
/// This is a lot like [Search](crate::Search), but without intersects, ids, and
/// collections.
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Items {
/// The maximum number of results to return (page size).
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -59,7 +58,6 @@ pub struct Items {
/// This is a lot like [Search](crate::Search), but without intersects, ids, and
/// collections.
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct GetItems {
/// The maximum number of results to return (page size).
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
1 change: 0 additions & 1 deletion stac-api/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use stac::Catalog;
/// URI is listed then the service must implement all of the required
/// capabilities.
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Root {
/// The [stac::Catalog].
#[serde(flatten)]
Expand Down
11 changes: 6 additions & 5 deletions stac-api/src/search.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{Error, Fields, Filter, GetItems, Items, Result, Sortby};
use geojson::Geometry;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use stac::{Geometry, Item};
use stac::Item;
use std::collections::HashMap;

/// The core parameters for STAC search are defined by OAFeat, and STAC adds a few parameters for convenience.
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Search {
/// The maximum number of results to return (page size).
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -68,7 +68,6 @@ pub struct Search {

/// GET parameters for the item search endpoint.
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct GetSearch {
/// The maximum number of results to return (page size).
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -158,9 +157,11 @@ impl Search {
///
/// ```
/// use stac_api::Search;
/// use geojson::{Geometry, Value};
///
/// let mut search = Search { bbox: Some(vec![-180.0, -90.0, 180.0, 80.0]), ..Default::default() };
/// search.validate().unwrap();
/// search.intersects = Some(stac::Geometry::point(0., 0.));
/// search.intersects = Some(Geometry::new(Value::Point(vec![0.0, 0.0])));
/// let _ = search.validate().unwrap_err();
/// ```
pub fn validate(&self) -> Result<()> {
Expand Down Expand Up @@ -292,7 +293,7 @@ impl Search {
/// let mut search = Search::new();
/// let mut item = Item::new("item-id");
/// assert!(search.intersects_matches(&item).unwrap());
/// search.intersects = Some(stac::Geometry::point(-105.1, 41.1));
/// search.intersects = Some(Geometry::new(Value::Point(vec![-105.1, 41.1])));
/// assert!(!search.intersects_matches(&item).unwrap());
/// item.set_geometry(Geometry::new(Value::Point(vec![-105.1, 41.1])));
/// assert!(search.intersects_matches(&item).unwrap());
Expand Down
2 changes: 0 additions & 2 deletions stac-api/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{

/// Fields by which to sort results.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Sortby {
/// The field to sort by.
pub field: String,
Expand All @@ -17,7 +16,6 @@ pub struct Sortby {
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum Direction {
#[serde(rename = "asc")]
Ascending,
Expand Down
8 changes: 8 additions & 0 deletions stac/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Changed

- Use `geojson::Geometry` instead of a crate-specific `Geometry` type([#245](https://github.com/stac-utils/stac-rs/pull/245))

### Removed

- `schemars` feature ([#245](https://github.com/stac-utils/stac-rs/pull/245))

## [0.6.0] - 2024-04-11

### Added
Expand Down
6 changes: 2 additions & 4 deletions stac/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ categories = ["science", "data-structures"]

[features]
gdal = ["dep:gdal", "dep:gdal-sys", "dep:log"]
geo = ["dep:geo", "dep:geojson"]
geo = ["dep:geo"]
reqwest = ["dep:reqwest"]
schemars = ["dep:schemars"]

[dependencies]
chrono = "0.4"
Expand All @@ -25,10 +24,9 @@ gdal-sys = { version = "0.9", optional = true, features = [
"bindgen",
] } # we use bindgen b/c the gdal crate doesn't support GDAL 3.8 as of this writing, and we depend on gdal-sys for build script usage
geo = { version = "0.28", optional = true }
geojson = { version = "0.24", optional = true }
geojson = { version = "0.24" }
log = { version = "0.4", optional = true }
reqwest = { version = "0.12", optional = true, features = ["json", "blocking"] }
schemars = { version = "0.8", optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
thiserror = "1"
Expand Down
12 changes: 1 addition & 11 deletions stac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Please see the [documentation](https://docs.rs/stac) for more usage examples.

## Features

There are four opt-in features.
There are a few opt-in features.

### reqwest

Expand Down Expand Up @@ -110,16 +110,6 @@ Then, you can set an item's geometry and bounding box at the same time:
}
```

### schemars

`schemars` allows for [jsonschema](https://json-schema.org/) generation from STAC objects.
This is mostly useful for auto-generating OpenAPI documentation for STAC APIs.

```toml
[dependencies]
stac = { version = "0.6", features = ["schemars"]}
```

## Other info

This crate is part of the [stac-rs](https://github.com/stac-utils/stac-rs) monorepo, see its README for contributing and license information.
1 change: 0 additions & 1 deletion stac/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::collections::HashMap;

/// An Asset is an object that contains a URI to data associated with the [Item](crate::Item) that can be downloaded or streamed.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Asset {
/// URI to the asset object.
///
Expand Down
25 changes: 25 additions & 0 deletions stac/src/bounds.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use geojson::{Geometry, Value};

/// Two-dimensional bounds.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Bounds {
Expand Down Expand Up @@ -62,6 +64,29 @@ impl Bounds {
self.xmax = self.xmax.max(other.xmax);
self.ymax = self.ymax.max(other.ymax);
}

/// Converts this bounds to a [Geometry](geojson::Geometry).
///
/// # Examples
///
/// ```
/// use stac::Bounds;
/// let bounds = Bounds::new(1., 1., 2., 2.);
/// let geomtry = bounds.to_geometry();
/// ```
pub fn to_geometry(&self) -> Geometry {
Geometry {
bbox: None,
value: Value::Polygon(vec![vec![
vec![self.xmin, self.ymin],
vec![self.xmax, self.ymin],
vec![self.xmax, self.ymax],
vec![self.xmax, self.ymax],
vec![self.xmin, self.ymin],
]]),
foreign_members: None,
}
}
}

impl Default for Bounds {
Expand Down
1 change: 0 additions & 1 deletion stac/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub const CATALOG_TYPE: &str = "Catalog";
/// Their purpose is discovery: to be browsed by people or be crawled by clients
/// to build a searchable index.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Catalog {
/// Set to `"Catalog"` if this Catalog only implements the `Catalog` spec.
#[serde(
Expand Down
5 changes: 0 additions & 5 deletions stac/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const DEFAULT_LICENSE: &str = "proprietary";
/// contains all the required fields is a valid STAC `Collection` and also a valid
/// STAC `Catalog`.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Collection {
/// Must be set to `"Collection"` to be a valid `Collection`.
#[serde(
Expand Down Expand Up @@ -99,7 +98,6 @@ pub struct Collection {
/// data offered by this `Collection`. May also include information about the
/// final storage provider hosting the data.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Provider {
/// The name of the organization or the individual.
pub name: String,
Expand Down Expand Up @@ -129,7 +127,6 @@ pub struct Provider {

/// The object describes the spatio-temporal extents of the [Collection](crate::Collection).
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Extent {
/// Spatial extents covered by the `Collection`.
pub spatial: SpatialExtent,
Expand All @@ -143,15 +140,13 @@ pub struct Extent {

/// The object describes the spatial extents of the Collection.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct SpatialExtent {
/// Potential spatial extents covered by the Collection.
pub bbox: Vec<Vec<f64>>,
}

/// The object describes the temporal extents of the Collection.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct TemporalExtent {
/// Potential temporal extents covered by the Collection.
pub interval: Vec<[Option<String>; 2]>,
Expand Down
5 changes: 2 additions & 3 deletions stac/src/extensions/projection.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! The Projection extension.

use crate::Geometry;
use super::Extension;
use geojson::Geometry;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};

use super::Extension;

/// The projection extension fields.
#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Clone)]
pub struct Projection {
Expand Down
Loading

0 comments on commit fa0a39b

Please sign in to comment.