Common types
These are types used throughout the rest of this specification and defined here once to avoid repetition.
string
: a valid UTF-8 string. While being processed in code, it might be in a different encoding temporarily, but in the public interface of Opencast, these are always valid UTF-8.NonBlankString
: A string that is not "blank", meaning it is not empty and does not consists only of UnicodeWhite_Space
.NonBlankAsciiString
: ANonBlankString
that is also restricted to only using ASCII characters.Label
: aNonBlankAsciiString
that only consists of letters, numbers or-._~!*:@,;
. This means a label is URL-safe except for use in the domain part.(2?)ID
: aLabel
that cannot be changed after being created.Username
: TODO define rules for usernamesLangCode
: specifies a language and optionally a region, e.g.en
oren-US
. Based on the IETF BCP 47 language tag specification: a two letter language code, optionally followed by a hyphen and a two letter region tag.int8
,int16
,int32
,int64
: signed integers of specific bit width.uint8
,uint16
,uint32
,uint64
: unsigned integers of specific bit width.(1?)Milliseconds
: auint64
representing a duration or a video timestamp in milliseconds (ms). Impl note: whenever possible, in code, this should be a custom type and not justint
.DateTime
: a date + time with timezone, i.e. a specific moment in a specific timezone.Timestamp
: a specific moment in time, without time zone (e.g. always stored as UTC).
Generally, this basically uses TypeScript syntax:
T?
: denotes an optional type, i.e.bool?
means the field could be eithertrue
,false
or undefined. All fields without?
are required /non null
.T[]
: array of typeT
.[T, U, ...]
: a tuple of values."foo" | "bar"
: one of the listed constant values.
JSON serialization
For most types, the JSON serialization is the obvious one, but there are some minor important details.
bool
asbool
string
and all "string with extra requirements" (e.g.Label
,ID
,NonBlankAsciiString
) as string- Integers as number.
- Note on 64 bit integers: In JavaScript, there is only one
number
type, which is a 64 bit floating point number (double
,f64
). Those can only exactly represent integers up to 253. While JSON is closely related to JS, the format itself is allowed to exceedf64
precision and may in fact encode arbitrary precision numbers. Opencast should serialize a 64 bit integer as exact integer into JSON and not rounded like anf64
. Rounding might happen in the frontend, but the API should emit the exact integer value.
- Note on 64 bit integers: In JavaScript, there is only one
- Arrays as arrays
- Tuples as arrays
Map<string, string>
is serialized as objectDateTime
: as ISO 8601-compatible formatted string. The ISO standard actually allows a number of different formats by ommitting parts of the string. Opencast shall format all date times as eitherYYYY-MM-DDTHH:mm:ss.sssZ
orYYYY-MM-DDTHH:mm:ssZ
, i.e. only the sub-second part is optional. The parts on this format string are best described in the ECMAScript specification (which again, is a subset of ISO 8601). Only thing of note:Z
could either be literalZ
or a timezone offset like+02
.Timestamp
: likeDateTime
but always in UTC, so always ending with literalZ
.
Open questions
- (1?) Java famously has no/bad support for unsigned integers. Decide how to deal with that: do we just give up one bit or do we require proper unsigned usage via
Integer.*Unsigned
methods? Either way: these values must never be negative! - (2?) Maybe disallow more of these special characters?