Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add array example #22

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/hasTypeAssertion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Has type Assertion

We use the very same types as JSON Schema allows, which each has a variant in each respective language.

If multiple arguments are are provided such as below, it means that the argument above the other is used as a generic input.
```json
{
"assertion": "hasType",
"arguments": [
"array",
"string"
]
}
```
In the example above it means that we have an array of strings. Restriction to this syntax is only one generic input allowed per type.


| Type | TS | Java |
| ----------- | ----------- | ----------- |
| number | number | double
| string | string | String
| boolean | boolean | boolean
| null | null | JsonNull
| object | any | Object
| array< Type > | < Type >[] | List< Type >


## Null restrictions

`null` will in many cases require a custom wrapper class to represent a null value. I.e. for Java we recommend `JsonNull`:

```java
class JsonNull {
static public JsonNull getInstance() {
return null;
}
}
```

In others, such as `TS` we can use `null`.
154 changes: 154 additions & 0 deletions test-suite/idl-schema/arrays/arrays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
[
{
"description": "Should have accurate array",
"schemas": [
{
"$schema": "https://json-schema.org/draft/2020-12/idl-schema",
"name": "SomeTitle",
"type": "object",
"properties": {
"NumberArray": {
"type": "array",
"items": {
"type": "number"
}
},
"StringArray": {
"type": "array",
"items": {
"type": "string"
}
},
"BooleanArray": {
"type": "array",
"items": {
"type": "boolean"
}
},
"NullArray": {
"type": "array",
"items": {
"type": "null"
}
},
"ObjectArray": {
"type": "array",
"items": {
"type": "object"
}
},
"ObjectArrayInArray": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "object"
}
}
}
}
}
],
"tests": [
{
"assertion": "hasClass",
"arguments": [
"SomeTitle"
],
"tests": [
{
"assertion": "hasProperty",
"arguments": [
"NumberArray"
],
"tests": [
{
"assertion": "hasType",
"arguments": [
"array",
"number"
]
}
]
},
{
"assertion": "hasProperty",
"arguments": [
"StringArray"
],
"tests": [
{
"assertion": "hasType",
"arguments": [
"array",
"string"
]
}
]
},
{
"assertion": "hasProperty",
"arguments": [
"BooleanArray"
],
"tests": [
{
"assertion": "hasType",
"arguments": [
"array",
"boolean"
]
}
]
},
{
"assertion": "hasProperty",
"arguments": [
"NullArray"
],
"tests": [
{
"assertion": "hasType",
"arguments": [
"array",
"null"
]
}
]
},
{
"assertion": "hasProperty",
"arguments": [
"ObjectArray"
],
"tests": [
{
"assertion": "hasType",
"arguments": [
"array",
"object"
]
}
]
},
{
"assertion": "hasProperty",
"arguments": [
"ObjectArrayInArray"
],
"tests": [
{
"assertion": "hasType",
"arguments": [
"array",
"array",
"object"
]
}
]
}
]
}
]
}
]