Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into phil/pacha-41-vs-main
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-chambers committed Oct 29, 2024
2 parents 69ab675 + c80bda7 commit 53b99c6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 83 deletions.
11 changes: 1 addition & 10 deletions ndc-models/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(deprecated)]

use std::{borrow::Borrow, collections::BTreeMap};

use indexmap::IndexMap;
Expand Down Expand Up @@ -211,8 +209,7 @@ pub struct SchemaResponse {
#[schemars(title = "Scalar Type")]
pub struct ScalarType {
/// A description of valid values for this scalar type.
/// Defaults to `TypeRepresentation::JSON` if omitted
pub representation: Option<TypeRepresentation>,
pub representation: TypeRepresentation,
/// A map from aggregate function names to their definitions. Result type names must be defined scalar types declared in ScalarTypesCapabilities.
pub aggregate_functions: BTreeMap<AggregateFunctionName, AggregateFunctionDefinition>,
/// A map from comparison operator names to their definitions. Argument type names must be defined scalar types declared in ScalarTypesCapabilities.
Expand All @@ -232,12 +229,6 @@ pub enum TypeRepresentation {
Boolean,
/// Any JSON string
String,
/// Any JSON number
#[deprecated(since = "0.1.2", note = "Use sized numeric types instead")]
Number,
/// Any JSON number, with no decimal part
#[deprecated(since = "0.1.2", note = "Use sized numeric types instead")]
Integer,
/// A 8-bit signed integer with a minimum value of -2^7 and a maximum value of 2^7 - 1
Int8,
/// A 16-bit signed integer with a minimum value of -2^15 and a maximum value of 2^15 - 1
Expand Down
42 changes: 4 additions & 38 deletions ndc-models/tests/json_schema/schema_response.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@
"type": "object",
"required": [
"aggregate_functions",
"comparison_operators"
"comparison_operators",
"representation"
],
"properties": {
"representation": {
"description": "A description of valid values for this scalar type. Defaults to `TypeRepresentation::JSON` if omitted",
"anyOf": [
"description": "A description of valid values for this scalar type.",
"allOf": [
{
"$ref": "#/definitions/TypeRepresentation"
},
{
"type": "null"
}
]
},
Expand Down Expand Up @@ -128,38 +126,6 @@
}
}
},
{
"description": "Any JSON number",
"deprecated": true,
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"number"
]
}
}
},
{
"description": "Any JSON number, with no decimal part",
"deprecated": true,
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"integer"
]
}
}
},
{
"description": "A 8-bit signed integer with a minimum value of -2^7 and a maximum value of 2^7 - 1",
"type": "object",
Expand Down
8 changes: 4 additions & 4 deletions ndc-reference/bin/reference/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ async fn get_schema() -> Json<models::SchemaResponse> {
(
"String".into(),
models::ScalarType {
representation: Some(models::TypeRepresentation::String),
representation: models::TypeRepresentation::String,
aggregate_functions: BTreeMap::from_iter([
("max".into(), models::AggregateFunctionDefinition::Max),
("min".into(), models::AggregateFunctionDefinition::Min),
Expand Down Expand Up @@ -368,7 +368,7 @@ async fn get_schema() -> Json<models::SchemaResponse> {
(
"Int".into(),
models::ScalarType {
representation: Some(models::TypeRepresentation::Int32),
representation: models::TypeRepresentation::Int32,
aggregate_functions: BTreeMap::from_iter([
("max".into(), models::AggregateFunctionDefinition::Max),
("min".into(), models::AggregateFunctionDefinition::Min),
Expand Down Expand Up @@ -407,7 +407,7 @@ async fn get_schema() -> Json<models::SchemaResponse> {
(
"Int64".into(),
models::ScalarType {
representation: Some(models::TypeRepresentation::Int64),
representation: models::TypeRepresentation::Int64,
aggregate_functions: BTreeMap::from_iter([
("max".into(), models::AggregateFunctionDefinition::Max),
("min".into(), models::AggregateFunctionDefinition::Min),
Expand Down Expand Up @@ -446,7 +446,7 @@ async fn get_schema() -> Json<models::SchemaResponse> {
(
"Float".into(),
models::ScalarType {
representation: Some(models::TypeRepresentation::Float64),
representation: models::TypeRepresentation::Float64,
aggregate_functions: BTreeMap::from_iter([
("max".into(), models::AggregateFunctionDefinition::Max),
("min".into(), models::AggregateFunctionDefinition::Min),
Expand Down
23 changes: 9 additions & 14 deletions ndc-test/src/test_cases/query/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,11 @@ pub fn check_value_has_type(
))
}
} else if let Some(scalar_type) = schema.scalar_types.get(name) {
if let Some(representation) = &scalar_type.representation {
representations::check_value_has_representation(
representation,
&value,
json_path,
)
} else {
Ok(())
}
representations::check_value_has_representation(
&scalar_type.representation,
&value,
json_path,
)
} else {
Err(Error::NamedTypeIsNotDefined(name.clone()))
}
Expand Down Expand Up @@ -593,11 +589,10 @@ mod representations {

match representation {
models::TypeRepresentation::Boolean => check!(value.is_boolean(), "boolean"),
models::TypeRepresentation::Number
| models::TypeRepresentation::Float32
| models::TypeRepresentation::Float64 => check!(value.is_number(), "number"),
models::TypeRepresentation::Integer
| models::TypeRepresentation::Int8
models::TypeRepresentation::Float32 | models::TypeRepresentation::Float64 => {
check!(value.is_number(), "number");
}
models::TypeRepresentation::Int8
| models::TypeRepresentation::Int16
| models::TypeRepresentation::Int32 => check!(value.is_i64(), "integer"),
models::TypeRepresentation::String
Expand Down
5 changes: 2 additions & 3 deletions ndc-test/src/test_cases/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ pub async fn validate_schema<R: Reporter>(
let Some(scalar_type) = schema.scalar_types.get(result_type) else {
return Err(Error::NamedTypeIsNotDefined(result_type.inner().clone()));
};
let Some(
models::TypeRepresentation::Int64 | models::TypeRepresentation::Float64,
) = scalar_type.representation
let (models::TypeRepresentation::Int64
| models::TypeRepresentation::Float64) = scalar_type.representation
else {
return Err(Error::InvalidTypeRepresentation(result_type.clone()));
};
Expand Down
4 changes: 4 additions & 0 deletions specification/src/specification/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ In addition, aggregate functions now have a set of [standard functions](./schema

Clients can now [indicate the intended protocol version](./versioning.md#requirements) in a HTTP header alongside any request.

### Scalar type representations

Scalar type representations are now required; previously they were optional, where a missing representation was assumed to mean JSON. In addition, the deprecated number and integer representations have been removed; a more precise representation (such as float64 or int32) should be chosen instead.

## `0.1.6`

### Specification
Expand Down
15 changes: 1 addition & 14 deletions specification/src/specification/schema/scalar-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ Scalar types define several types of operations, which extend the capabilities o

## Type Representations

A scalar type definition can include an optional _type representation_. The representation, if provided, indicates to potential callers what values can be expected in responses, and what values are considered acceptable in requests.

If the representation is omitted, it defaults to `json`.
A scalar type definition must include a _type representation_. The representation indicates to potential callers what values can be expected in responses, and what values are considered acceptable in requests.

### Supported Representations

Expand Down Expand Up @@ -46,17 +44,6 @@ For example, this representation indicates that the only three valid values are
}
```

### Deprecated Representations

The following representations are deprecated as of version 0.1.2:

| `type` | Description | JSON representation |
| --------- | ------------------------------------ | ------------------- |
| `number` | Any JSON number | Number |
| `integer` | Any JSON number with no decimal part | Number |

Connectors should use the sized integer and floating-point types instead.

## Comparison Operators

Comparison operators extend the query AST with the ability to express new binary comparison expressions in the predicate.
Expand Down

0 comments on commit 53b99c6

Please sign in to comment.