Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const rootNode = new PolymorphicTree(name)
const definitions = this.specInJson.definitions as DefinitionsObject
// Adding the model name or it's discriminator value as an enum constraint with one value
// (constant) on property marked as discriminator
const definition = definitions[name]
if (definition && definition.properties) {
// all derived types should have `"type": "object"`.
// otherwise it may pass validation for other types, such as `string`.
// see also https://github.com/Azure/oav/issues/390
definition.type = "object"
const d = definition.properties[discriminator]
if (d) {
const required = definition.required
if (!isArray(required)) {
definition.required = [discriminator]
} else if (required.find(v => v === discriminator) === undefined) {
definition.required = [...required, discriminator]
}
const val = definition["x-ms-discriminator-value"] || name
// Ensure that the property marked as a discriminator has only one value in the enum
// constraint for that model and it
// should be the one that is the model name or the value indicated by
// x-ms-discriminator-value. This will make the discriminator
// property a constant (in json schema terms).
if (d.$ref) {
delete d.$ref
}
const xMsEnum = d["x-ms-enum"]
if (xMsEnum !== undefined) {
// if modelAsString is set to `true` then validator will always succeeded on any string.
export const getSuppressions = async (specPath: string): Promise => {
// find readme.md
try {
const readMe = await amd.findReadMe(path.dirname(specPath))
if (readMe === undefined) {
return undefined
}
const readMeStr = await vfs.readFile(readMe)
const cmd = md.parse(readMeStr)
const suppressionCodeBlock = amd.getCodeBlocksAndHeadings(cmd.markDown).Suppression
if (suppressionCodeBlock === undefined) {
return undefined
}
const suppression = amd.getYamlFromNode(suppressionCodeBlock) as amd.Suppression
if (!it.isArray(suppression.directive)) {
return undefined
}
return suppression
} catch (err) {
log.warn(`Unable to load and parse suppression file. Error: ${err}`)
return undefined
}
}
if (f.base === "readme.enable-multi-api.md") {
foundMultiApiReadmes = true;
const content = (await fs.readFile(file)).toString();
const readMe = cm.parse(content);
const set = new Set();
for (const c of cm.iterate(readMe.markDown)) {
if (
c.type === "code_block" &&
c.info !== null &&
c.info.startsWith("yaml") &&
c.literal !== null
) {
const y = (yaml.load(c.literal) as Code)["input-file"];
if (typeof y === "string") {
set.add(y.replace('$(this-folder)', ''));
} else if (it.isArray(y)) {
for (const i of y) {
let cleanFilePath = i.replace('$(this-folder)', '');
set.add(cleanFilePath);
specs.push(Path.join(f.dir, cleanFilePath));
}
}
}
}
}
}
if (!foundMultiApiReadmes){
throw `Couldn't find any readme.enable-multi-api.md files.`
}
const allPaths = await getPaths(specs);
if (f.base === "readme.md") {
console.log(`processing ${file}`)
const content = (await fs.readFile(file)).toString()
const readMe = cm.parse(content)
const set = new Set()
for (const c of cm.iterate(readMe.markDown)) {
if (
c.type === "code_block" &&
c.info !== null &&
c.info.startsWith("yaml") &&
c.literal !== null
) {
const y = (yaml.load(c.literal) as Code)["input-file"]
if (typeof y === "string") {
set.add(y)
} else if (it.isArray(y)) {
for (const i of y) {
set.add(i)
}
}
}
}
const readMeMulti = cm.createNode(
"document",
cm.createNode(
"heading",
cm.createText("Multi-API support for AutoRest v3 generators")
),
cm.createNode(
"block_quote",
cm.createNode(
"paragraph",
try {
const titleObject: TitleObject | undefined = JSON.parse(title)
setPositionAndUrl(error, titleObject)
} catch {
log.error(`ICE: can't parse title: ${title}`)
}
}
const json = error[jsonSymbol]
if (error.jsonPosition === undefined && json !== undefined) {
const jsonInfo = getInfo(json)
if (jsonInfo !== undefined) {
const errorPathOriginal = error.path
const errorPath =
errorPathOriginal === undefined
? undefined
: isArray(errorPathOriginal)
? errorPathOriginal
: errorPathOriginal.split("/")
setMutableProperty(error, "jsonPosition", getDescendantFilePosition(json, errorPath))
error.directives = merge(error.directives, getAllDirectives(json, errorPath))
error.jsonUrl = getRootObjectInfo(jsonInfo).url
}
}
delete (error as any)[jsonSymbol]
delete (error as any)[schemaSymbol]
return error
}