Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 0d0c852

Browse files
author
Chris McConnell
authored
Chrimc/id (#739)
* Initial check-in. * Allof Working. * Move definitions local. * Launch to sdk. * Everything working for new merge. * schema: working * Working except that allof expansion does not expand local references. * Simplification and some analysis working. * Add extends. * Everything working. * Update help * Fix typo * Expand allOf and validate final schema. * Missing as warning and validate schema. * Update tests. * Update test to pass on server. * Normalize paths. * Check normalize for mac * Update for mac paths and lint. * Address review comments. * Update documentation and fix $id bugs. * Address review commehts * Fix bad merge.
1 parent c0edcb5 commit 0d0c852

File tree

6 files changed

+52
-73
lines changed

6 files changed

+52
-73
lines changed

packages/dialog/README.md

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ This package is intended for Microsoft use only and should be consumed through @
1111
# Commands
1212
<!-- commands -->
1313
* [`bf `](#bf-)
14-
* [`bf dialog:merge GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]`](#bf-dialogmerge-glob1-glob2-glob3-glob4-glob5-glob6-glob7-glob8-glob9)
15-
* [`bf dialog:verify GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]`](#bf-dialogverify-glob1-glob2-glob3-glob4-glob5-glob6-glob7-glob8-glob9)
14+
* [`bf dialog`](#bf-dialog)
15+
* [`bf dialog:merge PATTERNS`](#bf-dialogmerge-patterns)
16+
* [`bf dialog:verify PATTERNS`](#bf-dialogverify-patterns)
1617

1718
## `bf `
1819

@@ -26,89 +27,60 @@ OPTIONS
2627
-h, --help show CLI help
2728
```
2829

29-
_See code: [src/commands/index.ts](https://github.com/microsoft/botframework-cli/src/commands/index.ts)_
30+
_See code: [src\commands\index.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src\commands\index.ts)_
3031

31-
## `bf dialog:merge GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]`
32+
## `bf dialog`
3233

33-
```
34-
USAGE
35-
$ bf dialog:merge GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]
36-
37-
OPTIONS
38-
-b, --branch=branch [default: master] The branch to use for the meta-schema component.schema.
39-
-h, --help show CLI help
40-
-o, --output=output [default: app.schema] Output path and filename for merged schema. [default: app.schema]
41-
42-
-u, --update Update .schema files to point the <branch> component.schema and regenerate component.schema if
43-
baseComponent.schema is present.
44-
45-
--verbose output verbose logging of files as they are processed
46-
```
47-
48-
_See code: [src/commands/dialog/merge.ts](https://github.com/microsoft/botframework-cli/src/commands/dialog/merge.ts)_
49-
50-
## `bf dialog:verify GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]`
34+
Dialog related commands for working with .schema and .dialog files.
5135

5236
```
5337
USAGE
54-
$ bf dialog:verify GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]
38+
$ bf dialog
5539
5640
OPTIONS
57-
-h, --help show CLI help
58-
--verbose Show verbose output
41+
-h, --help Dialog command help
5942
```
6043

61-
_See code: [src/commands/dialog/verify.ts](https://github.com/microsoft/botframework-cli/src/commands/dialog/verify.ts)_
62-
<!-- commandsstop -->
63-
* [`bf dialog:merge [FILE]`](#bf-dialogmerge-file)
64-
* [`bf dialog:verify [FILE]`](#bf-dialogverify-file)
65-
66-
## `bf dialog:merge [FILE]`
44+
_See code: [src\commands\dialog\index.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src\commands\dialog\index.ts)_
6745

68-
The bf dialog:merge creates an merged schema file which represents merging of all of the component
69-
schemas and the SDK schemas together into an application .schema file.
46+
## `bf dialog:merge PATTERNS`
7047

71-
The file pattern can be an arbitrary GLOB patterns for finding .schema files (such as myfolder/**/*.schema), but
72-
the better way to use it is to invoke it in the folder that has a project in it (either .csproj or packages.json).
73-
In that case the project file will be analyzed for all dependent folders and .schema files will be merged to create
74-
the app.schema for the project.
48+
Merge component .schema files into an app.schema.
7549

7650
```
7751
USAGE
78-
$ bf dialog:merge GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]
52+
$ bf dialog:merge PATTERNS
53+
54+
ARGUMENTS
55+
PATTERNS Any number of glob regex patterns to match .schema, .csproj, or package.json files.
7956
8057
OPTIONS
81-
-b, --branch=branch The branch to use for the meta-schema component.schema. [default: master]
82-
-h, --help show CLI help
83-
-o, --output=output Output path and filename for merged schema. [default: app.schema]
84-
-u, --update Update .schema files to point the <branch> component.schema and regenerate component.schema if baseComponent.schema is present.
85-
--verbose output verbose logging of files as they are processed
86-
```
58+
-h, --help show CLI help
59+
-o, --output=output [default: app.schema] Output path and filename for merged schema.
60+
-v, --verbose Show verbose logging of files as they are processed.
8761
88-
Example:
89-
```
90-
bf dialog:merge -o app.schema
62+
EXAMPLES
63+
$ bf dialog:merge *.csproj
64+
$ bf dialog:merge libraries/**/*.schema **/*.csproj -o app.schema
9165
```
9266

93-
_See code: [src/commands/dialog/merge.ts](https://github.com/microsoft/botframework-cli/blob/v0.0.0/src/commands/dialog/merge.ts)_
67+
_See code: [src\commands\dialog\merge.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src\commands\dialog\merge.ts)_
9468

95-
## `bf dialog:verify [FILE]`
69+
## `bf dialog:verify PATTERNS`
9670

97-
The dialog:verify command is used to validate that all of the .dialog file resources for a project are valid based on the
98-
applications app.schema file (see dialog:merge command).
71+
Verify .dialog files match their app.schema.
9972

10073
```
10174
USAGE
102-
$ bf dialog:verify GLOB1 [GLOB2] [GLOB3] [GLOB4] [GLOB5] [GLOB6] [GLOB7] [GLOB8] [GLOB9]
75+
$ bf dialog:verify PATTERNS
76+
77+
ARGUMENTS
78+
PATTERNS Any number of glob regex patterns to match .dialog files.
10379
10480
OPTIONS
10581
-h, --help show CLI help
10682
--verbose Show verbose output
10783
```
10884

109-
Example:
110-
```
111-
bf dialog:verify test/**/*.dialog
112-
```
113-
114-
_See code: [src/commands/dialog/verify.ts](https://github.com/microsoft/botframework-cli/blob/v0.0.0/src/commands/dialog/verify.ts)_
85+
_See code: [src\commands\dialog\verify.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src\commands\dialog\verify.ts)_
86+
<!-- commandsstop -->

packages/dialog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@oclif/plugin-help"
2525
]
2626
},
27-
"repository": "microsoft/botframework-cli",
27+
"repository": "https://github.com/microsoft/botframework-cli/tree/master/packages/dialog",
2828
"scripts": {
2929
"postpack": "rimraf oclif.manifest.json",
3030
"posttest": "tslint -p test -t stylish",

packages/dialog/src/commands/dialog/merge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class DialogMerge extends Command {
1818
static flags: flags.Input<any> = {
1919
debug: flags.boolean({ char: 'd', description: 'Generate debug files.', hidden: true, default: false}),
2020
help: flags.help({ char: 'h' }),
21-
output: flags.string({ char: 'o', description: 'Output path and filename for merged schema. [default: app.schema]', default: 'app.schema', required: false }),
21+
output: flags.string({ char: 'o', description: 'Output path and filename for merged schema.', default: 'app.schema', required: false }),
2222
verbose: flags.boolean({ char: 'v', description: 'Show verbose logging of files as they are processed.', default: false }),
2323
}
2424

packages/dialog/src/commands/dialog/readme.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22

33
## Merge
44

5-
Ths will merge together [Microsoft Bot Builder](https://github.com/Microsoft/BotBuilder) .schema JSON schema files into a single JSON schema file. You can point to the files either directly with a glob pattern or indirectly through a glob pattern that matches a package.json, packages.config or \*.csproj file. The .schema files should have a unique filename that is used to refer to that type using `$kind`. The .schema files can optionally include a `$schema: "https://raw.githubusercontent.com/Microsoft/botbuilder-tools/SchemaGen/packages/DialogSchema/src/dialogSchema.schema"` which defines the schema they are validated against. Within a schema definition you can use `$role:"implements(<kind>)` to project the type definition into interface types defined using `$role:"interface"` while merging. To refer to a type in a property, just use `"$kind":"<kind>"`. The merger combines all of the component .schema files into a single .schema file that has resolved all external `$ref`, merged `allOf` and connected together schemas through `$role` and `$kind`.
5+
This will merge together [Microsoft Bot Builder](https://github.com/Microsoft/BotBuilder) .schema JSON schema files into a single JSON schema file. You can point to the files either directly with a glob pattern or indirectly through a glob pattern that matches a package.json, packages.config or \*.csproj file. The .schema files should have a unique filename that is used to refer to that type using `$kind`. The .schema files should include a `$schema: "https://raw.githubusercontent.com/microsoft/botframework-sdk/master/schemas/component/component.schema"` which defines the schema they are validated against. You can access common definitions by using `$ref: "schema:#/definitions/stringExpression"` in a property definition. At the top-level in a component schema you can use `$role:"implements(<kind>)` to project the type definition into interface types defined using `$role:"interface"` while merging. To extend an existing .schema file use `$role: "extends(<kind>)"`. To refer to a type in a property, use `"$kind":"<kind>"` and the corresponding kind will be wired into your schema. The merger combines all of the component .schema files into a single .schema file that has resolved all external `$ref`, merged `allOf` and connected together schemas through `$role` and `$kind`.
66

7-
In addition to types you can also mark properties with a `$role` which will define the underlying type and restrictions. This is also useful information for UI tools to help you construct values. Roles include:
8-
9-
- `$role: "expression"` which marks a string property which is expected to contain an expression string.
10-
- `$role: "lg"` which marks a string property which is used for language generation and can refer to LG templates.
11-
- `$role: "memoryPath"` which marks a string property which is expected to contain a path in memory like `user.name`.
7+
You can also mark properties with a `$role: "expression"` to indicate to tooling that an expression is allowed for that property.
128

139
For example look at these files:
1410

1511
- [IRecognizer.schema](test/schemas/IRecognizer.schema) defines the place holder for `IRecognizer` including a default option which is a bare string.
1612
- [Recognizer.schema](test/schemas/Recognizer.schema) includes `$role:"implements(IRecognizer)"` which extends the `IRecognizer` definition when merged.
17-
- [root.schema](test/schemas/root.schema) is a schema file that includes `$kind:"IRecognizer"` in order to make use of the `IRecognizer` place holder.
18-
- [app.schema](test/examples/app.schema) was created by this tool shows how all of these definitions are merged together. In particular if you look at `IRecognizer` you will see the definition that includes a string, or the complete definition of `Recognizer`.
13+
- [root.schema](test/schemas/root.schema) is a schema file that includes `$kind:"IRecognizer"` in order to make use of the `IRecognizer` place holder. The `$role: []` ensures that this is available as a top-level object.
14+
- [app.schema](test/schemas/app.schema) was created by this tool shows how all of these definitions are merged together. In particular if you look at `IRecognizer` you will see the definition that includes a string, or the complete definition of `Recognizer`.
1915

2016
[root.dialog](test/examples/root.dialog) Shows how you could use the resulting schema to enter in JSON schema and get intellisense.
2117

2218
## Verify
2319

24-
The verify command will check .dialog files to ensure that they all meet the schema.
20+
The verify command will check .dialog files to ensure that they all meet their $schema.
2521

packages/dialog/src/library/schemaMerger.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export default class SchemaMerger {
194194
}
195195
let finalSchema: any = {
196196
$schema: this.metaSchemaId,
197-
$id: ppath.resolve(this.output),
197+
$id: `file:///${ppath.resolve(this.output).replace(/\\/g, '/')}#`,
198198
type: 'object',
199199
title: 'Component kinds',
200200
description: 'These are all of the kinds that can be created by the loader.',
@@ -208,6 +208,7 @@ export default class SchemaMerger {
208208
// Convert all remote references to local ones
209209
finalSchema = await parser.bundle(finalSchema as parser.JSONSchema, this.schemaProtocolResolver())
210210
finalSchema = this.expandAllOf(finalSchema)
211+
this.removeId(finalSchema)
211212
if (this.debug) {
212213
await fs.writeJSON(this.output + '.expanded', finalSchema, this.jsonOptions)
213214
}
@@ -758,6 +759,16 @@ export default class SchemaMerger {
758759
return allof(bundle)
759760
}
760761

762+
// Remove any child $id because their references have been changed to be local
763+
removeId(bundle: any) {
764+
walkJSON(bundle, (val, _obj, path) => {
765+
if (path && val.$id) {
766+
delete val.$id
767+
}
768+
return false
769+
})
770+
}
771+
761772
// Verify schema has title/description everywhere and interfaces exist.
762773
verifySchema(schema: any): void {
763774
this.log('Verifying schema')
@@ -766,7 +777,7 @@ export default class SchemaMerger {
766777
this.currentKind = entry.$ref.substring(entry.$ref.lastIndexOf('/') + 1)
767778
let definition = schema.definitions[this.currentKind]
768779
let verifyProperty = (val, path) => {
769-
if (!val.$id) {
780+
if (!val.$schema) {
770781
if (val.$ref) {
771782
val = clone(val)
772783
let ref = ptr.get(schema, val.$ref)
@@ -804,7 +815,7 @@ export default class SchemaMerger {
804815
}
805816
}
806817
walkJSON(definition, (val, _, path) => {
807-
if (val.$id && path) {
818+
if (val.$schema && path) {
808819
return true
809820
}
810821
if (val.properties && !path?.endsWith('properties')) {

packages/dialog/test/commands/dialog/schemas/app.schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/microsoft/botframework-sdk/master/schemas/component/component.schema",
3-
"$id": "C:\\Users\\chrim\\source\\repos\\botframework-cli\\packages\\dialog\\test\\commands\\dialog\\schemas\\app.schema",
3+
"$id": "file:///C:/Users/chrim/source/repos/botframework-cli/packages/dialog/test/commands/dialog/schemas/app.schema#",
44
"type": "object",
55
"title": "Component kinds",
66
"description": "These are all of the kinds that can be created by the loader.",

0 commit comments

Comments
 (0)