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

binding config schema validation for unused properties #929

Merged
merged 11 commits into from
Apr 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ bindings:
app0:
type: grpc
kind: client
options:
services:
- protobuf/echo.proto
routes:
- exit: net0
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ bindings:
app0:
type: grpc
kind: client
options:
services:
- protobuf/echo.proto
routes:
- exit: net0
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@
"enum": [ "server", "client"]
},
"vault": false,
"options":
{
"properties":
{
"services":
{
"title": "Services",
"type": "array",
"items":
{
"title": "Service",
"type": "string"
},
"deprecated": true
}
},
"additionalProperties": false
},
"routes":
{
"items":
Expand Down Expand Up @@ -115,6 +97,46 @@
"routes"
]
}
],
"oneOf":
[
{
"properties":
{
"kind":
{
"const": "server"
},
"options":
{
"properties":
{
"services":
{
"title": "Services",
"type": "array",
"items":
{
"title": "Service",
"type": "string"
},
"deprecated": true
}
},
"additionalProperties": false
}
}
},
{
"properties":
{
"kind":
{
"const": "client"
},
"options": false
}
}
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SchemaTest
public final ConfigSchemaRule schema = new ConfigSchemaRule()
.schemaPatch("io/aklivity/zilla/specs/binding/grpc/schema/grpc.schema.patch.json")
.schemaPatch("io/aklivity/zilla/specs/engine/schema/guard/test.schema.patch.json")
.schemaPatch("io/aklivity/zilla/specs/engine/schema/catalog/test.schema.patch.json")
.configurationRoot("io/aklivity/zilla/specs/binding/grpc/config");

@Test
Expand All @@ -48,4 +49,36 @@ public void shouldValidateClient()

assertThat(config, not(nullValue()));
}

@Test
public void shouldValidateClientWhen()
{
JsonObject config = schema.validate("client.when.yaml");

assertThat(config, not(nullValue()));
}

@Test
public void shouldValidateServerWhenBinaryMetadata()
{
JsonObject config = schema.validate("server.when.binary.metadata.yaml");

assertThat(config, not(nullValue()));
}

@Test
public void shouldValidateClientWhenBinaryMetadata()
{
JsonObject config = schema.validate("client.when.binary.metadata.yaml");

assertThat(config, not(nullValue()));
}

@Test
public void shouldValidateServerWhenCatalog()
{
JsonObject config = schema.validate("server.when.catalog.yaml");

assertThat(config, not(nullValue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,35 @@
"routes"
]
}
],
"oneOf":
[
{
"properties":
{
"kind":
{
"const": "server"
}
}
},
{
"properties":
{
"kind":
{
"const": "client"
},
"options":
{
"properties":
{
"access-control": false,
"authorization": false
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that server options are a superset of client options, is there not a way to specify the common subset once, and then conditionally include the additional options properties for server?

]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SchemaTest
public final ConfigSchemaRule schema = new ConfigSchemaRule()
.schemaPatch("io/aklivity/zilla/specs/binding/http/schema/http.schema.patch.json")
.schemaPatch("io/aklivity/zilla/specs/engine/schema/guard/test.schema.patch.json")
.schemaPatch("io/aklivity/zilla/specs/engine/schema/model/test.schema.patch.json")
.configurationRoot("io/aklivity/zilla/specs/binding/http/config");

@Test
Expand Down Expand Up @@ -170,6 +171,14 @@ public void shouldValidateHttp2Client()
assertThat(config, not(nullValue()));
}

@Test
public void shouldValidateHttp2ClientWithValidation()
{
JsonObject config = schema.validate("v2/client.validation.yaml");

assertThat(config, not(nullValue()));
}

@Test
public void shouldValidateHttp2ClientOverride()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ bindings:
app0:
type: kafka
kind: cache_client
options:
merged:
- test
routes:
- exit: cache0
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@ bindings:
options:
servers:
- localhost:9092
merged:
- test
exit: net0
Loading