With #74, the method ModelUtils.getUnusedSchemas(OpenAPI) was updated. It computes the list of unused schema.
We could append this information to the output of the validate task. It is a kind of information that something is not right in the schema.
What do you think?
cc: @ackintosh (you seems to use this feature, are you interested?)
I would expect validate to only say whether or not a spec is valid. Unused models isn't invalid.
Maybe a switch like --recommend to output this additional information?
We could add nested commands as well. For example:
cli check valid
cli check unused
cli check security
etc
This way there wouldn't be confusion about the use cases.
I like the switch --recommend.
validate users, I hope the above features will be realized with single commandthe switch is suitable for satisfying the above. 馃挕
@ackintosh In #251, I have added warnings to the errors you'd normally receive with validation. With that PR, we'd begin validating on every generation by default. Rather than having multiple switches to enable/disable validation and enable/disable recommendations, I've rolled them into errors and warnings.
On generation, you'll only see these warnings _if_ errors are present. The message would look like this from the gradle plugin:
$ gradle generateGoWithInvalidSpec
> Task :generateGoWithInvalidSpec FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateGoWithInvalidSpec'.
> Specification has failed validation. | Error count: 1, Warning count: 1
Errors:
-attribute info is missing
Warnings:
-Unused model: Pet
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
1 actionable task: 1 executed
So for the CLI validate command, I was wondering if we should perform error+warning by default or, if you pass --recommend it would show recommendations even if you don't have errors. Which sounds best for openapi-generator-cli validate --recommend?
I think that we can consider different behaviors (exit code) useful for CI as well as pretty output-format capability. Something like:
openapi-generator-cli validate should
openapi-generator-cli validate --recommend should
openapi-generator-cli validate --ignore-recommend should
My idea is based on making it as simple as possible. From that point of view, here is my suggestion:
openapi-generator-cli validateUsers who run this command want to know if their spec is valid.
So the CLI should behave:
openapi-generator-cli validate --recommendUsers who run this command want to know wherther there are any matters as well as whether their spec is valid.
So the CLI should behave:
@ackintosh I like that suggestion best. However, for the second case I think it would make more sense to return an error code only if there are errors. If you validate and say "by the way, let me know of suggestions" I don't think that is technically a reason to exit with a status 1. Or is your thought that someone would be piping stderr somewhere and they'd want all errors and warnings as well as a failure if any exist? If it's the latter, I think we'd need to document that in the comment on --recommend because I would personally be surprised by that behavior.
@jimschubert I agree with you. There is no technically reason to exit with status 1 if errors are not present ( = if input spec is valid). 馃挕
I'll work on updating to include this --recommend option tonight.
I opened #292 to implement --recommend please check it out ;D
The implementation of #292 has been merged and exists in recent releases. Closing this. If issues arise, please reopen.