Fix for special symbols inside JSON-Pointer/Reference (#308)

* test for nested properties with `@` character.

* update json-refs.

* fix JSON-Pointer
This commit is contained in:
Sergey Shandar 2018-09-10 17:01:55 -07:00 коммит произвёл GitHub
Родитель 5417eec6d6
Коммит 5f43b2db45
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 37 добавлений и 21 удалений

2
.vscode/launch.json поставляемый
Просмотреть файл

@ -85,7 +85,7 @@
"stopOnEntry": false,
"args": [
"--no-timeouts",
"test/resolveNestedTests.ts",
"test/semanticValidatorTests.ts",
"-r",
"ts-node/register",
"--no-timeouts"

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

@ -1,5 +1,9 @@
# Changelog
### 09/10/2018 0.5.8
- Fix JSON-Pointer encoding.
### 08/28/2018 0.5.7
- Errors have optional `jsonUrl` and `jsonPosition` fields.

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

@ -28,6 +28,7 @@ import {
generatedPrefix,
getDefaultResponses
} from './cloudError';
import { pathToPtr } from 'json-refs';
const skipIfUndefined = <T>(f: (v: T) => T): ((v: T | undefined) => T | undefined) =>
(v) => v !== undefined ? f(v) : undefined
@ -64,7 +65,7 @@ export function resolveNestedDefinitions(spec: SwaggerObject, options: Options):
if (result !== undefined) {
generatedDefinitions[definitionName] = result
}
return { $ref: `#/definitions/${encodeURIComponent(definitionName)}` }
return { $ref: pathToPtr(["definitions", definitionName]) }
}
// a function to resolve SchemaObject array

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

@ -264,7 +264,7 @@ export class SpecResolver {
* @return {Promise<void>}
*/
private async resolveRelativePaths(
doc?: unknown,
doc?: object,
docPath?: string,
filterType?: string
): Promise<void> {

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

@ -192,7 +192,7 @@ export class WireFormatGenerator {
filter: ["relative", "remote"]
}
const allRefsRemoteRelative = JsonRefs.findRefs(this.specInJson, options)
const allRefsRemoteRelative = JsonRefs.findRefs(this.specInJson as object, options)
const e = entries(allRefsRemoteRelative as StringMap<any>)
const promiseFactories = toArray(map(
e,

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.5.7",
"version": "0.5.8",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -1618,16 +1618,16 @@
}
},
"json-refs": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/json-refs/-/json-refs-3.0.6.tgz",
"integrity": "sha512-umW/uhtvq2YO+MRtHXUiSIlaoslME3xjnpQJ5rkCQoF5RpDfuBqkbO22W3H4Q16VDOTECKHceqYQzef7sT/Hig==",
"version": "3.0.10",
"resolved": "https://registry.npmjs.org/json-refs/-/json-refs-3.0.10.tgz",
"integrity": "sha512-hTBuXx9RKpyhNhCEh7AUm0Emngxf9f1caw4BzH9CQSPlTqxSJG/X5W0di8AHSeePu+ZqSYjlXLU6u2+Q/6wFmw==",
"requires": {
"commander": "~2.11.0",
"graphlib": "^2.1.1",
"js-yaml": "^3.10.0",
"lodash": "^4.17.4",
"native-promise-only": "^0.8.1",
"path-loader": "^1.0.4",
"path-loader": "^1.0.5",
"slash": "^1.0.0",
"uri-js": "^3.0.2"
}

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.5.7",
"version": "0.5.8",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
@ -23,7 +23,7 @@
"glob": "^5.0.14",
"js-yaml": "^3.12.0",
"json-pointer": "^0.6.0",
"json-refs": "3.0.6",
"json-refs": "3.0.10",
"jsonpath": "^1.0.0",
"linq": "^3.1.0",
"lodash": "^4.17.10",

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

@ -11,10 +11,10 @@ const options: sway.Options = {
definitions: {
A: {
properties: {
a: {
"a": {
type: "string"
},
b: {
"b": {
properties: {
c: {
type: "string"
@ -22,6 +22,13 @@ const options: sway.Options = {
},
// additionalProperties: false,
required: ["c"]
},
"@": {
properties: {
c: {
type: "string"
}
}
}
},
required: ["a", "b"],
@ -63,11 +70,14 @@ describe("resolve nested properties", () => {
url: "example.com",
method: "x",
body: {
a: "somevalue",
b: {
"a": "somevalue",
"b": {
c: "somevalue",
// d: "anothervalue"
},
"@": {
c: "somevalue",
}
// d: 54
}
}

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

@ -1303,6 +1303,13 @@
"properties": {
"error": {
"$ref": "#/definitions/Error"
},
"@nested": {
"properties": {
"@a": {
"type": "string"
}
}
}
}
},

6
types/json-refs.d.ts поставляемый
Просмотреть файл

@ -1,6 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
declare module "json-refs" {
function findRefs(_0: unknown, _1?: unknown): unknown
}