bcherny/json-schema-to-typescript
GitHub で見る`declareExternallyReferenced` should be respected for non-interface types, too
Open
#525 opened on 2023年5月15日
buggood first issuehelp wanted
Repository metrics
- Stars
- (3,302 stars)
- PR merge metrics
- (30d に merged PR はありません)
説明
Consider the following JSON schema files:
foo.schema.json
{
"title": "Foo",
"oneOf": [
{
"$ref": "./bar.schema.json"
}
]
}
bar.schema.json
{
"title": "Bar",
"type": "string"
}
Compiling foo.schema.json with the option declareExternallyReferenced set to false would lead to bar.schema.json being present in the generated code:
import {compileFromFile} from 'json-schema-to-typescript'
import {ensureDir} from 'fs-extra'
ensureDir('dist')
.then(() => {
const schema = 'src/foo.schema.json';
return compileFromFile(schema, {
declareExternallyReferenced: false
});
})
.then((code) => {
console.log(code);
});
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
export type Foo = Bar;
export type Bar = string;
Except if I'm missing the purpose of declareExternallyReferenced , the generated code should be:
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
export type Foo = Bar;