Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
WIP config
  • Loading branch information
attilakreiner committed Jan 17, 2024
commit b0e961ea5f65863b017927733cf096ff92081af7
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum Method
public final List<HttpParamConfig> pathParams;
public final List<HttpParamConfig> queryParams;
public final ValidatorConfig content;
public final List<HttpResponseConfig> responses;

public HttpRequestConfig(
String path,
Expand All @@ -50,7 +51,8 @@ public HttpRequestConfig(
List<HttpParamConfig> headers,
List<HttpParamConfig> pathParams,
List<HttpParamConfig> queryParams,
ValidatorConfig content)
ValidatorConfig content,
List<HttpResponseConfig> responses)
{
this.path = path;
this.method = method;
Expand All @@ -59,6 +61,7 @@ public HttpRequestConfig(
this.pathParams = pathParams;
this.queryParams = queryParams;
this.content = content;
this.responses = responses;
}

public static HttpRequestConfigBuilder<HttpRequestConfig> builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class HttpRequestConfigBuilder<T> extends ConfigBuilder<T, HttpRequestCon
private List<HttpParamConfig> pathParams;
private List<HttpParamConfig> queryParams;
private ValidatorConfig content;
private List<HttpResponseConfig> responses;

HttpRequestConfigBuilder(
Function<HttpRequestConfig, T> mapper)
Expand Down Expand Up @@ -120,6 +121,12 @@ public HttpRequestConfigBuilder<T> pathParam(
return this;
}

public HttpParamConfigBuilder<HttpRequestConfigBuilder<T>> pathParam()
{
return new HttpParamConfigBuilder<>(this::pathParam);
}


public HttpParamConfigBuilder<HttpRequestConfigBuilder<T>> queryParam()
{
return new HttpParamConfigBuilder<>(this::queryParam);
Expand All @@ -143,11 +150,6 @@ public HttpRequestConfigBuilder<T> queryParam(
return this;
}

public HttpParamConfigBuilder<HttpRequestConfigBuilder<T>> pathParam()
{
return new HttpParamConfigBuilder<>(this::pathParam);
}

public HttpRequestConfigBuilder<T> content(
ValidatorConfig content)
{
Expand All @@ -161,9 +163,33 @@ public <C extends ConfigBuilder<HttpRequestConfigBuilder<T>, C>> C content(
return content.apply(this::content);
}

public HttpRequestConfigBuilder<T> responses(
List<HttpResponseConfig> responses)
{
this.responses = responses;
return this;
}

public HttpRequestConfigBuilder<T> response(
HttpResponseConfig response)
{
if (this.responses == null)
{
this.responses = new LinkedList<>();
}
this.responses.add(response);
return this;
}

public HttpResponseConfigBuilder<HttpRequestConfigBuilder<T>> response()
{
return new HttpResponseConfigBuilder<>(this::response);
}

@Override
public T build()
{
return mapper.apply(new HttpRequestConfig(path, method, contentTypes, headers, pathParams, queryParams, content));
return mapper.apply(new HttpRequestConfig(path, method, contentTypes, headers, pathParams, queryParams, content,
responses));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2021-2023 Aklivity Inc.
*
* Aklivity licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS 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.binding.http.config;

import static java.util.function.Function.identity;

import java.util.List;

import io.aklivity.zilla.runtime.engine.config.ValidatorConfig;

public class HttpResponseConfig
{
public final List<Integer> status;
public final List<String> contentType;
public final ValidatorConfig content;

public HttpResponseConfig(
List<Integer> status,
List<String> contentType,
ValidatorConfig content)
{
this.status = status;
this.contentType = contentType;
this.content = content;
}

public static HttpResponseConfigBuilder<HttpResponseConfig> builder()
{
return new HttpResponseConfigBuilder<>(identity());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2021-2023 Aklivity Inc.
*
* Aklivity licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS 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.binding.http.config;

import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;

import io.aklivity.zilla.runtime.engine.config.ConfigBuilder;
import io.aklivity.zilla.runtime.engine.config.ValidatorConfig;

public class HttpResponseConfigBuilder<T> extends ConfigBuilder<T, HttpResponseConfigBuilder<T>>
{
private final Function<HttpResponseConfig, T> mapper;

private List<Integer> status;
private List<String> contentType;
private ValidatorConfig content;

HttpResponseConfigBuilder(
Function<HttpResponseConfig, T> mapper)
{
this.mapper = mapper;
}

@Override
@SuppressWarnings("unchecked")
protected Class<HttpResponseConfigBuilder<T>> thisType()
{
return (Class<HttpResponseConfigBuilder<T>>) getClass();
}

public HttpResponseConfigBuilder<T> status(
int status)
{
if (this.status == null)
{
this.status = new LinkedList<>();
}
this.status.add(status);
return this;
}

public HttpResponseConfigBuilder<T> contentType(
String contentType)
{
if (this.contentType == null)
{
this.contentType = new LinkedList<>();
}
this.contentType.add(contentType);
return this;
}

public HttpResponseConfigBuilder<T> content(
ValidatorConfig content)
{
this.content = content;
return this;
}

public <C extends ConfigBuilder<HttpResponseConfigBuilder<T>, C>> C content(
Function<Function<ValidatorConfig, HttpResponseConfigBuilder<T>>, C> content)
{
return content.apply(this::content);
}

@Override
public T build()
{
return mapper.apply(new HttpResponseConfig(status, contentType, content));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import io.aklivity.zilla.runtime.binding.http.config.HttpParamConfig;
import io.aklivity.zilla.runtime.binding.http.config.HttpRequestConfig;
import io.aklivity.zilla.runtime.binding.http.config.HttpResponseConfig;
import io.aklivity.zilla.runtime.engine.config.ValidatorConfig;
import io.aklivity.zilla.runtime.engine.config.ValidatorConfigAdapter;

Expand All @@ -43,8 +44,10 @@ public class HttpRequestConfigAdapter implements JsonbAdapter<HttpRequestConfig,
private static final String PATH_PARAMS_NAME = "path";
private static final String QUERY_PARAMS_NAME = "query";
private static final String CONTENT_NAME = "content";
private static final String RESPONSES_NAME = "responses";

private final ValidatorConfigAdapter validator = new ValidatorConfigAdapter();
private final HttpResponseConfigAdapter response = new HttpResponseConfigAdapter();

@Override
public JsonObject adaptToJson(
Expand Down Expand Up @@ -106,6 +109,14 @@ public JsonObject adaptToJson(
JsonValue content = validator.adaptToJson(request.content);
object.add(CONTENT_NAME, content);
}
if (request.responses != null)
{
JsonArrayBuilder responses = Json.createArrayBuilder();
request.responses.stream()
.map(response::adaptToJson)
.forEach(responses::add);
object.add(RESPONSES_NAME, responses);
}
return object.build();
}

Expand Down Expand Up @@ -182,6 +193,15 @@ public HttpRequestConfig adaptFromJson(
}
}
}
return new HttpRequestConfig(path, method, contentType, headers, pathParams, queryParams, content);
List<HttpResponseConfig> responses = null;
if (object.containsKey(RESPONSES_NAME))
{
responses = object.getJsonArray(RESPONSES_NAME).stream()
.map(JsonObject.class::cast)
.map(response::adaptFromJson)
.collect(Collectors.toList());
}
return new HttpRequestConfig(path, method, contentType, headers, pathParams, queryParams, content,
responses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ public final class HttpRequestType
private static final Pattern QUERY_PATTERN = Pattern.compile(QUERY_REGEX);
private static final String EMPTY_INPUT = "";

// selectors
// request selectors
public final String path;
public final HttpRequestConfig.Method method;
public final List<String> contentType;

// matchers
// request matchers
public final Matcher pathMatcher;
public final Matcher queryMatcher;

// validators
// request validators
public final Map<String8FW, Validator> headers;
public final Map<String, Validator> pathParams;
public final Map<String, Validator> queryParams;
public final Validator content;

// responses
//public final List<HttpResponseConfig> responses;

private HttpRequestType(
String path,
HttpRequestConfig.Method method,
Expand Down
Loading