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

add number modifier to default configuration #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Currently supported modifiers:
- `[array]` Indicates that the value of the parameter must be set to `[]`.
- `[object]` Indicates that the value of the parameter must be set to `{}`.
- `[string]` Indicates that the value of the parameter must be set to `""`.
- `[number]` Indicates that the value of the parameter must be set to a number (ex. `0`).
- `[nullable]` Indicates that the parameter value can be set to `null`.
- `[default: DEFAULT_VALUE]` Sets the default value to `DEFAULT_VALUE`.

Expand All @@ -141,10 +142,10 @@ Custom configuration snippet:
...
"modifiers": {
"array": "array",
"object": "object"
"string": "string"
"nullable": "nullable",
"number": "number"
"object": "object",
"string": "string",
"number": "number",
"nullable": "nullable"
},
...
}
Expand All @@ -169,9 +170,10 @@ The configuration file has the following structure:
},
"modifiers": {
"array": "array", <-- Modifier that indicates an array type
"object": "object" <-- Modifier that indicates an object type
"string": "string" <-- Modifier that indicates a string type
"nullable": "nullable" <-- Modifier that indicates a parameter that can be set to null
"object": "object", <-- Modifier that indicates an object type
"string": "string", <-- Modifier that indicates a string type
"number": "number", <-- Modifier that indicates a number type
"nullable": "nullable" <-- Modifier that indicates a parameter that can be set to null
},
"regexp": {
"paramsSectionTitle": "Parameters" <-- Title of the parameters section to replace in the README.md
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"array": "array",
"object": "object",
"string": "string",
"number": "number",
"nullable": "nullable",
"default": "default"
},
Expand Down
2 changes: 2 additions & 0 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function applyModifiers(param, config) {
case `${config.modifiers.string}`:
param.value = '""';
break;
case `${config.modifiers.number}`:
break;
case `${config.modifiers.nullable}`:
// Do nothing since the nullable parameters must preserve its default value
// unless another modifier is applied at the same time. In that case, the second
Expand Down
3 changes: 3 additions & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ function renderOpenAPISchema(schemaFilePath, parametersList, config) {
case `${config.modifiers.string}`:
p.type = 'string';
break;
case `${config.modifiers.number}`:
p.type = 'number';
break;
default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions 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.6.1",
"version": "2.7.0",
"description": "Autogenerate READMEs tables and OpenAPI schemas for Helm Charts",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions tests/expected-readme.first-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ This description starts in a new line instead of the same line of description st
| `serviceAccount.name` | Name of the created ServiceAccount | `""` |
| `inventedArray` | Test parameter to check arrays | `["a","b"]` |
| `arrayModifier` | Test parameter for modifier array | `[]` |
| `numberModifier` | Test parameter for modifier number | `0` |
| `configuration` | haproxy configuration | `""` |
| `jobs[0].nameOverride` | String to partially override jobs.names.fullname | `""` |
| `jobs[0].fullnameOverride` | String to fully override jobs.names.fullname | `""` |
Expand All @@ -137,6 +138,7 @@ This description starts in a new line instead of the same line of description st
| `nullableNullStringWithValueChange` | Nullable null string. We apply string modifier that will change the type and value, but the schema will show `nullable: true`. | `""` |
| `nullableNullArray` | Nullable null array. We apply array modifier that will change the type in the schema plus `nullable: true`. | `nil` |
| `nullableNullString` | Nullable null string. We apply string modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNullNumber` | Nullable null number. We apply number modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNotNull` | Nullable parameter with a non null value | `somestring` |
| `nullableObject` | Nullable parameter with an object value | `{}` |
| `nullableArray` | Nullable parameter with an array value | `[]` |
Expand Down
2 changes: 2 additions & 0 deletions tests/expected-readme.last-section-text-below.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ This description starts in a new line instead of the same line of description st
| `serviceAccount.name` | Name of the created ServiceAccount | `""` |
| `inventedArray` | Test parameter to check arrays | `["a","b"]` |
| `arrayModifier` | Test parameter for modifier array | `[]` |
| `numberModifier` | Test parameter for modifier number | `0` |
| `configuration` | haproxy configuration | `""` |
| `jobs[0].nameOverride` | String to partially override jobs.names.fullname | `""` |
| `jobs[0].fullnameOverride` | String to fully override jobs.names.fullname | `""` |
Expand All @@ -175,6 +176,7 @@ This description starts in a new line instead of the same line of description st
| `nullableNullStringWithValueChange` | Nullable null string. We apply string modifier that will change the type and value, but the schema will show `nullable: true`. | `""` |
| `nullableNullArray` | Nullable null array. We apply array modifier that will change the type in the schema plus `nullable: true`. | `nil` |
| `nullableNullString` | Nullable null string. We apply string modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNullNumber` | Nullable null number. We apply number modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNotNull` | Nullable parameter with a non null value | `somestring` |
| `nullableObject` | Nullable parameter with an object value | `{}` |
| `nullableArray` | Nullable parameter with an array value | `[]` |
Expand Down
2 changes: 2 additions & 0 deletions tests/expected-readme.last-section.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ This description starts in a new line instead of the same line of description st
| `serviceAccount.name` | Name of the created ServiceAccount | `""` |
| `inventedArray` | Test parameter to check arrays | `["a","b"]` |
| `arrayModifier` | Test parameter for modifier array | `[]` |
| `numberModifier` | Test parameter for modifier number | `0` |
| `configuration` | haproxy configuration | `""` |
| `jobs[0].nameOverride` | String to partially override jobs.names.fullname | `""` |
| `jobs[0].fullnameOverride` | String to fully override jobs.names.fullname | `""` |
Expand All @@ -175,6 +176,7 @@ This description starts in a new line instead of the same line of description st
| `nullableNullStringWithValueChange` | Nullable null string. We apply string modifier that will change the type and value, but the schema will show `nullable: true`. | `""` |
| `nullableNullArray` | Nullable null array. We apply array modifier that will change the type in the schema plus `nullable: true`. | `nil` |
| `nullableNullString` | Nullable null string. We apply string modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNullNumber` | Nullable null number. We apply number modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNotNull` | Nullable parameter with a non null value | `somestring` |
| `nullableObject` | Nullable parameter with an object value | `{}` |
| `nullableArray` | Nullable parameter with an array value | `[]` |
Expand Down
2 changes: 2 additions & 0 deletions tests/expected-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ This description starts in a new line instead of the same line of description st
| `serviceAccount.name` | Name of the created ServiceAccount | `""` |
| `inventedArray` | Test parameter to check arrays | `["a","b"]` |
| `arrayModifier` | Test parameter for modifier array | `[]` |
| `numberModifier` | Test parameter for modifier number | `0` |
| `configuration` | haproxy configuration | `""` |
| `jobs[0].nameOverride` | String to partially override jobs.names.fullname | `""` |
| `jobs[0].fullnameOverride` | String to fully override jobs.names.fullname | `""` |
Expand All @@ -175,6 +176,7 @@ This description starts in a new line instead of the same line of description st
| `nullableNullStringWithValueChange` | Nullable null string. We apply string modifier that will change the type and value, but the schema will show `nullable: true`. | `""` |
| `nullableNullArray` | Nullable null array. We apply array modifier that will change the type in the schema plus `nullable: true`. | `nil` |
| `nullableNullString` | Nullable null string. We apply string modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNullNumber` | Nullable null number. We apply number modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNotNull` | Nullable parameter with a non null value | `somestring` |
| `nullableObject` | Nullable parameter with an object value | `{}` |
| `nullableArray` | Nullable parameter with an array value | `[]` |
Expand Down
11 changes: 11 additions & 0 deletions tests/expected-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@
"type": "string"
}
},
"numberModifier": {
"type": "number",
"description": "Test parameter for modifier number",
"default": 0
},
"configuration": {
"type": "string",
"description": "haproxy configuration",
Expand Down Expand Up @@ -689,6 +694,12 @@
"default": null,
"nullable": true
},
"nullableNullNumber": {
"type": "number",
"description": "Nullable null number. We apply number modifier to avoid infering an object type. The null must be preverved as value.",
"default": null,
"nullable": true
},
"nullableNotNull": {
"type": "string",
"description": "Nullable parameter with a non null value",
Expand Down
2 changes: 2 additions & 0 deletions tests/test-readme.last-section-text-below.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ This description starts in a new line instead of the same line of description st
| `serviceAccount.name` | Name of the created ServiceAccount | `""` |
| `inventedArray` | Test parameter to check arrays | `["a","b"]` |
| `arrayModifier` | Test parameter for modifier array | `[]` |
| `numberModifier` | Test parameter for modifier number | `0` |
| `configuration` | haproxy configuration | `""` |
| `jobs[0].nameOverride` | String to partially override jobs.names.fullname | `""` |
| `jobs[0].fullnameOverride` | String to fully override jobs.names.fullname | `""` |
Expand All @@ -175,6 +176,7 @@ This description starts in a new line instead of the same line of description st
| `nullableNullStringWithValueChange` | Nullable null string. We apply string modifier that will change the type and value, but the schema will show `nullable: true`. | `""` |
| `nullableNullArray` | Nullable null array. We apply array modifier that will change the type in the schema plus `nullable: true`. | `nil` |
| `nullableNullString` | Nullable null string. We apply string modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNullNumber` | Nullable null number. We apply number modifier to avoid infering an object type. The null must be preverved as value. | `nil` |
| `nullableNotNull` | Nullable parameter with a non null value | `somestring` |
| `nullableObject` | Nullable parameter with an object value | `{}` |
| `nullableArray` | Nullable parameter with an array value | `[]` |
Expand Down
Loading
Loading