add unresolvable_reference into error codes (#455)

* add unresolvable_reference into error codes

* Update the version and cleanup employee.json file
This commit is contained in:
Renhe Li 2019-09-30 10:47:47 +08:00 коммит произвёл Ray Chen
Родитель 3b8eacdc91
Коммит 26cb277199
6 изменённых файлов: 523 добавлений и 3 удалений

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

@ -53,6 +53,7 @@ const errorConstants = {
severity: Severity.Critical,
docUrl: ""
},
UNRESOLVABLE_REFERENCE: { severity: Severity.Critical, docUrl: "" },
OBJECT_PROPERTIES_MINIMUM: {
severity: Severity.Critical,
docUrl: ""

2
package-lock.json сгенерированный
Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.19.7-beta.0",
"version": "0.19.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.19.7-beta.0",
"version": "0.19.7",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",

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

@ -0,0 +1,25 @@
{
"input": {
"request": {
"method": "PUT",
"url": "/subscriptions/e7032cc6-7422-4ddd-9022-bfbf23b05332/resourceGroups/testRG/providers/Microsoft.Contoso/Employees/SpiderMan?api-version=2019-01-01",
"headers": {
"strict-Transport-Security": "max-age=31536000; includeSubDomains",
"x-ms-request-id": "8e3485b6-c8a7-45c2-a9f5-59b826e42880",
"date": "Tue, 11 Sep 2018 18:45:41 GMT",
"eTag": "\"AAAAAAAAjAIAAAAAAACL/A==\"",
"server": "Microsoft-HTTPAPI/2.0",
"Content-Type": "application/json"
},
"body": {
"properties": {
"firstName": "Spide$^%^@%$^%$@rMan",
"lastName": "Marvel",
"group": "Avengers",
"likesTea": "true",
"speciality": ["Use skyline to swing", "Crawl on virtually any surface"]
}
}
}
}
}

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

@ -0,0 +1,472 @@
{
"swagger": "2.0",
"info": {
"title": "ContosoManagementClient",
"description": "Contoso provider",
"version": "2019-01-01"
},
"host": "management.azure.com",
"schemes": ["https"],
"consumes": ["application/json"],
"produces": ["application/json"],
"security": [
{
"azure_auth": ["user_impersonation"]
}
],
"securityDefinitions": {
"azure_auth": {
"type": "oauth2",
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
"flow": "implicit",
"description": "Azure Active Directory OAuth2 Flow.",
"scopes": {
"user_impersonation": "impersonate your user account"
}
}
},
"paths": {
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.contoso/employees": {
"get": {
"description": "Returns list of employees.",
"operationId": "Employee_List",
"parameters": [
{
"$ref": "#/parameters/ResourceGroupNameParameter"
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
}
],
"responses": {
"200": {
"description": "Employee details.",
"schema": {
"$ref": "#/definitions/EmployeeResourceList"
}
}
},
"deprecated": false,
"x-ms-pageable": {
"nextLinkName": "nextLink"
},
"x-ms-examples": {
"EmployeeDetailsGet": {
"$ref": "./examples/EmployeeResourceList.json"
}
}
}
},
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.contoso/employees/{employeeName}": {
"get": {
"description": "Returns employee resource for a given name.",
"operationId": "Employee_Get",
"parameters": [
{
"$ref": "#/parameters/ResourceGroupNameParameter"
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
},
{
"$ref": "#/parameters/EmployeeNameParameter"
}
],
"responses": {
"200": {
"description": "Employee details.",
"schema": {
"$ref": "#/definitions/EmployeeResource"
}
}
},
"x-ms-examples": {
"EmployeeDetailsGet": {
"$ref": "./examples/EmployeeDetailsGet.json"
}
}
},
"put": {
"description": "Create or update employee resource.",
"operationId": "Employee_CreateAndUpdate",
"parameters": [
{
"$ref": "#/parameters/ResourceGroupNameParameter"
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
},
{
"$ref": "#/parameters/EmployeeNameParameter"
},
{
"name": "EmployeeResource",
"description": "Employee details.",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/EmployeeResource"
}
}
],
"responses": {
"200": {
"description": "Successful.",
"schema": {
"$ref": "#/definitions/EmployeeResource"
}
}
},
"x-ms-examples": {
"EmployeeResourceUpdate": {
"$ref": "./examples/EmployeeResourceUpdate.json"
}
}
},
"patch": {
"description": "Update employee details.",
"operationId": "Employees_Update",
"parameters": [
{
"$ref": "#/parameters/ResourceGroupNameParameter"
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
},
{
"$ref": "#/parameters/EmployeeNameParameter"
},
{
"name": "EmployeePatchResource",
"description": "Employee patch details.",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/EmployeePatchResource"
}
}
],
"responses": {
"200": {
"description": "Successful.",
"schema": {
"$ref": "#/definitions/EmployeeResource"
}
}
},
"x-ms-examples": {
"EmployeeResourceUpdate": {
"$ref": "./examples/EmployeeResourceUpdate.json"
}
}
}
},
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.contoso/operations": {
"get": {
"description": "Returns list of operations.",
"operationId": "Operation_List",
"parameters": [
{
"$ref": "#/parameters/ResourceGroupNameParameter"
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
}
],
"responses": {
"200": {
"description": "Operation details.",
"schema": {
"$ref": "#/definitions/OperationsList"
}
}
},
"deprecated": false,
"x-ms-pageable": {
"nextLinkName": "nextLink"
},
"x-ms-examples": {
"EmployeeDetailsGet": {
"$ref": "./examples/OperationsList.json"
}
}
}
}
},
"definitions": {
"Resource": {
"description": "An Azure resource.",
"properties": {
"id": {
"description": "Azure resource Id.",
"type": "string",
"readOnly": true
},
"name": {
"description": "Azure resource name.",
"type": "string",
"readOnly": true
},
"type": {
"description": "Azure resource type.",
"type": "string",
"readOnly": true
},
"location": {
"description": "Location of the resource.",
"type": "string",
"readOnly": false
},
"tags": {
"description": "resource tags.",
"type": "object",
"readOnly": false,
"additionalProperties": {
"type": "string"
}
}
},
"x-ms-azure-resource": true
},
"EmployeeResource": {
"type": "object",
"description": "Employee details",
"allOf": [
{
"$ref": "#/definitions/Resource"
}
],
"required": ["properties"],
"properties": {
"properties": {
"type": "object",
"required": ["firstName", "lastName", "group", "likesTea"],
"properties": {
"firstName": {
"type": "string",
"description": "Employee full name.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"middleName": {
"type": "string",
"description": "Employee middle name.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"lastName": {
"type": "string",
"description": "Employee last name.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"group": {
"type": "string",
"description": "group like Finance, HR etc...",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"identificationNumber": {
"type": "string",
"readOnly": true,
"description": "unique id assigned at the time of user creation"
},
"likesTea": {
"type": "string",
"description": "Gets or sets the deployment mode.",
"enum": ["Yes"],
"x-ms-enum": {
"name": "likesTea",
"modelAsString": true
}
}
}
}
}
},
"EmployeePatchResource": {
"type": "object",
"description": "Employee patch properties",
"properties": {
"tags": {
"description": "resource tags.",
"type": "object",
"readOnly": false,
"additionalProperties": {
"type": "string"
}
},
"properties": {
"type": "object",
"properties": {
"group": {
"type": "string",
"description": "group like Finance, HR etc..."
}
}
}
}
},
"EmployeeResourceList": {
"description": "The list of employees.",
"type": "object",
"properties": {
"nextLink": {
"description": "The link used to get the next page of employees list.",
"type": "string"
},
"value": {
"description": "The list of recommendations.",
"type": "array",
"items": {
"$ref": "#/definitions/EmployeeResource"
}
}
}
},
"NestedResource": {
"type": "object",
"description": "Nested Resource details",
"allOf": [
{
"$ref": "#/definitions/Resource"
}
],
"required": ["properties"],
"properties": {
"properties": {
"properties": {
"firstName": {
"type": "string",
"description": "Nested Resource full name.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"middleName": {
"type": "string",
"description": "Nested Resource name.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"lastName": {
"type": "string",
"description": "Nested Resource name.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"group": {
"type": "string",
"description": "group like Finance, HR etc...",
"minLength": 1,
"maxLength": 10,
"pattern": "^[A-Za-z0-9-._]+$"
},
"identificationNumber": {
"type": "string",
"readOnly": true,
"description": "unique id assigned at the time of user creation"
},
"likesTea": {
"type": "string",
"description": "Gets or sets the deployment mode.",
"enum": ["Yes"],
"x-ms-enum": {
"name": "likesTea",
"modelAsString": true
}
}
},
"required": ["firstName", "lastName", "group", "likesTea"],
"type": "object"
}
}
},
"NestedResourceList": {
"description": "The list of nested resources.",
"type": "object",
"properties": {
"nextLink": {
"description": "The link used to get the next page of nested resources list.",
"type": "string"
},
"value": {
"description": "The list of recommendations.",
"type": "array",
"items": {
"$ref": "#/definitions/NestedResource"
}
}
}
}
},
"parameters": {
"SubscriptionIdParameter": {
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "The Azure subscription ID."
},
"ApiVersionParameter": {
"name": "api-version",
"in": "query",
"required": true,
"type": "string",
"description": "Client Api Version."
},
"ResourceGroupNameParameter": {
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the resource group.",
"x-ms-parameter-location": "method"
},
"EmployeeNameParameter": {
"name": "employeeName",
"in": "path",
"required": true,
"type": "string",
"description": "The name employee resource.",
"x-ms-parameter-location": "method"
},
"NestedResourceNameParameter": {
"name": "nestedResourceName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of nested resource.",
"x-ms-parameter-location": "method"
},
"ExtensionResourceNameParameter": {
"name": "extensionResourceName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of extension resource.",
"x-ms-parameter-location": "method"
}
}
}

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

