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

String Validator improvement to support OpenAPI & AsyncAPI specs #873

Merged
merged 7 commits into from
Apr 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ bindings:
method: GET
params:
query:
limit:
model: int32
limit: int32
- path: /items
method: POST
content:
Expand Down Expand Up @@ -111,8 +110,7 @@ bindings:
content-type:
- application/json
headers:
x-pages:
model: int32
x-pages: int32
x-next: string
content:
model: json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ bindings:
method: GET
params:
query:
limit:
model: int32
limit: int32
- path: /items
method: POST
content:
Expand All @@ -38,14 +37,12 @@ bindings:
- path: "/items/{id}"
method: PUT
headers:
hello:
model: int32
hello: int32
params:
path:
id: string
query:
limit:
model: int32
limit: int32
ciao: string
- path: "/items/{id}"
method: DELETE
Expand Down Expand Up @@ -90,8 +87,7 @@ bindings:
content-type:
- application/json
headers:
x-pages:
model: int32
x-pages: int32
x-next: string
content:
model: json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"op": "add",
"path": "/$defs/converter/types/enum/-",
"path": "/$defs/types/enum/-",
"value": "avro"
},
{
"op": "add",
"path": "/$defs/converter/allOf/-",
"path": "/$defs/converter/oneOf/1/allOf/-",
"value":
{
"if":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,5 @@ bindings:
kind: server
type: test
options:
value:
model: int64
format: text
max: 1234
min: -1234
exclusiveMax: true
exclusiveMin: true
multiple: 10
value: int64
exit: test
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ bindings:
value:
model: string
encoding: utf_8
maxLength: 5
minLength: 1
exit: test
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"op": "add",
"path": "/$defs/converter/types/enum/-",
"path": "/$defs/types/enum/-",
"value": "int32"
},
{
"op": "add",
"path": "/$defs/converter/allOf/-",
"path": "/$defs/converter/oneOf/1/allOf/-",
"value":
{
"if":
Expand Down Expand Up @@ -66,12 +66,7 @@
},
{
"op": "add",
"path": "/$defs/validator/types/enum/-",
"value": "int32"
},
{
"op": "add",
"path": "/$defs/validator/allOf/-",
"path": "/$defs/validator/oneOf/1/allOf/-",
"value":
{
"if":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"op": "add",
"path": "/$defs/converter/types/enum/-",
"path": "/$defs/types/enum/-",
"value": "int64"
},
{
"op": "add",
"path": "/$defs/converter/allOf/-",
"path": "/$defs/converter/oneOf/1/allOf/-",
"value":
{
"if":
Expand Down Expand Up @@ -66,12 +66,7 @@
},
{
"op": "add",
"path": "/$defs/validator/types/enum/-",
"value": "int64"
},
{
"op": "add",
"path": "/$defs/validator/allOf/-",
"path": "/$defs/validator/oneOf/1/allOf/-",
"value":
{
"if":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"op": "add",
"path": "/$defs/converter/types/enum/-",
"path": "/$defs/types/enum/-",
"value": "string"
},
{
"op": "add",
"path": "/$defs/converter/allOf/-",
"path": "/$defs/converter/oneOf/1/allOf/-",
"value":
{
"if":
Expand Down Expand Up @@ -35,6 +35,20 @@
"utf_8",
"utf_16"
]
},
"minLength":
{
"type": "integer",
"minimum": 1
},
"maxLength":
{
"type": "integer",
"minimum": 1
},
"pattern":
{
"type": "string"
}
},
"additionalProperties": false
Expand All @@ -43,12 +57,7 @@
},
{
"op": "add",
"path": "/$defs/validator/types/enum/-",
"value": "string"
},
{
"op": "add",
"path": "/$defs/validator/allOf/-",
"path": "/$defs/validator/oneOf/1/allOf/-",
"value":
{
"if":
Expand Down Expand Up @@ -76,6 +85,20 @@
[
"utf_8"
]
},
"minLength":
{
"type": "integer",
"minimum": 1
},
"maxLength":
{
"type": "integer",
"minimum": 1
},
"pattern":
{
"type": "string"
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.specs.model.core.config;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

import jakarta.json.JsonObject;

import org.junit.Rule;
import org.junit.Test;

import io.aklivity.zilla.specs.engine.config.ConfigSchemaRule;

public class Int64SchemaTest
{
@Rule
public final ConfigSchemaRule schema = new ConfigSchemaRule()
.schemaPatch("io/aklivity/zilla/specs/engine/schema/binding/test.schema.patch.json")
.schemaPatch("io/aklivity/zilla/specs/model/core/schema/int64.schema.patch.json")
.configurationRoot("io/aklivity/zilla/specs/model/core/config");

@Test
public void shouldValidateCatalog()
{
JsonObject config = schema.validate("int64.model.yaml");

assertThat(config, not(nullValue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public Int64ModelConfigBuilder<T> exclusiveMin(
public T build()
{
String format = this.format != null ? this.format : DEFAULT_FORMAT;
long max = this.max != null ? this.max : Integer.MAX_VALUE;
long min = this.min != null ? this.min : Integer.MIN_VALUE;
long max = this.max != null ? this.max : Long.MAX_VALUE;
long min = this.min != null ? this.min : Long.MIN_VALUE;
long multiple = this.multiple != null ? this.multiple : DEFAULT_MULTIPLE;
boolean exclusiveMax = this.exclusiveMax != null ? this.exclusiveMax : false;
boolean exclusiveMin = this.exclusiveMin != null ? this.exclusiveMin : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@

public final class StringModelConfig extends ModelConfig
{
public static final String DEFAULT_ENCODING = "utf_8";

public final String encoding;
public final String pattern;
public final int maxLength;
public final int minLength;

public StringModelConfig(
String encoding)
String encoding,
String pattern,
int maxLength,
int minLength)
{
super("string");
this.encoding = encoding != null ? encoding : DEFAULT_ENCODING;
this.encoding = encoding;
this.pattern = pattern;
this.maxLength = maxLength;
this.minLength = minLength;

}

public static <T> StringModelConfigBuilder<T> builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@

public class StringModelConfigBuilder<T> extends ConfigBuilder<T, StringModelConfigBuilder<T>>
{
public static final String DEFAULT_ENCODING = "utf_8";

private final Function<StringModelConfig, T> mapper;

private String encoding;
private String pattern;
private int maxLength;
private int minLength;

StringModelConfigBuilder(
Function<StringModelConfig, T> mapper)
Expand All @@ -44,9 +49,31 @@ public StringModelConfigBuilder<T> encoding(
return this;
}

public StringModelConfigBuilder<T> pattern(
String pattern)
{
this.pattern = pattern;
return this;
}

public StringModelConfigBuilder<T> maxLength(
int maxLength)
{
this.maxLength = maxLength;
return this;
}

public StringModelConfigBuilder<T> minLength(
int minLength)
{
this.minLength = minLength;
return this;
}

@Override
public T build()
{
return mapper.apply(new StringModelConfig(encoding));
String encoding = this.encoding != null ? this.encoding : DEFAULT_ENCODING;
return mapper.apply(new StringModelConfig(encoding, pattern, maxLength, minLength));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.model.core.internal;

public final class StringState
{
public int processed;
public int length;
}
Loading
Loading