Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Major Refactor] Native typescript support, circular references fix, vitest #29

Merged
merged 7 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
working top level dereferencing
  • Loading branch information
jonluca committed Aug 1, 2022
commit b61e33e64c97a53820046007474e4ccd8f3914b5
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"scripts": {
"build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node scripts/fixup.cjs",
"typecheck": "tsc --noEmit",
"test": "vitest test/**",
"test": "vitest test/** -t 'dereferencing schema with deference option at root'",
"coverage": "vitest --coverage"
},
"repository": "github:openapi-contrib/json-schema-to-openapi-schema",
Expand All @@ -32,12 +32,12 @@
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.9",
"chalk": "^5.0.1",
"json-schema-walker": "^0.0.1",
"json-schema-walker": "^0.0.4",
"yargs": "^17.5.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"c8": "^7.12.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
136 changes: 136 additions & 0 deletions test/dereference_schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,142 @@ it('dereferencing schema with deference option', async ({ expect }) => {
expect(result).toEqual(expected);
});

it('dereferencing schema with deference option at root', async ({ expect }) => {
const schema = {
definitions: {
AgilityServerWebServicesSDKServerServiceSVCJSONGetNavigationMenu2PostRequest:
{
type: 'object',
additionalProperties: false,
properties: {
navigationMenuIdentity: {
$ref: '#/definitions/NavigationMenuIdentity',
},
sessionId: {
type: 'string',
},
},
required: [],
title:
'AgilityServerWebServicesSDKServerServiceSVCJSONGetNavigationMenu2PostRequest',
},
NavigationMenuIdentity: {
type: 'object',
additionalProperties: false,
properties: {
Id: {
type: 'string',
},
LastModifiedDate: {
type: 'string',
},
Name: {
type: 'string',
},
__type: {
type: 'string',
},
},
required: [],
title: 'NavigationMenuIdentity',
},
},
$ref: '#/definitions/AgilityServerWebServicesSDKServerServiceSVCJSONGetNavigationMenu2PostRequest',
};

const result = await convert(schema, { dereference: true });

const expected = {
type: 'object',
additionalProperties: false,
properties: {
navigationMenuIdentity: {
type: 'object',
additionalProperties: false,
properties: {
Id: {
type: 'string',
},
LastModifiedDate: {
type: 'string',
},
Name: {
type: 'string',
},
__type: {
type: 'string',
},
},
required: [],
title: 'NavigationMenuIdentity',
},
sessionId: {
type: 'string',
},
},
required: [],
title:
'AgilityServerWebServicesSDKServerServiceSVCJSONGetNavigationMenu2PostRequest',
definitions: {
AgilityServerWebServicesSDKServerServiceSVCJSONGetNavigationMenu2PostRequest:
{
type: 'object',
additionalProperties: false,
properties: {
navigationMenuIdentity: {
type: 'object',
additionalProperties: false,
properties: {
Id: {
type: 'string',
},
LastModifiedDate: {
type: 'string',
},
Name: {
type: 'string',
},
__type: {
type: 'string',
},
},
required: [],
title: 'NavigationMenuIdentity',
},
sessionId: {
type: 'string',
},
},
required: [],
title:
'AgilityServerWebServicesSDKServerServiceSVCJSONGetNavigationMenu2PostRequest',
},
NavigationMenuIdentity: {
type: 'object',
additionalProperties: false,
properties: {
Id: {
type: 'string',
},
LastModifiedDate: {
type: 'string',
},
Name: {
type: 'string',
},
__type: {
type: 'string',
},
},
required: [],
title: 'NavigationMenuIdentity',
},
},
};

expect(result).toEqual(expected);
});

it('dereferencing schema with remote http and https references', async ({
expect,
}) => {
Expand Down