@ -10,7 +10,7 @@ import { ResponsesObject } from "yasway"
import * as Constants from "../lib/util/constants"
import { LiveValidator } from "../lib/validators/liveValidator"
const numberOfSpecs = 9
const numberOfSpecs = 10
jest.setTimeout(150000)
describe("Live Validator", () => {
@ -515,6 +515,28 @@ describe("Live validator snapshot validation", () => {
expect(validationResult).toMatchSnapshot()
})
test(`should return expected error for unresolvable reference`, async () => {
const options = {
directory: `${__dirname}/liveValidation/swaggers/`,
isPathCaseSensitive: false,
useRelativeSourceLocationUrl: true,
swaggerPathsPattern:
"specification\\rpsaas\\resource-manager\\Microsoft.Contoso\\stable\\2019-01-01\\*.json",
git: {
shouldClone: false
}
}
const liveValidator = new LiveValidator(options)
await liveValidator.initialize()
const payload = require(`${__dirname}/liveValidation/payloads/unresolvableReference_input.json`)
const result = liveValidator.validateLiveRequest(payload.input.request, {
includeErrors: ["UNRESOLVABLE_REFERENCE"]
})
expect(result.isSuccessful === false)
expect(result.errors[0].code === "UNRESOLVABLE_REFERENCE")
})
errors.forEach(error => {
test(`should return the expected error requestResponse validation for ${error}`, async () => {
const payload = require(`${__dirname}/liveValidation/payloads/${lodash.camelCase(