Skip to content

Commit 8e84732

Browse files
committed
fix(clients): add generation banner to generated files
1 parent f93e2d1 commit 8e84732

24 files changed

+63
-6
lines changed

generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public void processOpts() {
3030

3131
super.processOpts();
3232

33+
// Generation notice, added on every generated files
34+
Utils.setGenerationBanner(additionalProperties);
35+
3336
// Prevent all useless file to generate
3437
apiTestTemplateFiles.clear();
3538
modelTestTemplateFiles.clear();

generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public void processOpts() {
3232
setModelPropertyNaming("original");
3333
setApiPackage("src");
3434

35+
// Generation notice, added on every generated files
36+
Utils.setGenerationBanner(additionalProperties);
37+
3538
languageSpecificPrimitives.add("Record");
3639
instantiationTypes.put("map", "Record");
3740
// clear all supported files to avoid unwanted ones

generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public void processOpts() {
3131

3232
super.processOpts();
3333

34+
// Generation notice, added on every generated files
35+
Utils.setGenerationBanner(additionalProperties);
36+
3437
// Remove base template as we want to change its path
3538
supportingFiles.removeIf(file -> file.getTemplateFile().equals("Configuration.mustache"));
3639

generators/src/main/java/com/algolia/codegen/Utils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,14 @@ public static JsonNode readJsonFile(String filePath) throws ConfigException {
179179
public static boolean shouldUseExplicitOneOfName(Collection<String> oneOf) {
180180
return oneOf.stream().filter(type -> type != null && type.startsWith("List")).count() >= 2;
181181
}
182+
183+
/**
184+
* Sets a `generationBanner` variable on the mustache templates, to display the generation banner on generated files.
185+
*/
186+
public static void setGenerationBanner(Map<String, Object> additionalProperties) {
187+
additionalProperties.put(
188+
"generationBanner",
189+
"This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation."
190+
);
191+
}
182192
}

templates/java/api.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
package {{package}};
24

35
import {{invokerPackage}}.ApiClient;

templates/java/model.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
package {{package}};
24

35
import java.util.Objects;

templates/javascript/clients/algoliasearch/builds/browser.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
import {
24
createMemoryCache,
35
createFallbackableCache,

templates/javascript/clients/algoliasearch/builds/models.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
import type {
24
Host,
35
Requester,

templates/javascript/clients/algoliasearch/builds/node.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
import {
24
DEFAULT_CONNECT_TIMEOUT_NODE,
35
DEFAULT_READ_TIMEOUT_NODE,

templates/javascript/clients/api-single.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
{{> client/api/imports}}
24

35
export const apiClientVersion = '{{packageVersion}}';

templates/javascript/clients/client/builds/browser.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
import { createXhrRequester } from '{{{npmNamespace}}}/requester-browser-xhr';
24
import { DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_BROWSER } from '{{{npmNamespace}}}/client-common';
35
{{> client/builds/imports}}

templates/javascript/clients/client/builds/node.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
import { createHttpRequester } from '{{{npmNamespace}}}/requester-node-http';
24
import { DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE } from '{{{npmNamespace}}}/client-common';
35
{{> client/builds/imports}}

templates/javascript/clients/client/model/clientMethodProps.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
{{#apiInfo.apis.0}}
24

35
{{#imports}}

templates/javascript/clients/client/model/modelBarrel.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
{{#models}}
24
{{#model}}
35
export * from '{{{ classFilename }}}';

templates/javascript/clients/model.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// {{{generationBanner}}}
2+
13
{{#models}}{{#model}}
24
{{#tsImports}}
35
import { {{classname}} } from '{{filename}}';

templates/php/ApiException.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// {{{generationBanner}}}
12
<?php
23

34
namespace {{invokerPackage}};

templates/php/ConfigWithRegion.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
// {{{generationBanner}}}
23

34
namespace {{invokerPackage}}\Configuration;
45

templates/php/Configuration.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
// {{{generationBanner}}}
23

34
namespace {{invokerPackage}}\Configuration;
45

templates/php/ModelInterface.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
// {{{generationBanner}}}
23

34
namespace {{modelPackage}};
45

templates/php/ObjectSerializer.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
// {{{generationBanner}}}
23

34
namespace {{invokerPackage}};
45

templates/php/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
// {{{generationBanner}}}
23

34
namespace {{apiPackage}};
45

templates/php/client_config.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
// {{{generationBanner}}}
23

34
namespace {{invokerPackage}}\Configuration;
45

templates/php/model.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
// {{{generationBanner}}}
3+
24
{{#models}}
35
{{#model}}
46

website/docs/contributing/add-new-language.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ The resulting User Agent is the concatenation of `base`, then `client` and all t
9393

9494
For example, if we have:
9595

96-
- base: `Algolia for Java (4.0.0)`
97-
- client: `; Search (4.0.0)`
98-
- segment:
99-
- `; JVM (11.0.14)`
100-
- `; experimental`
101-
- `; test (8.0.0-beta)`
96+
- base: `Algolia for Java (4.0.0)`
97+
- client: `; Search (4.0.0)`
98+
- segment:
99+
- `; JVM (11.0.14)`
100+
- `; experimental`
101+
- `; test (8.0.0-beta)`
102102

103103
Then the resulting User Agent is (the order is arbitrary):
104104

@@ -109,6 +109,7 @@ Algolia for Java (4.0.0); JVM (11.0.14); Search (4.0.0); experimental ; test (8.
109109
You can take a look at the Java implementation [here](https://github.com/algolia/api-clients-automation/pull/347).
110110

111111
The `User-Agent` MUST match the following regular expression:
112+
112113
```regex
113114
^Algolia for <LANGUAGE> \\(\\d+\\.\\d+\\.\\d+(-.*)?\\)(; [a-zA-Z. ]+ (\\(\\d+((\\.\\d+)?\\.\\d+)?(-.*)?\\))?)*(; <CLIENT> (\\(\\d+\\.\\d+\\.\\d+(-.*)?\\)))(; [a-zA-Z. ]+ (\\(\\d+((\\.\\d+)?\\.\\d+)?(-.*)?\\))?)*$
114115
```
@@ -150,3 +151,9 @@ The default requester must be the classic HTTP requester, and it's possible to p
150151
### Logger
151152

152153
> TODO: informations
154+
155+
### Generated file banner
156+
157+
The banner **should** be added at the very top of every generated files, to avoid confusion for our user, but also redirect them to the `api-clients-automation` monorepo, where the contribution happens.
158+
159+
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.

0 commit comments

Comments
 (0)