Skip to content

Commit

Permalink
Read everything when no properties specified
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Jul 19, 2023
1 parent 39a8a65 commit ca2c7f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function extractNested(properties, data) {
Object.entries(properties).forEach(([name, propSchema]) => {
if (propSchema.type === 'object') {
propSchema.default ||= {};
propSchema.additionalProperties = false;

const possibles = Object.keys(data).filter((key) =>
key.startsWith(`${name}_`),
Expand All @@ -63,6 +62,7 @@ function extractNested(properties, data) {
}

if (propSchema.properties) {
propSchema.additionalProperties = false;
extractNested(propSchema.properties, data[name]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nested-env-schema",
"version": "1.0.0",
"version": "1.0.1",
"description": "Validate & extract your env variables using nested JSON schema, Ajv and dotenv",
"main": "lib/index.js",
"types": "types/index.d.ts",
Expand Down
19 changes: 19 additions & 0 deletions test/nested.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ const tests = [
},
},
},
{
name: 'simple nested object - ok - without properties',
schema: {
type: 'object',
properties: {
K8S: {
type: 'object',
},
},
},
isOk: true,
confExpected: {
K8S: {
NAMESPACE: 'pippo',
CLUSTER_ID: 'pluto',
CLUSTER_PASS: 'neptune',
},
},
},
];

tests.forEach(function (testConf) {
Expand Down

0 comments on commit ca2c7f3

Please sign in to comment.