Skip to content

Commit 1251bbc

Browse files
authored
Merge pull request #78 from bitnami-labs/feature/allow-set-default-value
Allow setting a default value for a parameter using the modifier
2 parents 44a4049 + 4eaa863 commit 1251bbc

17 files changed

+342
-471
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Currently supported modifiers:
117117
- `[object]` Indicates that the value of the parameter must be set to `{}`.
118118
- `[string]` Indicates that the value of the parameter must be set to `""`.
119119
- `[nullable]` Indicates that the parameter value can be set to `null`.
120+
- `[default: DEFAULT_VALUE]` Sets the default value to `DEFAULT_VALUE`.
120121

121122
The modifiers are also customizable via the [configuration file](#configuration-file).
122123

config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"array": "array",
1515
"object": "object",
1616
"string": "string",
17-
"nullable": "nullable"
17+
"nullable": "nullable",
18+
"default": "default"
1819
},
1920
"regexp": {
2021
"paramsSectionTitle": "Parameters"

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function runReadmeGenerator(options) {
6060
}
6161

6262
if (schemaFilePath) {
63+
parsedMetadata.parameters = buildParamsToRenderList(parsedMetadata.parameters, config);
6364
renderOpenAPISchema(schemaFilePath, parsedMetadata.parameters, config);
6465
}
6566
}

