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

Commit d2e756a

Browse files
author
Chris McConnell
authored
Remove $id from schema:merge and enable authoringKey in luis:build (#744)
* Remove $id from schema:merge. Enable authoringKey config to work for luis:build. * Fix case issue in test.
1 parent b91b3a8 commit d2e756a

File tree

12 files changed

+73
-64
lines changed

12 files changed

+73
-64
lines changed

.vscode/launch.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "bf CLI",
11+
"preLaunchTask": "${defaultBuildTask}",
12+
"program": "${workspaceFolder}/packages/cli/bin/run",
13+
"outputCapture": "std",
14+
"outFiles": [
15+
"${workspaceFolder}/packages/luis/lib/**"
16+
],
17+
"args": [
18+
"luis:build",
19+
"--luConfig",
20+
"${env:TEMP}/sandwich.out/luconfig.json"
21+
],
22+
"internalConsoleOptions": "openOnSessionStart",
23+
"cwd": "${workspaceFolder}"
24+
},
725
{
826
"type": "node",
927
"request": "launch",
@@ -198,9 +216,7 @@
198216
"--in",
199217
".",
200218
"--luConfig",
201-
"luconfig.json",
202-
"--authoringKey",
203-
"${env:LUIS_AUTHORING_KEY}"
219+
"luconfig.json"
204220
],
205221
"internalConsoleOptions": "openOnSessionStart",
206222
"cwd": "${env:TEMP}/sandwich.out"

common/config/rush/pnpm-lock.yaml

Lines changed: 3 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"module": "commonjs",
66
"outDir": "lib",
77
"rootDir": "src",
8+
"sourceMap": true,
89
"strict": true,
910
"target": "es2017",
1011
"composite": true

