You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then we loose the rest of the type - say that { "test": 123 } is passed into the query, we can't analyze it and know if that's valid or not.
I see there is a branch about static types, which seem to do some pretty cool improvements on the builtin types, and as part RumbleML, annotate was introduced, but are there any plans to support something like how TypeScripts annotates objects and arrays, or even better, JSON Schema?
Edit: The example in listing 1.23 on this guided tour for XQuery seems like a pretty good candidate, just with JSON Schema instead:
importschemaorder = "https://example.com/order.json";
declarefunctionlocal:lookup-billing-address($order-id as string)
asorder.definitions.address(: or order#address :)
{
let $order asorder := fetch-json("https://example.com/orders?order_id=" || uri-encode($order-id))
return $order.billing_address
};
local:lookup-billing-address("ORD-1234")
JSON Schema to JSONiq types
RumbleDB should turn types in schemas to JSONiq types, such as:
JSONiq
JSON Schema
OpenAPI
string
{ type: "string" }
Same
base64Binary
{ type: "string", contentEncoding: "base64" }
{ type: "string", format: "byte" }
Other constraints such as maxProperties should be ignored, and are only used by linters.
OpenAPI 3 example
importschema pet-store = "https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml";
declarefunctionlocal:lookup-pet($pet-id as integer)
as pet-store.components.schemas.Pet
{
fetch-json("https://petstore3.swagger.io/api/v3/pets/" || $pet-id)
};
JSound support
If JSound schemas has a way of identifying itself like JSON Schema $schema: "..." OpenAPI openapi: "3.0.2", one should be able to import JSound schemas as well.
The text was updated successfully, but these errors were encountered:
jsommr
changed the title
Typed objects and arrays
JSON Schema support
Feb 26, 2021
Indeed annotate() is only a temporary function. We are actively working on static typing as well as supporting user-defined types right now, first with JSound, and we may consider other schema languages at a later point.
So your request confirms that this is a useful feature and that the timing is good. Thank you for this!
The next release will include a limited user-defined-type system with the JSound compact syntax. The type names can be reused as variable/parameter types and instance of/treat as expressions.
Example:
declare type local:id-and-sentence as {
"id": "integer",
"sentence": "string"
};
let $local-data := (
{"id": 1, "sentence": "Hi I heard about Spark"},
{"id": 2, "sentence": "I wish Java could use case classes"},
{"id": 3, "sentence": "Logistic regression models are neat"}
)
let $validated-data := validate type local:id-and-sentence* { $local-data }
return $validated-data instance of local:id-and-sentence+
The functionality will then continue to be expanded in subsequent releases.
Having a way to create custom types would enable auto generation of eg. OpenAPI 3 specifications based on static code analysis.
Say we have a query like this:
We know that the input is an optional string, and that string? is returned. But what if we have
Then we loose the rest of the type - say that
{ "test": 123 }
is passed into the query, we can't analyze it and know if that's valid or not.I see there is a branch about static types, which seem to do some pretty cool improvements on the builtin types, and as part RumbleML,
annotate
was introduced, but are there any plans to support something like how TypeScripts annotates objects and arrays, or even better, JSON Schema?Edit: The example in listing 1.23 on this guided tour for XQuery seems like a pretty good candidate, just with JSON Schema instead:
And ideally, one could create the schema like this:
Examples
https://example.com/address.json
https://example.com/query1.jq
https://example.com/person.json
https://example.com/query2.jq
Example with definitions
https://example.com/order.json
https://example.com/query3.jq
JSON Schema to JSONiq types
RumbleDB should turn types in schemas to JSONiq types, such as:
Other constraints such as
maxProperties
should be ignored, and are only used by linters.OpenAPI 3 example
JSound support
If JSound schemas has a way of identifying itself like JSON Schema
$schema: "..."
OpenAPIopenapi: "3.0.2"
, one should be able to import JSound schemas as well.The text was updated successfully, but these errors were encountered: