diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index 18327e293e..4db98b97d7 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -30,6 +30,9 @@ public void processOpts() { super.processOpts(); + // Generation notice, added on every generated files + Utils.setGenerationBanner(additionalProperties); + // Prevent all useless file to generate apiTestTemplateFiles.clear(); modelTestTemplateFiles.clear(); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java index 9a1fc10f04..4d79848d8c 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java @@ -32,6 +32,9 @@ public void processOpts() { setModelPropertyNaming("original"); setApiPackage("src"); + // Generation notice, added on every generated files + Utils.setGenerationBanner(additionalProperties); + languageSpecificPrimitives.add("Record"); instantiationTypes.put("map", "Record"); // clear all supported files to avoid unwanted ones diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java index 57e2fc20bf..e3d3444573 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java @@ -31,6 +31,9 @@ public void processOpts() { super.processOpts(); + // Generation notice, added on every generated files + Utils.setGenerationBanner(additionalProperties); + // Remove base template as we want to change its path supportingFiles.removeIf(file -> file.getTemplateFile().equals("Configuration.mustache")); diff --git a/generators/src/main/java/com/algolia/codegen/Utils.java b/generators/src/main/java/com/algolia/codegen/Utils.java index b2cf753f76..03e7c7800c 100644 --- a/generators/src/main/java/com/algolia/codegen/Utils.java +++ b/generators/src/main/java/com/algolia/codegen/Utils.java @@ -179,4 +179,15 @@ public static JsonNode readJsonFile(String filePath) throws ConfigException { public static boolean shouldUseExplicitOneOfName(Collection oneOf) { return oneOf.stream().filter(type -> type != null && type.startsWith("List")).count() >= 2; } + + /** + * Sets a `generationBanner` variable on the mustache templates, to display the generation banner + * on generated files. + */ + public static void setGenerationBanner(Map additionalProperties) { + additionalProperties.put( + "generationBanner", + "This file is generated, manual changes will be lost - read more on" + " https://github.com/algolia/api-clients-automation." + ); + } } diff --git a/templates/java/api.mustache b/templates/java/api.mustache index 9bcaf9a884..54a94120a0 100644 --- a/templates/java/api.mustache +++ b/templates/java/api.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + package {{package}}; import {{invokerPackage}}.ApiClient; diff --git a/templates/java/model.mustache b/templates/java/model.mustache index 5b1b77df91..ede048f4fb 100644 --- a/templates/java/model.mustache +++ b/templates/java/model.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + package {{package}}; import java.util.Objects; diff --git a/templates/javascript/clients/algoliasearch/builds/browser.mustache b/templates/javascript/clients/algoliasearch/builds/browser.mustache index 73d662201c..507e7dd15a 100644 --- a/templates/javascript/clients/algoliasearch/builds/browser.mustache +++ b/templates/javascript/clients/algoliasearch/builds/browser.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + import { createMemoryCache, createFallbackableCache, diff --git a/templates/javascript/clients/algoliasearch/builds/models.mustache b/templates/javascript/clients/algoliasearch/builds/models.mustache index f50af07288..d4324aa852 100644 --- a/templates/javascript/clients/algoliasearch/builds/models.mustache +++ b/templates/javascript/clients/algoliasearch/builds/models.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + import type { Host, Requester, diff --git a/templates/javascript/clients/algoliasearch/builds/node.mustache b/templates/javascript/clients/algoliasearch/builds/node.mustache index 6e2e9dd8dd..7eb8a838ce 100644 --- a/templates/javascript/clients/algoliasearch/builds/node.mustache +++ b/templates/javascript/clients/algoliasearch/builds/node.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + import { DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, diff --git a/templates/javascript/clients/api-single.mustache b/templates/javascript/clients/api-single.mustache index 7044245ff5..d44667b875 100644 --- a/templates/javascript/clients/api-single.mustache +++ b/templates/javascript/clients/api-single.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + {{> client/api/imports}} export const apiClientVersion = '{{packageVersion}}'; diff --git a/templates/javascript/clients/client/builds/browser.mustache b/templates/javascript/clients/client/builds/browser.mustache index d7364432d2..da1df3e44f 100644 --- a/templates/javascript/clients/client/builds/browser.mustache +++ b/templates/javascript/clients/client/builds/browser.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + import { createXhrRequester } from '{{{npmNamespace}}}/requester-browser-xhr'; import { DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_BROWSER } from '{{{npmNamespace}}}/client-common'; {{> client/builds/imports}} diff --git a/templates/javascript/clients/client/builds/node.mustache b/templates/javascript/clients/client/builds/node.mustache index b244a65517..ecf7cca401 100644 --- a/templates/javascript/clients/client/builds/node.mustache +++ b/templates/javascript/clients/client/builds/node.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + import { createHttpRequester } from '{{{npmNamespace}}}/requester-node-http'; import { DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE } from '{{{npmNamespace}}}/client-common'; {{> client/builds/imports}} diff --git a/templates/javascript/clients/client/model/clientMethodProps.mustache b/templates/javascript/clients/client/model/clientMethodProps.mustache index 85e5ee3d5d..3fd05a4b4a 100644 --- a/templates/javascript/clients/client/model/clientMethodProps.mustache +++ b/templates/javascript/clients/client/model/clientMethodProps.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + {{#apiInfo.apis.0}} {{#imports}} diff --git a/templates/javascript/clients/client/model/modelBarrel.mustache b/templates/javascript/clients/client/model/modelBarrel.mustache index bb5fdbb6c3..c14c76fa05 100644 --- a/templates/javascript/clients/client/model/modelBarrel.mustache +++ b/templates/javascript/clients/client/model/modelBarrel.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + {{#models}} {{#model}} export * from '{{{ classFilename }}}'; diff --git a/templates/javascript/clients/model.mustache b/templates/javascript/clients/model.mustache index e17ba49544..0b965735b6 100644 --- a/templates/javascript/clients/model.mustache +++ b/templates/javascript/clients/model.mustache @@ -1,3 +1,5 @@ +// {{{generationBanner}}} + {{#models}}{{#model}} {{#tsImports}} import { {{classname}} } from '{{filename}}'; diff --git a/templates/php/ApiException.mustache b/templates/php/ApiException.mustache index dbcb1c3fde..0103c2929a 100644 --- a/templates/php/ApiException.mustache +++ b/templates/php/ApiException.mustache @@ -1,3 +1,4 @@ +// {{{generationBanner}}} \\(\\d+\\.\\d+\\.\\d+(-.*)?\\)(; [a-zA-Z. ]+ (\\(\\d+((\\.\\d+)?\\.\\d+)?(-.*)?\\))?)*(; (\\(\\d+\\.\\d+\\.\\d+(-.*)?\\)))(; [a-zA-Z. ]+ (\\(\\d+((\\.\\d+)?\\.\\d+)?(-.*)?\\))?)*$ ``` @@ -140,13 +141,19 @@ You can take a look at the implementation over all clients, [in this pull reques Every methods of every clients provide a parameter that does not exist in the REST API, called `requestOptions`. -This parameter **must** be the last parameter of a method, and allow a user to override/merge additional `query parameters` or `headers` with the transporter ones. +This parameter MUST be the last parameter of a method, and allow a user to override/merge additional `query parameters` or `headers` with the transporter ones. ### Requesters -The requester needs to be configurable and capable to be overwriten to use a user defined requester. +The requester needs to be configurable and capable to be overwritten to use a user defined requester. The default requester must be the classic HTTP requester, and it's possible to provide other alternatives like an [Echo Requester](https://github.com/algolia/api-clients-automation/blob/main/clients/algoliasearch-client-javascript/packages/client-common/src/createEchoRequester.ts) that just send the request back. ### Logger -> TODO: informations +> TODO: information + +### Generated file banner + +The banner SHOULD be added at the very top of every generated files, to avoid confusion for our users, but also redirect them to the `api-clients-automation` monorepo, where the contribution happens. + +To do so, a `generationBanner` variable is available on every `mustache` templates, see [the initial implementation](https://github.com/algolia/api-clients-automation/pull/816) for more context.