Skip to content

Commit

Permalink
Merge branch 'main' into postman-captures-interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
niclim committed Apr 5, 2023
2 parents af512a2 + 8254afe commit aa15d48
Show file tree
Hide file tree
Showing 21 changed files with 388 additions and 262 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "openapi-workspaces",
"license": "MIT",
"private": true,
"version": "0.42.0",
"version": "0.42.2",
"workspaces": [
"projects/json-pointer-helpers",
"projects/openapi-io",
Expand Down
6 changes: 3 additions & 3 deletions projects/json-pointer-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/json-pointer-helpers",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.42.0",
"version": "0.42.2",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand All @@ -25,13 +25,13 @@
"@types/node": "^18.0.0",
"babel-jest": "^29.3.1",
"jest": "^29.3.1",
"prettier": "^2.4.1",
"prettier": "^2.8.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"dependencies": {
"jsonpointer": "^5.0.1",
"minimatch": "7.4.4"
"minimatch": "8.0.3"
}
}
6 changes: 3 additions & 3 deletions projects/openapi-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/openapi-cli",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.42.0",
"version": "0.42.2",
"main": "build/lib.js",
"types": "build/lib.d.ts",
"files": [
Expand Down Expand Up @@ -47,7 +47,7 @@
"bent": "^7.3.12",
"jest": "^29.3.1",
"node-fetch": "^2.6.7",
"prettier": "^2.4.1",
"prettier": "^2.8.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"tunnel": "^0.0.6",
Expand Down Expand Up @@ -78,7 +78,7 @@
"lodash.sortby": "^4.7.0",
"log": "^6.3.1",
"log-node": "^8.0.3",
"minimatch": "7.4.4",
"minimatch": "8.0.3",
"mockttp": "^3.3.1",
"node-forge": "^1.2.1",
"node-machine-id": "^1.1.12",
Expand Down
6 changes: 3 additions & 3 deletions projects/openapi-io/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/openapi-io",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.42.0",
"version": "0.42.2",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand All @@ -25,13 +25,13 @@
"@types/fast-json-patch": "^1.1.5",
"@types/is-url": "^1.2.30",
"@types/lodash.clonedeep": "^4",
"@types/lodash.sortby": "^4.7.6",
"@types/lodash.sortby": "^4.7.7",
"@types/node": "^18.0.0",
"@types/node-fetch": "2.6.3",
"@types/semver": "^7.3.10",
"babel-jest": "^29.3.1",
"jest": "^29.3.1",
"prettier": "^2.4.1",
"prettier": "^2.8.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ParseOpenAPIResult,
parseOpenAPIWithSourcemap,
} from '../../parser/openapi-sourcemap-parser';
import sortBy from 'lodash.sortby';

function prepSnapshot(result: ParseOpenAPIResult) {
const cwd = process.cwd();
Expand All @@ -18,8 +17,9 @@ function prepSnapshot(result: ParseOpenAPIResult) {

result.sourcemap.rootFilePath = result.sourcemap.rootFilePath.split(cwd)[1];

result.sourcemap.files = sortBy(result.sourcemap.files, 'path');

result.sourcemap.files = result.sourcemap.files.sort((a, b) =>
a.path.toLocaleLowerCase().localeCompare(b.path.toLocaleLowerCase())
);
return result;
}
describe('denormalize', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
parseOpenAPIWithSourcemap,
} from '../openapi-sourcemap-parser';
import path from 'path';
import sortBy from 'lodash.sortby';

const cwd = process.cwd();

Expand All @@ -20,7 +19,9 @@ function prepSnapshot(result: ParseOpenAPIResult) {

result.sourcemap.rootFilePath = result.sourcemap.rootFilePath.split(cwd)[1];

result.sourcemap.files = sortBy(result.sourcemap.files, 'path');
result.sourcemap.files = result.sourcemap.files.sort((a, b) =>
a.path.toLocaleLowerCase().localeCompare(b.path.toLocaleLowerCase())
);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`advanced validators run and append their results 1`] = `
"invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema > oneOf must NOT have fewer than 1 items
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema/oneOf
invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema > anyOf must NOT have fewer than 1 items
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema/anyOf
invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema > items must be object
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema/items
invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema schema with type "object" cannot also include keywords: items
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema"
`;

exports[`error cases with messages additional properties in invalid place 1`] = `
"invalid openapi: paths > /example > get must have required property 'responses'
/paths/~1example/get
invalid openapi: info must NOT have additional properties
/info"
exports[`non-strict validation should fail open api doc with no path should throw an error 1`] = `
"invalid openapi:  must have required property 'paths'
"
`;

exports[`error cases with messages open api doc with no description in response 1`] = `
exports[`non-strict validation should fail open api doc without responses 1`] = `
"invalid openapi: paths > /example > get must have required property 'responses'
/paths/~1example/get"
`;

exports[`error cases with messages open api doc with no path should throw an error 1`] = `
"invalid openapi:  must have required property 'paths'
"
`;

exports[`processValidatorErrors 1`] = `
"invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema > properties > hello > items must be object
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema/properties/hello/items"
Expand All @@ -51,3 +33,19 @@ exports[`processValidatorErrors attaches the sourcemap 1`] = `
40 | }
41 | }"
`;
exports[`strict validation advanced validators run and append their results 1`] = `
"invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema > oneOf must NOT have fewer than 1 items
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema/oneOf
invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema > anyOf must NOT have fewer than 1 items
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema/anyOf
invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema > items must be object
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema/items
invalid openapi: paths > /api/users/{userId} > get > responses > 200 > content > application/json > schema schema with type "object" cannot also include keywords: items
/paths/~1api~1users~1{userId}/get/responses/200/content/application~1json/schema"
`;
exports[`strict validation open api doc with no description in response should throw 1`] = `
"invalid openapi: paths > /example > get > responses > 200 must have required property 'description'
/paths/~1example/get/responses/200"
`;
60 changes: 60 additions & 0 deletions projects/openapi-io/src/validation/validation-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,66 @@ const createOpenAPIValidationSchema = (schema: any) => ({
},
});

export const basic3openapi_schema = {
$id: 'http://openapis.org/v3/schema.json#',
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
required: ['openapi', 'info', 'paths'],
properties: {
openapi: {
type: 'string',
},
info: {
type: 'object',
},
paths: {
type: 'object',
patternProperties: {
'^/': {
type: 'object',
properties: {
get: {
$ref: '#/definitions/operation',
},
put: {
$ref: '#/definitions/operation',
},
post: {
$ref: '#/definitions/operation',
},
delete: {
$ref: '#/definitions/operation',
},
options: {
$ref: '#/definitions/operation',
},
head: {
$ref: '#/definitions/operation',
},
patch: {
$ref: '#/definitions/operation',
},
trace: {
$ref: '#/definitions/operation',
},
},
},
},
},
},
definitions: {
operation: {
type: 'object',
required: ['responses'],
properties: {
responses: {
type: 'object',
},
},
},
},
};

export const openapi3_0_json_schema = createOpenAPIValidationSchema(
openapi3_0_schema_object
);
Expand Down
Loading

0 comments on commit aa15d48

Please sign in to comment.