Closed grimmer0125 closed 1 year ago
Thanks for the report. Can you provide a minimal reproducible example that demonstrates the issue?
@domoritz,
I push the example into this repo, https://github.com/grimmer0125/nestj-ts-json-schema-generator-example.
// src/dto/sum.dto.ts
export class SumDto {
numbers: number[];
}
// src/dto/subtract.dto.ts
export class SubtractDto {
numberArray: number[];
}
"gen-json-schema": "ts-json-schema-generator --path src/**/*.dto.ts --no-type-check --type \"*\" -o json.schema"
in npm script After invoking this script, there is only SubtractDto
generated in the json schema file.
@domoritz ,
I made another minimized repo, https://github.com/grimmer0125/ts-json-schema-generator-example https://github.com/vega/ts-json-schema-generator that does not include NestJS and other npm packages. But it still gets only SubtractDto
in json.schema
.
I also noticed that this issue only happened in CLI interface. To use programmatic usage, there is no this issue.
I just tried it locally and this works:
$ yarn --silent run run --path 'test.ts' --type '*'
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"SubtractDto": {
"additionalProperties": false,
"properties": {
"numberArray": {
"items": {
"type": "number"
},
"type": "array"
}
},
"required": [
"numberArray"
],
"type": "object"
},
"SumDto": {
"additionalProperties": false,
"properties": {
"numbers": {
"items": {
"type": "number"
},
"type": "array"
}
},
"required": [
"numbers"
],
"type": "object"
}
}
}
Let me know if you see different output when you run this without an npm script.
@domoritz I'm sorry that I posted the wrong repo URL in the prevoius comment. Here is my new repo to reproduce this issue, just use npm start
to test. https://github.com/grimmer0125/ts-json-schema-generator-example
Let me know if you see different output when you run this without an npm script.
If I put my testing source files in the cloned repo, https://github.com/vega/ts-json-schema-generator, and execute yarn --silent run run --path 'src/dto/*.ts' --type '*' -o json.schema
, and I got the correct result.
So you're saying it works in this repo but not your test repo? Can you see what's different?
@domoritz ,
Thank you for the follow-up and the reminder about run this without an npm script.
I tried to do a comprehensive test (& a little tracing code). I noted the conclusions in the readme of this https://github.com/grimmer0125/ts-json-schema-generator-example. Please take a look.
The conclusion is the npm script "gen-json-schema": "ts-json-schema-generator --path src/*.dto.ts -o json.schema"
will convert src/*.dto.ts
as multiple files name arguments, but commander package can not handle this. After I try "gen-json-schema": "ts-json-schema-generator --path 'src/*.dto.ts' -o json.schema"
and it works.
Thank you again for this great library.
:rocket: Issue was released in v1.2.0-next.4
:rocket:
:rocket: Issue was released in v1.2.0-next.4
:rocket:
Thank you for supplying this great tool.
I notice that the CLI only proceed one file. I'd like to know if this is the expected behavior. If so, is there any other way to parse multiple source files at once and output the json schema file?