lib/builder.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ function applyModifiers(param, config) {
3535
// unless another modifier is applied at the same time. In that case, the second
3636
// modifier specifies the default value.
3737
break;
38+
case modifier.match(new RegExp(`${config.modifiers.default}:.*`))?.input: {
39+
const defaultSpacesRegex = `${config.modifiers.default}:\\s*`;
40+
param.value = modifier.replace(new RegExp(defaultSpacesRegex), '');
41+
break;
42+
}
3843
default:
3944
throw new Error(`Unknown modifier: ${modifier} for parameter ${param.name}`);
4045
}
@@ -58,8 +63,8 @@ function combineMetadataAndValues(valuesObject, valuesMetadata) {
5863
if (!param.extra) {
5964
const paramIndex = valuesObject.findIndex((e) => e.name === param.name);
6065
if (paramIndex !== -1) {
61-
// Set the value from actual object
62-
param.value = valuesObject[paramIndex].value;
66+
// Set the value from actual object if not set before
67+
if (!param.value) param.value = valuesObject[paramIndex].value;
6368
param.type = valuesObject[paramIndex].type;
6469
// TODO(miguelaeh): Hack to avoid render parameters with dots in keys into the schema.
6570
// Must be removed once fixed

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function createValuesObject(valuesFilePath) {
170170
// The existence check is needed to avoid duplicate plain array keys
171171
if (!resultValues.find((v) => v.name === valuePath)) {
172172
const param = new Parameter(valuePath);
173-
param.value = value;
173+
if (!param.value) param.value = value;
174174
param.type = type;
175175
resultValues.push(param);
176176
param.schema = renderInSchema;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitnami/readme-generator-for-helm",
3-
"version": "2.5.2",
3+
"version": "2.6.0",
44
"description": "Autogenerate READMEs tables and OpenAPI schemas for Helm Charts",
55
"main": "index.js",
66
"scripts": {

tests/expected-readme.first-execution.md

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,48 @@ It even supports multiple lines and [Link parsing](#common-parameters).
2929

3030
This description starts in a new line instead of the same line of description start tag. It does not have multiple lines.
3131

32-
| Name | Description | Value |
33-
| ---------------------------------------- | --------------------------------------------------- | ---------------------- |
34-
| `image.registry` | Kubewatch image registry | `docker.io` |
35-
| `image.repository` | Kubewatch image name | `bitnami/kubewatch` |
36-
| `image.tag` | Kubewatch image tag | `0.1.0-debian-10-r162` |
37-
| `image.pullPolicy` | Kubewatch image tag | `IfNotPresent` |
38-
| `image.pullSecrets` | Specify docker-registry secret names as an array | `[]` |
39-
| `slack.enabled` | Enable Slack notifications | `true` |
40-
| `slack.channel` | Slack channel to notify | `XXXX` |
41-
| `slack.token` | Slack API token | `XXXX` |
42-
| `hipchat.enabled` | Enable HipChat notifications | `false` |
43-
| `hipchat.room` | HipChat room to notify | `""` |
44-
| `hipchat.token` | HipChat token | `""` |
45-
| `hipchat.url` | HipChat URL | `""` |
46-
| `mattermost.enabled` | Enable Mattermost notifications | `false` |
47-
| `mattermost.channel` | Mattermost channel to notify | `""` |
48-
| `mattermost.username` | Mattermost user to notify | `""` |
49-
| `mattermost.url` | Mattermost URL | `""` |
50-
| `flock.enabled` | Enable Flock notifications | `false` |
51-
| `flock.url` | Flock URL | `""` |
52-
| `msteams.enabled` | Enable Microsoft Teams notifications | `false` |
53-
| `msteams.webhookurl` | Microsoft Teams webhook URL | `""` |
54-
| `webhook` | Enable Webhook notifications | `{}` |
55-
| `smtp.enabled` | Enable SMTP (email) notifications | `false` |
56-
| `smtp.to` | Destination email address (required) | `""` |
57-
| `smtp.from` | Source email address (required) | `""` |
58-
| `smtp.hello` | SMTP hello field (optional) | `""` |
59-
| `smtp.smarthost` | SMTP server address (name:port) (required) | `""` |
60-
| `smtp.subject` | SMTP subject for the email | `""` |
61-
| `smtp.requireTLS` | Force STARTTLS | `false` |
62-
| `smtp.auth.username` | Username for LOGIN and PLAIN auth mech | `""` |
63-
| `smtp.auth.password` | Password for LOGIN and PLAIN auth mech | `""` |
64-
| `smtp.auth.secret` | Secret for CRAM-MD5 auth mech | `""` |
65-
| `smtp.auth.identity` | Identity for PLAIN auth mech | `""` |
66-
| `namespaceToWatch` | Namespace to watch, leave it empty for watching all | `""` |
67-
| `resourcesToWatch.pod` | Watch changes to Pods | `true` |
68-
| `resourcesToWatch.deployment` | Watch changes to Deployments | `true` |
69-
| `resourcesToWatch.replicationcontroller` | Watch changes to ReplicationControllers | `false` |
70-
| `resourcesToWatch.replicaset` | Watch changes to ReplicaSets | `false` |
71-
| `resourcesToWatch.daemonset` | Watch changes to DaemonSets | `false` |
72-
| `resourcesToWatch.services` | Watch changes to Services | `false` |
73-
| `resourcesToWatch.job` | Watch changes to Jobs | `false` |
74-
| `resourcesToWatch.persistentvolume` | Watch changes to PersistentVolumes | `false` |
32+
| Name | Description | Value |
33+
| ---------------------------------------- | --------------------------------------------------- | --------------------------- |
34+
| `image.registry` | Kubewatch image registry | `REGISTRY_NAME` |
35+
| `image.repository` | Kubewatch image name | `REPOSITORY_NAME/kubewatch` |
36+
| `image.pullPolicy` | Kubewatch image pull policy | `IfNotPresent` |
37+
| `image.pullSecrets` | Specify docker-registry secret names as an array | `[]` |
38+
| `slack.enabled` | Enable Slack notifications | `true` |
39+
| `slack.channel` | Slack channel to notify | `XXXX` |
40+
| `slack.token` | Slack API token | `XXXX` |
41+
| `hipchat.enabled` | Enable HipChat notifications | `false` |
42+
| `hipchat.room` | HipChat room to notify | `""` |
43+
| `hipchat.token` | HipChat token | `""` |
44+
| `hipchat.url` | HipChat URL | `""` |
45+
| `mattermost.enabled` | Enable Mattermost notifications | `false` |
46+
| `mattermost.channel` | Mattermost channel to notify | `""` |
47+
| `mattermost.username` | Mattermost user to notify | `""` |
48+
| `mattermost.url` | Mattermost URL | `""` |
49+
| `flock.enabled` | Enable Flock notifications | `false` |
50+
| `flock.url` | Flock URL | `""` |
51+
| `msteams.enabled` | Enable Microsoft Teams notifications | `false` |
52+
| `msteams.webhookurl` | Microsoft Teams webhook URL | `""` |
53+
| `webhook` | Enable Webhook notifications | `{}` |
54+
| `smtp.enabled` | Enable SMTP (email) notifications | `false` |
55+
| `smtp.to` | Destination email address (required) | `""` |
56+
| `smtp.from` | Source email address (required) | `""` |
57+
| `smtp.hello` | SMTP hello field (optional) | `""` |
58+
| `smtp.smarthost` | SMTP server address (name:port) (required) | `""` |
59+
| `smtp.subject` | SMTP subject for the email | `""` |
60+
| `smtp.requireTLS` | Force STARTTLS | `false` |
61+
| `smtp.auth.username` | Username for LOGIN and PLAIN auth mech | `""` |
62+
| `smtp.auth.password` | Password for LOGIN and PLAIN auth mech | `""` |
63+
| `smtp.auth.secret` | Secret for CRAM-MD5 auth mech | `""` |
64+
| `smtp.auth.identity` | Identity for PLAIN auth mech | `""` |
65+
| `namespaceToWatch` | Namespace to watch, leave it empty for watching all | `""` |
66+
| `resourcesToWatch.pod` | Watch changes to Pods | `true` |
67+
| `resourcesToWatch.deployment` | Watch changes to Deployments | `true` |
68+
| `resourcesToWatch.replicationcontroller` | Watch changes to ReplicationControllers | `false` |
69+
| `resourcesToWatch.replicaset` | Watch changes to ReplicaSets | `false` |
70+
| `resourcesToWatch.daemonset` | Watch changes to DaemonSets | `false` |
71+
| `resourcesToWatch.services` | Watch changes to Services | `false` |
72+
| `resourcesToWatch.job` | Watch changes to Jobs | `false` |
73+
| `resourcesToWatch.persistentvolume` | Watch changes to PersistentVolumes | `false` |
7574

7675
### Deployment parameters
7776

0 commit comments

Comments
 (0)