packages/dialog/src/library/schemaMerger.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default class SchemaMerger {
7272
private readonly missingKinds = new Set()
7373
private currentFile = ''
7474
private currentKind = ''
75-
private readonly jsonOptions = { spaces: '\t', EOL: os.EOL }
75+
private readonly jsonOptions = {spaces: '\t', EOL: os.EOL}
7676

7777
/**
7878
* Merger to combine copmonent .schema files to make a custom schema.
@@ -128,8 +128,8 @@ export default class SchemaMerger {
128128
this.log(`Parsing ${componentPath}`)
129129
}
130130
let component = await fs.readJSON(componentPath)
131-
if (component.$id) {
132-
this.parsingWarning(`Skipping because of top-level $id ${component.$id}`)
131+
if (component.definitions && component.definitions.component) {
132+
this.parsingWarning('Skipping merged schema')
133133
} else {
134134
this.relativeToAbsoluteRefs(component, componentPath)
135135

@@ -181,7 +181,7 @@ export default class SchemaMerger {
181181
.filter(kind => !this.isInterface(kind) && this.definitions[kind].$role)
182182
.sort()
183183
.map(kind => {
184-
return { $ref: `#/definitions/${kind}` }
184+
return {$ref: `#/definitions/${kind}`}
185185
})
186186
this.addSchemaDefinitions()
187187

@@ -194,7 +194,6 @@ export default class SchemaMerger {
194194
}
195195
let finalSchema: any = {
196196
$schema: this.metaSchemaId,
197-
$id: `file:///${ppath.resolve(this.output).replace(/\\/g, '/')}#`,
198197
type: 'object',
199198
title: 'Component kinds',
200199
description: 'These are all of the kinds that can be created by the loader.',
@@ -423,7 +422,7 @@ export default class SchemaMerger {
423422
async findGlobalNuget(): Promise<string> {
424423
let result = ''
425424
try {
426-
const { stdout } = await exec('dotnet nuget locals global-packages --list')
425+
const {stdout} = await exec('dotnet nuget locals global-packages --list')
427426
const name = 'global-packages:'
428427
let start = stdout.indexOf(name)
429428
if (start > -1) {
@@ -524,7 +523,7 @@ export default class SchemaMerger {
524523

525524
if (extension.patternProperties) {
526525
if (definition.patternProperties) {
527-
definition.patternPropties = { ...definition.patternProperties, ...extension.patternProperties }
526+
definition.patternPropties = {...definition.patternProperties, ...extension.patternProperties}
528527
} else {
529528
definition.patternProperties = clone(extension.patternProperties)
530529
}
@@ -666,7 +665,7 @@ export default class SchemaMerger {
666665
expandKinds(): void {
667666
for (this.currentKind in this.definitions) {
668667
walkJSON(this.definitions[this.currentKind], val => {
669-
if (val.$kind) {
668+
if (val.$kind && typeof val.$kind === 'string') {
670669
if (this.definitions.hasOwnProperty(val.$kind)) {
671670
val.$ref = '#/definitions/' + val.$kind
672671
} else {
@@ -727,7 +726,7 @@ export default class SchemaMerger {
727726
// Add schema definitions and turn schema: or full definition URI into local reference
728727
addSchemaDefinitions(): void {
729728
const scheme = 'schema:'
730-
this.definitions = { ...this.metaSchema.definitions, ...this.definitions }
729+
this.definitions = {...this.metaSchema.definitions, ...this.definitions}
731730
for (this.currentKind in this.definitions) {
732731
walkJSON(this.definitions[this.currentKind], val => {
733732
if (typeof val === 'object' && val.$ref && (val.$ref.startsWith(scheme) || val.$ref.startsWith(this.metaSchemaId))) {
@@ -761,8 +760,8 @@ export default class SchemaMerger {
761760

762761
// Remove any child $id because their references have been changed to be local
763762
removeId(bundle: any) {
764-
walkJSON(bundle, (val, _obj, path) => {
765-
if (path && val.$id) {
763+
walkJSON(bundle, val => {
764+
if (val.$id) {
766765
delete val.$id
767766
}
768767
return false

packages/dialog/test/commands/dialog/merge.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ describe('dialog:merge', async () => {
6969
assert(countMatches(/error|warning/i, lines) == 1, 'Error merging schemas')
7070
let oracle = await fs.readJSON('schemas/app.schema')
7171
let generated = await fs.readJSON('generated.schema')
72-
delete oracle.$id
73-
delete generated.$id
7472
let oracles = JSON.stringify(oracle)
7573
let generateds = JSON.stringify(generated)
7674
if (oracles !== generateds) {

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

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

packages/luis/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@
6464
"@types/lodash": "~4.14.146",
6565
"@types/mocha": "^5.2.7",
6666
"@types/node": "^10.17.4",
67+
"@types/nock": "^11.1.0",
6768
"@types/rimraf": "^2.0.3",
6869
"chai": "^4.2.0",
6970
"globby": "^10.0.1",
7071
"mocha": "^6.2.2",
72+
"nock": "^11.7.0",
7173
"nyc": "^14.1.1",
7274
"rimraf": "^3.0.0",
7375
"sinon": "^7.5.0",
@@ -76,4 +78,4 @@
7678
"typescript": "^3.5.3",
7779
"uuid": "^3.3.3"
7880
}
79-
}
81+
}

packages/luis/src/commands/luis/build.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ export default class LuisBuild extends Command {
4646
async run() {
4747
try {
4848
const {flags} = this.parse(LuisBuild)
49-
const userConfig = await utils.getUserConfig(this.config.configDir)
50-
51-
flags.stdin = await this.readStdin()
5249

50+
// Luconfig overrides flags
5351
let files: string[] = []
5452
if (flags.luConfig) {
5553
const configFilePath = path.resolve(flags.luConfig)
@@ -67,32 +65,36 @@ export default class LuisBuild extends Command {
6765
}
6866
}
6967

70-
if (!flags.stdin && !flags.in && files.length === 0) {
68+
// Flags override userConfig
69+
let {inVal, authoringKey, botName, region, out, defaultCulture, fallbackLocale, suffix, dialog, force, luConfig, deleteOldVersion, log}
70+
= await utils.processInputs(flags, Object.keys(LuisBuild.flags), this.config.configDir)
71+
72+
flags.stdin = await this.readStdin()
73+
74+
if (!flags.stdin && !inVal && files.length === 0) {
7175
throw new CLIError('Missing input. Please use stdin or pass a file or folder location with --in flag')
7276
}
7377

74-
if (!flags.authoringKey && (!userConfig || !userConfig.authoringKey)) {
75-
throw new CLIError('Missing luis authoring key. Please pass authoring key with --authoringKey flag')
76-
} else {
77-
flags.authoringKey = flags.authoringKey || userConfig.authoringKey
78+
if (!authoringKey) {
79+
throw new CLIError('Missing LUIS authoring key. Please pass authoring key with --authoringKey flag or specify via bf config:set:luis.')
7880
}
7981

80-
if (!flags.botName) {
81-
throw new CLIError('Missing bot name. Please pass bot name with --botName flag')
82+
if (!botName) {
83+
throw new CLIError('Missing bot name. Please pass bot name with --botName flag.')
8284
}
8385

84-
if (flags.dialog && flags.dialog !== recognizerType.MULTILANGUAGE && flags.dialog !== recognizerType.CROSSTRAINED) {
85-
throw new CLIError('Recognizer type specified by --dialog is not right. Please specify [multiLanguage|crosstrained]')
86+
if (dialog && dialog !== recognizerType.MULTILANGUAGE && dialog !== recognizerType.CROSSTRAINED) {
87+
throw new CLIError('Recognizer type specified by --dialog is not right. Please specify [multiLanguage|crosstrained].')
8688
}
8789

88-
flags.defaultCulture = flags.defaultCulture && flags.defaultCulture !== '' ? flags.defaultCulture : 'en-us'
89-
flags.region = flags.region && flags.region !== '' ? flags.region : 'westus'
90-
flags.suffix = flags.suffix && flags.suffix !== '' ? flags.suffix : await username() || 'development'
91-
flags.fallbackLocale = flags.fallbackLocale && flags.fallbackLocale !== '' ? flags.fallbackLocale : 'en-us'
90+
defaultCulture = defaultCulture && defaultCulture !== '' ? defaultCulture : 'en-us'
91+
region = region && region !== '' ? region : 'westus'
92+
suffix = suffix && suffix !== '' ? suffix : await username() || 'development'
93+
fallbackLocale = fallbackLocale && fallbackLocale !== '' ? fallbackLocale : 'en-us'
9294

9395
// create builder class
9496
const builder = new Builder((input: string) => {
95-
if (flags.log) this.log(input)
97+
if (log) this.log(input)
9698
})
9799

98100
let luContents: any[] = []
@@ -102,19 +104,19 @@ export default class LuisBuild extends Command {
102104

103105
if (flags.stdin && flags.stdin !== '') {
104106
// load lu content from stdin and create default recognizer, multiRecognier and settings
105-
if (flags.log) this.log('Load lu content from stdin\n')
106-
const content = new Content(flags.stdin, new LUOptions('stdin', true, flags.defaultCulture, path.join(process.cwd(), 'stdin')))
107+
if (log) this.log('Load lu content from stdin\n')
108+
const content = new Content(flags.stdin, new LUOptions('stdin', true, defaultCulture, path.join(process.cwd(), 'stdin')))
107109
luContents.push(content)
108110
multiRecognizers.set('stdin', new MultiLanguageRecognizer(path.join(process.cwd(), 'stdin.lu.dialog'), {}))
109-
settings.set('stdin', new Settings(path.join(process.cwd(), `luis.settings.${flags.suffix}.${flags.region}.json`), {}))
111+
settings.set('stdin', new Settings(path.join(process.cwd(), `luis.settings.${suffix}.${region}.json`), {}))
110112
const recognizer = Recognizer.load(content.path, content.name, path.join(process.cwd(), `${content.name}.dialog`), settings.get('stdin'), {})
111113
recognizers.set(content.name, recognizer)
112114
} else {
113-
if (flags.log) this.log('Loading files...\n')
115+
if (log) this.log('Loading files...\n')
114116

115-
// get lu files from flags.in.
116-
if (flags.in && flags.in !== '') {
117-
const luFiles = await file.getLuFiles(flags.in, true, fileExtEnum.LUFile)
117+
// get lu files from in.
118+
if (inVal && inVal !== '') {
119+
const luFiles = await file.getLuFiles(inVal, true, fileExtEnum.LUFile)
118120
files.push(...luFiles)
119121
}
120122

@@ -123,22 +125,22 @@ export default class LuisBuild extends Command {
123125

124126
// load lu contents from lu files
125127
// load existing recognizers, multiRecogniers and settings or create default ones
126-
const loadedResources = await builder.loadContents(files, flags.defaultCulture, flags.suffix, flags.region)
128+
const loadedResources = await builder.loadContents(files, defaultCulture, suffix, region)
127129
luContents = loadedResources.luContents
128130
recognizers = loadedResources.recognizers
129131
multiRecognizers = loadedResources.multiRecognizers
130132
settings = loadedResources.settings
131133
}
132134

133135
// update or create and then train and publish luis applications based on loaded resources
134-
if (flags.log) this.log('Handling applications...')
135-
const dialogContents = await builder.build(luContents, recognizers, flags.authoringKey, flags.region, flags.botName, flags.suffix, flags.fallbackLocale, flags.deleteOldVersion, multiRecognizers, settings)
136+
if (log) this.log('Handling applications...')
137+
const dialogContents = await builder.build(luContents, recognizers, authoringKey, region, botName, flags.suffix, fallbackLocale, deleteOldVersion, multiRecognizers, settings)
136138

137139
// write dialog assets based on config
138-
if (flags.dialog) {
139-
const writeDone = await builder.writeDialogAssets(dialogContents, flags.force, flags.out, flags.dialog, flags.luConfig)
140-
const dialogFilePath = (flags.stdin || !flags.in) ? process.cwd() : flags.in.endsWith(fileExtEnum.LUFile) ? path.dirname(path.resolve(flags.in)) : path.resolve(flags.in)
141-
const outputFolder = flags.out ? path.resolve(flags.out) : dialogFilePath
140+
if (dialog) {
141+
const writeDone = await builder.writeDialogAssets(dialogContents, force, out, dialog, luConfig)
142+
const dialogFilePath = (flags.stdin || !inVal) ? process.cwd() : inVal.endsWith(fileExtEnum.LUFile) ? path.dirname(path.resolve(inVal)) : path.resolve(inVal)
143+
const outputFolder = out ? path.resolve(out) : dialogFilePath
142144
if (writeDone) {
143145
this.log(`Successfully wrote .dialog files to ${outputFolder}\n`)
144146
} else {

packages/luis/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const isDirectory = (path: string): boolean => {
7070
}
7171

7272
const filterByAllowedConfigValues = (configObj: any, prefix: string) => {
73-
const allowedConfigValues = [`${prefix}appId`, `${prefix}endpoint`, `${prefix}region`, `${prefix}subscriptionKey`, `${prefix}versionId`]
73+
const allowedConfigValues = [`${prefix}appId`, `${prefix}endpoint`, `${prefix}region`, `${prefix}subscriptionKey`, `${prefix}versionId`, `${prefix}authoringKey`]
7474
const filtered = Object.keys(configObj)
7575
.filter(key => allowedConfigValues.includes(key))
7676
.reduce((filteredConfigObj: any, key) => {

packages/luis/test/commands/luis/build.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('luis:build cli parameters test', () => {
2626
.stderr()
2727
.command(['luis:build', '--in', `${path.join(__dirname, './../../fixtures/testcases/lubuild')}`, '--botName', 'Contoso'])
2828
.it('displays an error if any required input parameters are missing', ctx => {
29-
expect(ctx.stderr).to.contain('Missing luis authoring key. Please pass authoring key with --authoringKey flag')
29+
expect(ctx.stderr).to.contain('Missing LUIS authoring key. Please pass authoring key with --authoringKey flag')
3030
})
3131

3232
test

0 commit comments

Comments
 (0)