Skip to content

Commit

Permalink
change json to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ipatka committed Oct 31, 2023
1 parent 2728f56 commit 0830805
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolve, join, dirname } from 'path'
import { fileURLToPath } from 'url'
import Ajv from 'ajv'

import PolicyEngineResponse from './schemas/IPolicyEnginePolicyResponse.json'
import PolicyEngineResponse from './schemas/IPolicyEnginePolicyResponse'

// Native modules are not currently supported with ES module imports.
// https://nodejs.org/api/esm.html#esm_no_native_module_loading
Expand Down
1 change: 0 additions & 1 deletion schemas/IPolicyEnginePolicyResponse.json

This file was deleted.

57 changes: 57 additions & 0 deletions schemas/IPolicyEnginePolicyResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export default {
"type": "object",
"properties": {
"reasons": {
"type": "array",
"items": {
"$ref": "#/definitions/IPolicyStatementResult"
}
},
"decision": {
"$ref": "#/definitions/PolicyDecision"
},
"errors": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"decision",
"errors",
"reasons"
],
"definitions": {
"IPolicyStatementResult": {
"type": "object",
"properties": {
"policy_id": {
"type": "string"
},
"invoked": {
"type": "boolean"
},
"annotations": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"required": [
"annotations",
"invoked",
"policy_id"
]
},
"PolicyDecision": {
"enum": [
"Allow",
"Deny"
],
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}
3 changes: 2 additions & 1 deletion scripts/compileSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const generate = async () => {
// Get symbols for different types from generator.
const schema = generator.getSchemaForSymbol(symbol)

writeFileSync(join(outputPath, `${symbol}.json`), JSON.stringify(schema))
writeFileSync(join(outputPath, `${symbol}.ts`), `export default ${JSON.stringify(schema, null, 2)}`)

}
}
generate()

0 comments on commit 0830805

Please sign in to comment.