@@ -6,8 +6,8 @@ import type {
66} from 'json-schema' ;
77import type { Options , SchemaType , SchemaTypeKeys } from './types' ;
88import { Walker } from 'json-schema-walker' ;
9- import { allowedKeywords } from './const' ;
10- import type { OpenAPI3 } from 'openapi-typescript ' ;
9+ import { allowedKeywords } from './const.js ' ;
10+ import type { OpenAPIV3 } from 'openapi-types ' ;
1111
1212class InvalidTypeError extends Error {
1313 constructor ( message : string ) {
@@ -31,16 +31,26 @@ const handleDefinition = async <T>(
3131 if ( type ) {
3232 // Walk just the definitions types
3333 const walker = new Walker < T > ( ) ;
34- await walker . loadSchema ( { ...def , $schema : schema [ '$schema' ] } as any , {
35- dereference : true ,
36- cloneSchema : true ,
37- dereferenceOptions : {
38- dereference : {
39- circular : 'ignore' ,
34+ await walker . loadSchema (
35+ {
36+ definitions : schema [ 'definitions' ] || [ ] ,
37+ ...def ,
38+ $schema : schema [ '$schema' ] ,
39+ } as any ,
40+ {
41+ dereference : true ,
42+ cloneSchema : true ,
43+ dereferenceOptions : {
44+ dereference : {
45+ circular : 'ignore' ,
46+ } ,
4047 } ,
41- } ,
42- } ) ;
48+ }
49+ ) ;
4350 await walker . walk ( convertSchema , walker . vocabularies . DRAFT_07 ) ;
51+ if ( 'definitions' in walker . rootSchema ) {
52+ delete ( < any > walker . rootSchema ) . definitions ;
53+ }
4454 return walker . rootSchema ;
4555 } else if ( Array . isArray ( def ) ) {
4656 // if it's an array, we might want to reconstruct the type;
@@ -62,7 +72,7 @@ const handleDefinition = async <T>(
6272const convert = async < T = JSONSchema > (
6373 schema : T ,
6474 options ?: Options
65- ) : Promise < OpenAPI3 > => {
75+ ) : Promise < OpenAPIV3 . Document > => {
6676 const walker = new Walker < T > ( ) ;
6777 const convertDefs = options ?. convertUnreferencedDefinitions ?? true ;
6878 await walker . loadSchema ( schema , options ) ;
@@ -75,7 +85,7 @@ const convert = async <T = JSONSchema>(
7585 rootSchema . definitions [ defName ] = await handleDefinition ( def , schema ) ;
7686 }
7787 }
78- return rootSchema as OpenAPI3 ;
88+ return rootSchema as OpenAPIV3 . Document ;
7989} ;
8090
8191function stripIllegalKeywords ( schema : SchemaType ) {
0 commit comments