Skip to content

Commit

Permalink
fix: flattened $defs in JSON schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoverson committed Sep 11, 2023
1 parent 4d6e3f4 commit 6626351
Show file tree
Hide file tree
Showing 23 changed files with 5,254 additions and 5,648 deletions.
12 changes: 6 additions & 6 deletions crates/wick/wick-config/definitions/json-schema.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"type": "object",
"$defs": {},
"oneOf": [
{ "$ref": "#/$defs/v1/AppConfiguration" },
{ "$ref": "#/$defs/v1/ComponentConfiguration" },
{ "$ref": "#/$defs/v1/TypesConfiguration" },
{ "$ref": "#/$defs/v1/TestConfiguration" },
{ "$ref": "#/$defs/v1/LockdownConfiguration" },
{ "$ref": "#/$defs/v0/HostManifest" }
{ "$ref": "#/$defs/v1.AppConfiguration" },
{ "$ref": "#/$defs/v1.ComponentConfiguration" },
{ "$ref": "#/$defs/v1.TypesConfiguration" },
{ "$ref": "#/$defs/v1.TestConfiguration" },
{ "$ref": "#/$defs/v1.LockdownConfiguration" },
{ "$ref": "#/$defs/v0.HostManifest" }
]
}
8 changes: 4 additions & 4 deletions crates/wick/wick-config/definitions/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const inner_json = imports.map((path) =>

let template_json = JSON.parse(readFileSync(template_path, 'utf-8'));

for (const json of inner_json) {
for (const [key, value] of Object.entries(json)) {
template_json['$defs'][key] = value;
}
let entries = inner_json.flatMap((json) => Object.entries(json));

for (const [key, value] of entries) {
template_json['$defs'][key] = value;
}

console.log(JSON.stringify(template_json, null, 2));
15 changes: 0 additions & 15 deletions crates/wick/wick-config/definitions/v0/manifest.apex
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,13 @@ type NetworkManifest {
"The unique identifier for this Network."
name: string?,

"The collection to use as the entrypoint when running as a standalone process."
triggers: EntrypointDefinition?,

"The links between capabilities and components."
schematics: [SchematicManifest],

"A list of component collections."
collections: [CollectionDefinition],
}

"A collection definition for the main entrypoint."
type EntrypointDefinition {
"The reference/location of the collection."
reference: string,

"The component to use as the entrypoint."
component: string,

"Data or configuration used to initialize the collection."
data: {string: any}?,
}

"A collection definition."
type CollectionDefinition {
"The local namespace for the collection."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

{
"v0": {
{{~#each definitions~}}
{{~#switch kind~}}
{{#case "TypeDefinition"}}{{> schema-definition-type}}{{/case}}
Expand All @@ -15,6 +14,5 @@
{{~/default~}}
{{~/switch~}}
{{~/each~}}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,43 @@
{{#case "ListType"}}
"type":"array",
"items": {
{{#withType type}}
{{#withAnnotation "shortform" ~}}
"oneOf" : [
{ "type":"string" },
{{#with "{"}}{{.}}{{/with}}
{{~/withAnnotation}}
{{/withType}}
{{> expand-type type }}
{{#withType type}}
{{#withAnnotation "shortform" ~}}
{{#with "}"}}{{.}}{{/with}}
]
{{~/withAnnotation}}
{{/withType}}
}
{{/case}}
{{#case "Optional"}}
"required" : false,
{{> expand-type type }}
{{#ifCond type.name.value "==" "ConnectionTargetDefinition"}}
#[serde(deserialize_with = "connection_target_shortform")]
{{/ifCond}}
{{/case}}
{{#case "Named"~}}
{{#switch name.value~}}
{{#case "any"}}"oneOf": [{"type":"boolean"},{"type":"object"},{"type":"array"},{"type":"string"},{"type":"number"}]{{/case}}
{{#case "any"}}{{/case}}
{{#case "LocationReference"}}"type":"string"{{/case}}
{{#case "Glob"}}"type":"string"{{/case}}
{{#case "string"}}"type":"string"{{/case}}
{{#case "i8"}}"type":"number"{{/case}}
{{#case "u8"}}"type":"number"{{/case}}
{{#case "i16"}}"type":"number"{{/case}}
{{#case "u16"}}"type":"number"{{/case}}
{{#case "i32"}}"type":"number"{{/case}}
{{#case "u32"}}"type":"number"{{/case}}
{{#case "i64"}}"type":"number"{{/case}}
{{#case "u64"}}"type":"number"{{/case}}
{{#case "f32"}}"type":"number"{{/case}}
{{#case "f64"}}"type":"number"{{/case}}
{{#case "i8"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "u8"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "i16"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "u16"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "i32"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "u32"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "i64"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "u64"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "f32"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "f64"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "bool"}}"type":"boolean"{{/case}}
{{#default}}"$ref":"#/$defs/v0/{{name.value}}"{{/default}}
{{#default}}"$ref":"#/$defs/v0.{{name.value}}"{{/default}}
{{~/switch}}
{{~/case}}
{{~/switch}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"{{name.value}}": {
"$anchor": "#v0/{{name.value}}",
"v0.{{name.value}}": {
"$anchor": "v0.{{name.value}}",
"enum" : [
{{#join values "," ~}}
"{{name.value}}"
"{{ pascalCase name.value}}"
{{~/join}}
]
},
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
"{{name.value}}": {
"$anchor": "#v0/{{name.value}}",
{{#withAnnotation "nameonly"}}
"v0.{{../name.value}}": {
"$anchor": "v0.{{../name.value}}",
"additionalProperties": false,
"type":"string",
{{#if arguments.0.value.value}}
"enum": ["{{arguments.0.value.value}}"]
{{else}}
"enum": ["{{../name.value}}"]
{{/if}}
},
{{else}}
"v0.{{name.value}}": {
"$anchor": "v0.{{name.value}}",
"additionalProperties": false,
"type":"object",
"properties": {
{{#withAnnotation "tagged"}}
{{#ifCond name.value '===' 'tagged'}}
"kind": {
"type": "string",
"description": "The kind of the collection",
"enum": ["{{arguments.0.value.value}}"]
},
{{/ifCond}}
{{/withAnnotation}}
{{#join fields "," ~}}
"{{name.value}}" : {
{{#if description}}
Expand All @@ -10,7 +32,16 @@
{{#withAnnotation "discriminant"}}
"enum": [{{arguments.0.value.value}}]
{{else}}
{{> expand-type type }}
{{#withAnnotation "shortform" ~}}
"oneOf" : [
{ "type":"string" },
{{#with "{"}}{{.}}{{/with}}
{{~/withAnnotation}}
{{> expand-type type }}
{{#withAnnotation "shortform" ~}}
{{#with "}"}}{{.}}{{/with}}
]
{{~/withAnnotation}}
{{/withAnnotation}}
}
{{~/join}}
Expand All @@ -21,3 +52,4 @@
{{~/each~}}
]
},
{{/withAnnotation}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"v1": {
{{#each definitions}}
{{#switch kind}}
{{~#case "ImportDefinition"}}
Expand All @@ -16,5 +15,4 @@
{{/default}}
{{/switch}}
{{/each}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{{#case "f32"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "f64"}}"oneOf" : [{"type":"number"},{"type":"string"}]{{/case}}
{{#case "bool"}}"type":"boolean"{{/case}}
{{#default}}"$ref":"#/$defs/v1/{{name.value}}"{{/default}}
{{#default}}"$ref":"#/$defs/v1.{{name.value}}"{{/default}}
{{~/switch}}
{{~/case}}
{{~/switch}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"{{name.value}}": {
"v1.{{name.value}}": {
{{#switch name.value~}}
{{#case "LiquidJsonValue"}}"oneOf": [{"type":"boolean"},{"type":"object"},{"type":"array"},{"type":"string"},{"type":"number"}]{{/case}}
{{#default}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"{{name.value}}": {
"$anchor": "#v1/{{name.value}}",
"v1.{{name.value}}": {
"$anchor": "v1.{{name.value}}",
"enum" : [
{{#join values "," ~}}
"{{ pascalCase name.value}}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{{#withAnnotation "nameonly"}}
"{{../name.value}}": {
"$anchor": "#v1/{{../name.value}}",
"v1.{{../name.value}}": {
"$anchor": "v1.{{../name.value}}",
"additionalProperties": false,
"type":"string",
{{#if arguments.0.value.value}}
Expand All @@ -11,8 +11,8 @@
{{/if}}
},
{{else}}
"{{name.value}}": {
"$anchor": "#v1/{{name.value}}",
"v1.{{name.value}}": {
"$anchor": "v1.{{name.value}}",
"additionalProperties": false,
"type":"object",
"properties": {
Expand All @@ -30,9 +30,6 @@
{{#if description}}
"description": "{{description.value}}",
{{/if}}
{{#ifCond type.kind "===" "Optional"}}
"required" : false,
{{/ifCond}}
{{#withAnnotation "discriminant"}}
"enum": [{{arguments.0.value.value}}]
{{else}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"{{name.value}}": {
"v1.{{name.value}}": {
"oneOf" : [
{{#withAnnotation "shortform" ~}}
{ "type":"string" },
{{~/withAnnotation}}
{{#unlessAnnotation "shortformonly"}}
{{#join types "," ~}}
{"$ref": "#/$defs/v1/{{name.value}}"}
{"$ref": "#/$defs/v1.{{name.value}}"}
{{~/join}}
{{/unlessAnnotation}}
]
Expand Down
19 changes: 0 additions & 19 deletions crates/wick/wick-config/docs/v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,11 @@ aliases:
| Field name | Type | Description | Required? | Shortform? |
|------------|------|-------------|-----------|------------|
| `name` | <code>`string`</code> |The unique identifier for this Network.|||
| `triggers` | <code>[`EntrypointDefinition`](#entrypointdefinition)</code> |The collection to use as the entrypoint when running as a standalone process.|||
| `schematics` | <code>[`SchematicManifest`](#schematicmanifest)[]</code> |The links between capabilities and components.|||
| `collections` | <code>[`CollectionDefinition`](#collectiondefinition)[]</code> |A list of component collections.|||



--------

## EntrypointDefinition

<p>
<div style="font-style:italic">A collection definition for the main entrypoint.</div>
</p>



| Field name | Type | Description | Required? | Shortform? |
|------------|------|-------------|-----------|------------|
| `reference` | <code>`string`</code> |The reference/location of the collection.|||
| `component` | <code>`string`</code> |The component to use as the entrypoint.|||
| `data` | <code>`{` `string` `: ` `any` `}`</code> |Data or configuration used to initialize the collection.|||



--------

## CollectionDefinition
Expand Down
Loading

0 comments on commit 6626351

Please sign in to comment.