Skip to content

Commit

Permalink
feat: YAML type validation
Browse files Browse the repository at this point in the history
  • Loading branch information
d-jeffery committed Oct 31, 2023
1 parent 34bb0ff commit 93f3177
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 57 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ See the [DEVELOPMENT](./docs/DEVELOPMENT.md) and [CONTRIBUTING](https://github.c

## Acknowledgments
- CEL Textmate Grammar was taken from [vscode-cel](https://github.com/hmarr/vscode-cel)
- Range conversion from `yaml` to `vscode` from [actions/languageservices](https://github.com/actions/languageservices/blob/4280a967a8aa058dd3c8825349b90bc932d82283/workflow-parser/src/workflows/yaml-object-reader.ts#L220)

## License

Expand Down
118 changes: 111 additions & 7 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
},
"dependencies": {
"@openfga/syntax-transformer": "^0.2.0-beta.4",
"ajv": "^8.12.0",
"vscode-languageserver": "^8.1.0",
"vscode-languageserver-textdocument": "^1.0.11",
"yaml": "^2.3.2"
"yaml": "^2.3.3"
},
"scripts": {}
"scripts": {},
"devDependencies": {
"@types/js-yaml": "^4.0.8"
}
}
161 changes: 161 additions & 0 deletions server/src/openfga-yaml-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@

export const OPENFGA_YAML_SCHEMA = {
type: "object",
oneOf: [
{ required: ["model_file"] },
{ required: ["model"] }
],
properties: {
name: {
type: "string",
description: "The store name"
},
model_file: {
type: "string",
description: "The Authorization Model"
},
model: {
type: "string",
description: "The Authorization Model"
},
tuples: {
type: "array",
items: {
type: "object",
additionalProperties: false,
properties: {
user: {
type: "string",
description: "The user"
},
relation: {
type: "string",
description: "The relation"
},
object: {
type: "string",
description: "The object"
},
condition: {
type: "object",
additionalProperties: false,
properties: {
name: {
type: "string",
},
context: {
type: "object"
}
}
}
}
}
},
tests: {
type: "array",
items: {
type: "object",
additionalProperties: false,
properties: {
name: {
type: "string",
description: "The test name"
},
description: {
type: "string",
description: "The test description"
},
tuples: {
type: "array",
items: {
type: "object",
additionalProperties: false,
properties: {
user: {
type: "string",
description: "The user"
},
relation: {
type: "string",
description: "The relation"
},
object: {
type: "string",
description: "The object"
},
context: {
type: "object"
}
}
}
},
check: {
type: "array",
items: {
type: "object",
additionalProperties: false,
properties: {
user: {
type: "string",
description: "The user"
},
object: {
type: "string",
description: "The object"
},
assertions: {
type: "object",
patternProperties: {
".*": {
type: "boolean"
}
}
},
context: {
type: "object"
}
}
}
},
list_objects: {
type: "array",
items: {
type: "object",
additionalProperties: false,
properties: {
user: {
type: "string",
description: "The user"
},
relation: {
type: "string",
description: "The relation"
},
type: {
type: "string",
description: "The object type"
},
assertions: {
type: "object",
patternProperties: {
".*": {
type: "array",
items: {
type: "string"
}
}
}
},
context: {
type: "object"
}
}
}
}
}
}
}
},
required: ["tests"],
additionalProperties: false,
};
Loading

0 comments on commit 93f3177

Please sign in to comment.