generated from toomuchdesign/npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3689cc
commit a418ecb
Showing
27 changed files
with
216 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-ts-json-schema": minor | ||
--- | ||
|
||
`PluginInput['makeRelativePath']` type renamed to `PluginInput['makeRelativeModulePath']` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-ts-json-schema": minor | ||
--- | ||
|
||
Support Windows OS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-ts-json-schema": minor | ||
--- | ||
|
||
Remove `schemaFileName` meta data prop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ coverage | |
!.github | ||
!.nvmrc | ||
!.changeset | ||
!.gitattributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import path from 'node:path'; | ||
|
||
/** | ||
* Evaluate the relative module path from/to 2 absolute paths. | ||
* Accepts posix and win32 absolute urls and return a relative modules path (""./foo/bar") | ||
*/ | ||
export function makeRelativeModulePath({ | ||
fromDirectory, | ||
to, | ||
}: { | ||
fromDirectory: string; | ||
to: string; | ||
}): string { | ||
return ( | ||
'./' + path.relative(fromDirectory, to).split(path.sep).join(path.posix.sep) | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Parses OpenApi ref: | ||
* "#/components/schema/Foo" --> "components/schema/Foo" | ||
*/ | ||
export function parseRef(ref: string): string { | ||
if (!ref.startsWith('#/')) { | ||
throw new Error(`[openapi-ts-json-schema] Unsupported ref value: "${ref}"`); | ||
} | ||
|
||
const refPath = ref.replace('#/', ''); | ||
return refPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import path from 'node:path'; | ||
import { addSchemaToMetaData } from '../../src/utils'; | ||
import type { SchemaMetaData } from '../../src/types'; | ||
|
||
describe('addSchemaToMetaData', () => { | ||
it('generates expected metadata', () => { | ||
const ref = '#/components/schemas/Foo'; | ||
const schemaMetaDataMap = new Map(); | ||
const outputPath = path.normalize('/absolute/output/path'); | ||
const schema = { | ||
description: 'Schema description', | ||
type: 'object' as const, | ||
required: ['bar'], | ||
properties: { bar: { type: 'string' } } as const, | ||
}; | ||
|
||
addSchemaToMetaData({ | ||
ref, | ||
schemaMetaDataMap, | ||
schema, | ||
outputPath, | ||
isRef: true, | ||
}); | ||
|
||
const actual = schemaMetaDataMap.get(ref); | ||
const expected: SchemaMetaData = { | ||
isRef: true, | ||
originalSchema: schema, | ||
schemaAbsoluteDirName: | ||
'/absolute/output/path/components/schemas'.replaceAll('/', path.sep), | ||
schemaAbsoluteImportPath: | ||
'/absolute/output/path/components/schemas/Foo'.replaceAll( | ||
'/', | ||
path.sep, | ||
), | ||
schemaAbsolutePath: | ||
'/absolute/output/path/components/schemas/Foo.ts'.replaceAll( | ||
'/', | ||
path.sep, | ||
), | ||
schemaId: '/components/schemas/Foo', | ||
schemaUniqueName: 'componentsSchemasFoo', | ||
}; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
Oops, something went wrong.