-
-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exportOpenApi: provide configuration parameters via command line #1178
base: ng
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for dtc-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Since this PR introduces a new file structure for tests to put them under
TL;DR; My suggestion here is to adhere your basic concept which is good, but rather try to restructure the actual source files than try to adopt the test suite to the existing structure. |
One small remark on your current proposal:
I'd like to have them under
because the |
Good feedback. I do not know Gradle standard conventions. I will move the directory containing the test code into the existing
I agree with you. But this is out of scope for this ticket. The reason for this PR is to align us "how do we test tasks". The outcome would be a standard/guideline what minimal tests we want to have for new tasks.
Once again, I agree with you. But I would not refactor the existing code without good test coverage.
We can restructure the source code when we have the test code in place ;-) |
I disagree with you on this point. The main point of a test should be to reflect the structure of the documentation project structure. This means, following our standard project structure, if an OpenAPI specification is located in Having "stuff" in a directory "resources" is the "Gradle/Java" way of thinking, which doesn't necessarily reflect a documentation project directoyr structure. |
Ah, yes makes sense, thanks for pointing that out. I agree if we align to adhere the documentation project directory structure. |
This would just kill the scope of this PR i guess :D But if we align on the things discussed above, we could start incrementally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this file still in use somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment nowhere.
I haven't finished this PR. I'm going to remove it.
// The properties defined by 'GenerateTask' have to be declared in the | ||
// configuration phase. Defining those properties in doFirst() throws | ||
// exception "propert 'X' is final and cannot be changed any further". | ||
generatorName = 'asciidoc' | ||
outputDir = "${targetDir}/OpenAPI".toString() | ||
inputSpec = "${docDir}/${specFile}" // plugin is not able to find file if inputPath is defined as '.' | ||
outputDir = "${targetDir}/OpenAPI".toString() | ||
|
||
// Define cache is always out-of-date to enforce file generation regardless of input and output file | ||
outputs.upToDateWhen { false } | ||
outputs.cacheIf { false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PacoVK I would appreciate it, if you could take a look into the implementation of this task.
The implementation looks strange. Defining the GenerateTask
properties in doFirst() throws exceptions. My Gradle mojo is below average. Maybe there is a better way.
if (!specFile) { | ||
logger.info("\n---> OpenAPI specification file not found in Config.groovy (https://doctoolchain.github.io/docToolchain/#_exportopenapi)") | ||
// If the specFile is not defined skip the rest. Otherwise GenerateTask | ||
// is called which fails with a misleading error message "file doesn't exist". | ||
// We throw the descriptive "missing property" error message during execution phase. | ||
return | ||
} else { | ||
logger.info("Found OpenAPI specification in Config.groovy") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also looks strange. But I had to add this return
statement otherwise GenerateTask
would throw an exception and I never reached the code in doFirst() which contains a better error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to investigate a bit, on the first glance it's because you use just a 3rd partie task and the implementation is just offering this behaviour. Maybe there is something to turn off the validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is already an improvement, i am also fine with that
Changes in
exportOpenApi
: the propertyopenApi.specFile
may be provided via the command line with-PopenApi.specFile
. This would ease the use case of having more than one OpenAPI specification file, as described in #1167.The
exportOpenApi
task did not have a test case yet. So I try to gather feedback about how test case should be structured (see #1107).Test case structure on the file system:
src/test/groovy/scripts/<task_name>
.src/test/groovy
. The content of this directory mirrors the structure and location of SUT, the system-under-test (i.e. the docToolchain tasks located inscripts
)<task_name>Spec
(starting with Uppercase)cerateTask
)config.groovy
. The test case can have more than one configuration file (config-*.groovy
).This PR includes the unit tests with the proposed structure for
exportOpenApi
.ExportOpenApiSpec.groovy
: the Spock unit testsconfig.groovy
: this is the configuration files used by most testsconfig-openApi-missing.groovy
: a configuration file where theopenApi
configuration is missingsrc/petstore-*.yaml
: the OpenApi specifications used by the testsrc/test/groovy/scripts/exportOpenApi/build