Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a default value for a parameter using the modifier #78

Merged
merged 7 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Currently supported modifiers:
- `[object]` Indicates that the value of the parameter must be set to `{}`.
- `[string]` Indicates that the value of the parameter must be set to `""`.
- `[nullable]` Indicates that the parameter value can be set to `null`.
- `[default: DEFAULT_VALUE]` Sets the default value to `DEFAULT_VALUE`.

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

Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"array": "array",
"object": "object",
"string": "string",
"nullable": "nullable"
"nullable": "nullable",
"default": "default"
},
"regexp": {
"paramsSectionTitle": "Parameters"
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function runReadmeGenerator(options) {
}

if (schemaFilePath) {
parsedMetadata.parameters = buildParamsToRenderList(parsedMetadata.parameters, config);
renderOpenAPISchema(schemaFilePath, parsedMetadata.parameters, config);
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function applyModifiers(param, config) {
// unless another modifier is applied at the same time. In that case, the second
// modifier specifies the default value.
break;
case modifier.match(new RegExp(`${config.modifiers.default}:.*`))?.input: {
const defaultSpacesRegex = `${config.modifiers.default}:\\s*`;
param.value = modifier.replace(new RegExp(defaultSpacesRegex), '');
break;
}
default:
throw new Error(`Unknown modifier: ${modifier} for parameter ${param.name}`);
}
Expand All @@ -58,8 +63,8 @@ function combineMetadataAndValues(valuesObject, valuesMetadata) {
if (!param.extra) {
const paramIndex = valuesObject.findIndex((e) => e.name === param.name);
if (paramIndex !== -1) {
// Set the value from actual object
param.value = valuesObject[paramIndex].value;
// Set the value from actual object if not set before
if (!param.value) param.value = valuesObject[paramIndex].value;
param.type = valuesObject[paramIndex].type;
// TODO(miguelaeh): Hack to avoid render parameters with dots in keys into the schema.
// Must be removed once fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function createValuesObject(valuesFilePath) {
// The existence check is needed to avoid duplicate plain array keys
if (!resultValues.find((v) => v.name === valuePath)) {
const param = new Parameter(valuePath);
param.value = value;
if (!param.value) param.value = value;
param.type = type;
resultValues.push(param);
param.schema = renderInSchema;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitnami/readme-generator-for-helm",
"version": "2.5.2",
"version": "2.6.0",
"description": "Autogenerate READMEs tables and OpenAPI schemas for Helm Charts",
"main": "index.js",
"scripts": {
Expand Down
85 changes: 42 additions & 43 deletions tests/expected-readme.first-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,48 @@ It even supports multiple lines and [Link parsing](#common-parameters).

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

| Name | Description | Value |
| ---------------------------------------- | --------------------------------------------------- | ---------------------- |
| `image.registry` | Kubewatch image registry | `docker.io` |
| `image.repository` | Kubewatch image name | `bitnami/kubewatch` |
| `image.tag` | Kubewatch image tag | `0.1.0-debian-10-r162` |
| `image.pullPolicy` | Kubewatch image tag | `IfNotPresent` |
| `image.pullSecrets` | Specify docker-registry secret names as an array | `[]` |
| `slack.enabled` | Enable Slack notifications | `true` |
| `slack.channel` | Slack channel to notify | `XXXX` |
| `slack.token` | Slack API token | `XXXX` |
| `hipchat.enabled` | Enable HipChat notifications | `false` |
| `hipchat.room` | HipChat room to notify | `""` |
| `hipchat.token` | HipChat token | `""` |
| `hipchat.url` | HipChat URL | `""` |
| `mattermost.enabled` | Enable Mattermost notifications | `false` |
| `mattermost.channel` | Mattermost channel to notify | `""` |
| `mattermost.username` | Mattermost user to notify | `""` |
| `mattermost.url` | Mattermost URL | `""` |
| `flock.enabled` | Enable Flock notifications | `false` |
| `flock.url` | Flock URL | `""` |
| `msteams.enabled` | Enable Microsoft Teams notifications | `false` |
| `msteams.webhookurl` | Microsoft Teams webhook URL | `""` |
| `webhook` | Enable Webhook notifications | `{}` |
| `smtp.enabled` | Enable SMTP (email) notifications | `false` |
| `smtp.to` | Destination email address (required) | `""` |
| `smtp.from` | Source email address (required) | `""` |
| `smtp.hello` | SMTP hello field (optional) | `""` |
| `smtp.smarthost` | SMTP server address (name:port) (required) | `""` |
| `smtp.subject` | SMTP subject for the email | `""` |
| `smtp.requireTLS` | Force STARTTLS | `false` |
| `smtp.auth.username` | Username for LOGIN and PLAIN auth mech | `""` |
| `smtp.auth.password` | Password for LOGIN and PLAIN auth mech | `""` |
| `smtp.auth.secret` | Secret for CRAM-MD5 auth mech | `""` |
| `smtp.auth.identity` | Identity for PLAIN auth mech | `""` |
| `namespaceToWatch` | Namespace to watch, leave it empty for watching all | `""` |
| `resourcesToWatch.pod` | Watch changes to Pods | `true` |
| `resourcesToWatch.deployment` | Watch changes to Deployments | `true` |
| `resourcesToWatch.replicationcontroller` | Watch changes to ReplicationControllers | `false` |
| `resourcesToWatch.replicaset` | Watch changes to ReplicaSets | `false` |
| `resourcesToWatch.daemonset` | Watch changes to DaemonSets | `false` |
| `resourcesToWatch.services` | Watch changes to Services | `false` |
| `resourcesToWatch.job` | Watch changes to Jobs | `false` |
| `resourcesToWatch.persistentvolume` | Watch changes to PersistentVolumes | `false` |
| Name | Description | Value |
| ---------------------------------------- | --------------------------------------------------- | --------------------------- |
| `image.registry` | Kubewatch image registry | `REGISTRY_NAME` |
| `image.repository` | Kubewatch image name | `REPOSITORY_NAME/kubewatch` |
| `image.pullPolicy` | Kubewatch image pull policy | `IfNotPresent` |
| `image.pullSecrets` | Specify docker-registry secret names as an array | `[]` |
| `slack.enabled` | Enable Slack notifications | `true` |
| `slack.channel` | Slack channel to notify | `XXXX` |
| `slack.token` | Slack API token | `XXXX` |
| `hipchat.enabled` | Enable HipChat notifications | `false` |
| `hipchat.room` | HipChat room to notify | `""` |
| `hipchat.token` | HipChat token | `""` |
| `hipchat.url` | HipChat URL | `""` |
| `mattermost.enabled` | Enable Mattermost notifications | `false` |
| `mattermost.channel` | Mattermost channel to notify | `""` |
| `mattermost.username` | Mattermost user to notify | `""` |
| `mattermost.url` | Mattermost URL | `""` |
| `flock.enabled` | Enable Flock notifications | `false` |
| `flock.url` | Flock URL | `""` |
| `msteams.enabled` | Enable Microsoft Teams notifications | `false` |
| `msteams.webhookurl` | Microsoft Teams webhook URL | `""` |
| `webhook` | Enable Webhook notifications | `{}` |
| `smtp.enabled` | Enable SMTP (email) notifications | `false` |
| `smtp.to` | Destination email address (required) | `""` |
| `smtp.from` | Source email address (required) | `""` |
| `smtp.hello` | SMTP hello field (optional) | `""` |
| `smtp.smarthost` | SMTP server address (name:port) (required) | `""` |
| `smtp.subject` | SMTP subject for the email | `""` |
| `smtp.requireTLS` | Force STARTTLS | `false` |
| `smtp.auth.username` | Username for LOGIN and PLAIN auth mech | `""` |
| `smtp.auth.password` | Password for LOGIN and PLAIN auth mech | `""` |
| `smtp.auth.secret` | Secret for CRAM-MD5 auth mech | `""` |
| `smtp.auth.identity` | Identity for PLAIN auth mech | `""` |
| `namespaceToWatch` | Namespace to watch, leave it empty for watching all | `""` |
| `resourcesToWatch.pod` | Watch changes to Pods | `true` |
| `resourcesToWatch.deployment` | Watch changes to Deployments | `true` |
| `resourcesToWatch.replicationcontroller` | Watch changes to ReplicationControllers | `false` |
| `resourcesToWatch.replicaset` | Watch changes to ReplicaSets | `false` |
| `resourcesToWatch.daemonset` | Watch changes to DaemonSets | `false` |
| `resourcesToWatch.services` | Watch changes to Services | `false` |
| `resourcesToWatch.job` | Watch changes to Jobs | `false` |
| `resourcesToWatch.persistentvolume` | Watch changes to PersistentVolumes | `false` |

### Deployment parameters

Expand Down
Loading