Skip to content

Commit a47e522

Browse files
authored
[core] Refactor templating management (#6357)
* [core] Refactor templating management This refactors template management to get logic out of DefaultGenerator and to provide a cleaner API to template search and read/compile. Deprecates MockDefaultGenerator, which is not a mock and causes in-memory retention of file contents. Maintainers should prefer executing a "dryRun" with new DefaultGenerator(true) or do true mock/spies if evaluating template intermediaries is truly necessary. Tests may read written files with lower overhead than the in-process retention of those bytes. This attempts to maintain some compatibility with existing templating adapter interfaces. Any breaking change here would be unintentional but minimal effort to retarget the new interface. * Tests for dry run file outputs * Update API usage in Meta, test TemplateManager * Wait on lastModified, lookup by filename in SpringCodegenTest * Test DefaultGenerator + ignore file * Move config.processOpenAPI in DefaultGenerator * Fix wrong use of libraries templateDirector (java) The samples scripts for Java incorrectly referenced the libraries directories directly rather than the upper-level Java directory. This was incorrect usage of template directories, because the generator expects to be given the "language" directory and perform a lookup for missing templates in the order: * user defined libraries directory * user defined language root * embedded libraries directory * embedded language root * _common directory This is incorrect in our samples scripts because a user or maintainer has the expectation that any template change to files at the Java/ root should also be honored on generation if the script specifies a custom template directory. * Fix handlebars extension usage, clean up Meta tasks HandlebarseEngineAdapter previously didn't handle files without extensions in the same was as the MustacheEngineAdapter. This now allows for files without extension (or dotfiles) to lookup in the same location. Meta tasks are cleaned up to use template manager only, rather than attempting to create an "empty" generator to use the previous templating specific methods. * Update kotlin-multiplatform gradle wrapper * Rename GraphQL .gitignore template The .gitignore file is unable to load via classpath resource from the graphql node server resource directory (for unknown reasons). Before this change, the missing template would fail silently. A .gitignore file may exist in other directories and load as expected. Added a default .gitignore to _common as a fallback so as not to break any custom generators which may also be failing silently. * Log entire stacktrace in go sdk built by gradle in AppVeyor * Rename PHP .gitignore to gitignore Java resources may not load .gitignore, this follows suit with other generators and uses "gitignore" (some use "gitignore.mustache"). * [php] Rename .gitignore templates to gitignore * Use same classpath lookup in common locator * [rust] Properly escape empty triple-braces * [samples] Regenerate
1 parent 74584eb commit a47e522

File tree

139 files changed

+2936
-1824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+2936
-1824
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ build_script:
5050
# install openapi-generator locally
5151
- mvn --no-snapshot-updates --quiet clean install -Dorg.slf4j.simpleLogger.defaultLogLevel=error
5252
# run the locally installed openapi-generator-gradle-plugin
53-
- gradle -b modules\openapi-generator-gradle-plugin\samples\local-spec\build.gradle buildGoSdk --info
53+
- gradle -b modules\openapi-generator-gradle-plugin\samples\local-spec\build.gradle buildGoSdk --stacktrace
5454
test_script:
5555
# restore test-related files
5656
- copy /b/v/y CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj

bin/ci/java-feign.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"generatorName": "java",
44
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
55
"outputDir": "samples/client/petstore/java/feign",
6-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/feign",
6+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
77
"additionalProperties": {
88
"hideGenerationTimestamp": true,
99
"booleanGetterPrefix": "is",

bin/ci/java-feign10x.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"generatorName": "java",
44
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
55
"outputDir": "samples/client/petstore/java/feign10x",
6-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/feign",
6+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
77
"additionalProperties": {
88
"hideGenerationTimestamp": true,
99
"booleanGetterPrefix": "is"

bin/ci/java-google-api-client.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"generatorName": "java",
44
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
55
"outputDir": "samples/client/petstore/java/google-api-client",
6-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/google-api-client",
6+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
77
"additionalProperties": {
88
"hideGenerationTimestamp": true
99
}

bin/ci/java-native.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"generatorName": "java",
44
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
55
"outputDir": "samples/client/petstore/java/native",
6-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/native",
6+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
77
"additionalProperties": {
88
"hideGenerationTimestamp": true
99
}

bin/ci/java-okhttp-gson-parcelableModel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"generatorName": "java",
55
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
66
"outputDir": "samples/client/petstore/java/okhttp-gson-parcelableModel",
7-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson",
7+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
88
"additionalProperties": {
99
"hideGenerationTimestamp": true,
1010
"parcelableModel": true

bin/ci/java-okhttp-gson.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"generatorName": "java",
44
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
55
"outputDir": "samples/client/petstore/java/okhttp-gson",
6-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson",
6+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
77
"additionalProperties": {
88
"hideGenerationTimestamp": true
99
}

bin/ci/java-petstore-feign-10x.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"generatorName": "java",
33
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
4-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/feign",
4+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
55
"outputDir": "samples/client/petstore/java/feign10x",
66
"additionalProperties": {
77
"hideGenerationTimestamp": true,

bin/ci/java-rest-assured-jackson.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"generatorName": "java",
44
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
55
"outputDir": "samples/client/petstore/java/rest-assured-jackson",
6-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/rest-assured",
6+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
77
"additionalProperties": {
88
"hideGenerationTimestamp": true,
99
"booleanGetterPrefix": "is",

bin/ci/java-rest-assured.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"generatorName": "java",
44
"inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml",
55
"outputDir": "samples/client/petstore/java/rest-assured",
6-
"templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/rest-assured",
6+
"templateDir": "modules/openapi-generator/src/main/resources/Java",
77
"additionalProperties": {
88
"hideGenerationTimestamp": true,
99
"booleanGetterPrefix": "is"

0 commit comments

Comments
 (0)