Skip to content

Commit 4b55738

Browse files
authored
fix(clients): add generation banner to generated files (#816)
1 parent 042b5a5 commit 4b55738

24 files changed

+67
-9
lines changed

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

+3
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

+3
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

+3
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

+11
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,15 @@ 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
185+
* on generated files.
186+
*/
187+
public static void setGenerationBanner(Map<String, Object> additionalProperties) {
188+
additionalProperties.put(
189+
"generationBanner",
190+
"This file is generated, manual changes will be lost - read more on" + " https://github.com/algolia/api-clients-automation."
191+
);
192+
}
182193
}

templates/java/api.mustache

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// {{{generationBanner}}}
12
<?php
23

34
namespace {{invokerPackage}};

templates/php/ConfigWithRegion.mustache

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+2
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

+16-9
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
```
@@ -140,13 +141,19 @@ You can take a look at the implementation over all clients, [in this pull reques
140141

141142
Every methods of every clients provide a parameter that does not exist in the REST API, called `requestOptions`.
142143

143-
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.
144+
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.
144145

145146
### Requesters
146147

147-
The requester needs to be configurable and capable to be overwriten to use a user defined requester.
148+
The requester needs to be configurable and capable to be overwritten to use a user defined requester.
148149
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.
149150

150151
### Logger
151152

152-
> TODO: informations
153+
> TODO: information
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 users, 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)