Skip to content

Commit

Permalink
Revert using bundled dependencies for @autorest/schema (Azure#3745)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored Dec 16, 2020
1 parent af07a63 commit 760a2b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/extensions/core/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { existsSync } from "fs";

const resolveAppRoot = () => {
let current = path.resolve(__dirname);
while (!existsSync(path.join(current, "node_modules"))) {
while (!existsSync(path.join(current, "package.json"))) {
current = path.dirname(current);
}
return current;
Expand Down
13 changes: 9 additions & 4 deletions packages/extensions/core/lib/pipeline/schema-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import * as SchemaValidator from "z-schema";
import { OperationAbortedException } from "../exception";
import { Channel } from "../message";
import { createPerFilePlugin, PipelinePlugin } from "./common";
import * as path from "path";
import { AppRoot } from "../constants";

// TODO-TIM: Find a better way? Move schema to a package?
const schemaFolder = process.env.JEST_WORKER_ID === undefined ? "." : path.resolve(AppRoot, "../../libs/autorest-schemas");

export function createSwaggerSchemaValidatorPlugin(): PipelinePlugin {
const validator = new SchemaValidator({ breakOnFirstError: false });

const extendedSwaggerSchema = require(`@autorest/schemas/swagger-extensions.json`);
const extendedSwaggerSchema = require(`${schemaFolder}/swagger-extensions.json`);
(<any>validator).setRemoteReference(
"http://json.schemastore.org/swagger-2.0",
require(`@autorest/schemas/swagger.json`),
require(`${schemaFolder}/swagger.json`),
);
(<any>validator).setRemoteReference(
"https://raw.githubusercontent.com/Azure/autorest/master/schema/example-schema.json",
require(`@autorest/schemas/example-schema.json`),
require(`${schemaFolder}/example-schema.json`),
);
return createPerFilePlugin(async (config) => async (fileIn, sink) => {
const obj = await fileIn.ReadObject<any>();
Expand Down Expand Up @@ -55,7 +60,7 @@ export function createSwaggerSchemaValidatorPlugin(): PipelinePlugin {
export function createOpenApiSchemaValidatorPlugin(): PipelinePlugin {
const validator = new SchemaValidator({ breakOnFirstError: false });

const extendedOpenApiSchema = require(`@autorest/schemas/openapi3-schema.json`);
const extendedOpenApiSchema = require(`${schemaFolder}/openapi3-schema.json`);
return createPerFilePlugin(async (config) => async (fileIn, sink) => {
const obj = await fileIn.ReadObject<any>();
const errors = await new Promise<Array<{
Expand Down
13 changes: 4 additions & 9 deletions packages/extensions/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
"test": "jest --coverage=false --forceExit --runInBand",
"test:ci": "jest --ci",
"watch": "tsc -p . --watch",
"build": "tsc -p .",
"build": "npm run before-build && tsc -p .",
"static-link": "static-link --no-node-modules --debug",
"fix": "eslint . --fix --ext .ts",
"lint": "eslint . --ext .ts --max-warnings=0",
"prepack": "npm run static-link && npm run build",
"run-pwsh": "pwsh -noprofile -command \"& {param($script) pwsh -noprofile -command ((convertfrom-json (get-content -raw ./package.json)).'pwsh-scripts'.$script) }\"",
"clean": "rimraf ./dist && rimraf ./*.log"
"clean": "rimraf ./dist && rimraf ./*.log",
"before-build": "mkdirp ./dist/lib/pipeline && cpy ../../libs/autorest-schemas/*.json ./dist/lib/pipeline"
},
"typings": "./dist/main.d.ts",
"devDependencies": {
Expand Down Expand Up @@ -109,11 +110,5 @@
"yaml-ast-parser": "0.0.40",
"z-schema": "^3.19.0"
}
},
"dependencies": {
"@autorest/schemas": "~1.0.0"
},
"bundledDependencies": [
"@autorest/schemas"
]
}
}

0 comments on commit 760a2b2

Please sign in to comment.