* replace `findReadMe` file.

* get suppressions from HTTPS

* changelog
This commit is contained in:
Sergey Shandar 2018-10-08 12:27:16 -07:00 коммит произвёл GitHub
Родитель eca7ad99f5
Коммит 9f268206fe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 448 добавлений и 1722 удалений

Просмотреть файл

@ -1,5 +1,9 @@
# Changelog
### 10/08/2018 0.7.5
- Get suppressions from HTTPS.
### 10/03/2018 0.7.4
- Fix `@ts-common/source-map` `.d.ts` files.

Просмотреть файл

@ -146,7 +146,7 @@ export async function validateCompositeSpec(
compositeSpecPath: string, options: Options
): Promise<ReadonlyArray<SpecValidationResult>> {
return validate(options, async o => {
const suppression = getSuppressions(compositeSpecPath)
const suppression = await getSuppressions(compositeSpecPath)
const docs = await getDocumentsFromCompositeSwagger(suppression, compositeSpecPath)
o.consoleLogLevel = log.consoleLogLevel
o.logFilepath = log.filepath
@ -185,7 +185,7 @@ export async function validateExamplesInCompositeSpec(
return await validate(options, async o => {
o.consoleLogLevel = log.consoleLogLevel
o.logFilepath = log.filepath
const suppression = getSuppressions(compositeSpecPath)
const suppression = await getSuppressions(compositeSpecPath)
const docs = await getDocumentsFromCompositeSwagger(suppression, compositeSpecPath)
const promiseFactories = docs.map(
doc => async () => await validateExamples(doc, undefined, o))
@ -202,7 +202,7 @@ export async function resolveSpec(
log.filepath = options.logFilepath || log.filepath
const specFileName = path.basename(specPath)
try {
const suppression = getSuppressions(specPath)
const suppression = await getSuppressions(specPath)
const result = await utils.parseJson(suppression, specPath)
const resolver = new SpecResolver(specPath, result, options)
await resolver.resolve(suppression);
@ -228,7 +228,7 @@ export async function resolveCompositeSpec(
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel
log.filepath = options.logFilepath || log.filepath
try {
const suppression = getSuppressions(specPath)
const suppression = await getSuppressions(specPath)
const docs = await getDocumentsFromCompositeSwagger(suppression, specPath)
options.consoleLogLevel = log.consoleLogLevel
options.logFilepath = log.filepath
@ -270,7 +270,7 @@ export async function generateWireFormatInCompositeSpec(
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel
log.filepath = options.logFilepath || log.filepath
try {
const suppression = getSuppressions(compositeSpecPath)
const suppression = await getSuppressions(compositeSpecPath)
const docs = await getDocumentsFromCompositeSwagger(suppression, compositeSpecPath)
options.consoleLogLevel = log.consoleLogLevel
options.logFilepath = log.filepath
@ -302,7 +302,7 @@ export async function generateUml(
shouldResolveNullableTypes: false
}
try {
const suppression = getSuppressions(specPath)
const suppression = await getSuppressions(specPath)
const result = await utils.parseJson(suppression, specPath)
const resolver = new SpecResolver(specPath, result, resolverOptions)
const umlGenerator = new umlGeneratorLib.UmlGenerator(resolver.specInJson, options)

Просмотреть файл

@ -168,7 +168,7 @@ export class SpecValidator<T extends CommonValidationResult> {
try {
let suppression: amd.Suppression | undefined
if (this.specInJson === undefined || this.specInJson === null) {
suppression = getSuppressions(this.specPath)
suppression = await getSuppressions(this.specPath)
const result = await utils.parseJson(suppression, this.specPath)
this.specInJson = result
}

Просмотреть файл

@ -5,15 +5,34 @@ import * as path from "path"
import * as fs from "fs"
import * as md from "@ts-common/commonmark-to-markdown"
import * as amd from "@ts-common/azure-openapi-markdown"
import { isArray } from '@ts-common/iterator';
import { isArray } from "@ts-common/iterator"
import { findReadMe, urlParse } from "@ts-common/azure-openapi-markdown"
export const getSuppressions = (specPath: string): undefined | amd.Suppression => {
// tslint:disable-next-line:promise-function-async
const fsReadFile = (pathStr: string): Promise<Buffer> =>
new Promise((resolve, reject) => fs.readFile(
pathStr,
(err, data) => {
if (err) {
reject(err)
}
resolve(data)
}))
const readFile = async (pathStr: string): Promise<string> => {
const result = urlParse(pathStr)
return result === undefined ?
(await fsReadFile(pathStr)).toString() :
(await amd.httpsGet(pathStr)).read()
}
export const getSuppressions = async (specPath: string): Promise<undefined | amd.Suppression> => {
// find readme.md
const readMe = findReadMe(path.dirname(specPath))
const readMe = await findReadMe(path.dirname(specPath))
if (readMe === undefined) {
return undefined
}
const readMeStr = fs.readFileSync(readMe).toString()
const readMeStr = await readFile(readMe)
const cmd = md.parse(readMeStr)
const suppressionCodeBlock = amd.getCodeBlocksAndHeadings(cmd.markDown).Suppression
if (suppressionCodeBlock === undefined) {
@ -25,18 +44,3 @@ export const getSuppressions = (specPath: string): undefined | amd.Suppression =
}
return suppression
}
const findReadMe = (dir: string): string | undefined => {
dir = path.resolve(dir)
while (true) {
const fileName = path.join(dir, "readme.md")
if (fs.existsSync(fileName)) {
return fileName
}
const newDir = path.dirname(dir)
if (newDir === dir) {
return undefined
}
dir = newDir
}
}

Просмотреть файл

@ -79,7 +79,7 @@ export class WireFormatGenerator {
utils.clearCache()
}
try {
const suppression = getSuppressions(this.specPath)
const suppression = await getSuppressions(this.specPath)
const result = await utils.parseJson(suppression, this.specPath)
this.specInJson = result
const specOptions = {

2096
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.7.4",
"version": "0.7.5",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
@ -10,9 +10,9 @@
"license": "MIT",
"dependencies": {
"@microsoft.azure/autorest-extension-base": "1.0.13",
"@ts-common/azure-openapi-markdown": "^0.2.4",
"@ts-common/azure-openapi-markdown": "^0.3.1",
"@ts-common/commonmark-to-markdown": "^1.1.3",
"@ts-common/iterator": "0.0.36",
"@ts-common/iterator": "0.0.37",
"@ts-common/json": "0.0.19",
"@ts-common/json-parser": "0.2.2",
"@ts-common/property-set": "0.0.8",
@ -52,13 +52,14 @@
"@types/json-pointer": "^1.0.30",
"@types/jsonpath": "^0.2.0",
"@types/mocha": "^5.2.5",
"@types/node": "^8.10.34",
"@types/recursive-readdir": "^2.2.0",
"@types/should": "^8.1.30",
"@types/swagger-parser": "^4.0.2",
"@types/uuid": "^3.4.4",
"@types/yargs": "^11.1.2",
"mocha": "^5.2.0",
"nyc": "^11.8.0",
"nyc": "^13.0.1",
"should": "^5.2.0",
"ts-node": "^6.0.5",
"tslint": "^5.11.0",
@ -120,5 +121,8 @@
"start": "node ./dist/lib/autorestPlugin/pluginHost.js",
"prepack": "npm install && tsc && npm run tslint",
"cli": "node dist/cli.js"
},
"engines": {
"node": ">=10.11.0"
}
}