Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
87b534f
feat(chaotic-openapi): pass RequestContext to generated View::Handle
lemito Aug 14, 2026
97ba9b4
chore(chaotic-openapi): update golden tests and views for View::Handl…
lemito Aug 14, 2026
9217456
docs(chaotic-openapi): document View::Handle RequestContext contract
lemito Aug 14, 2026
3658eda
fix(chaotic-openapi): fix int_tests
lemito Aug 14, 2026
761a6e6
refactor(chaotic-openapi): require RequestContext in View::Handle
lemito Aug 16, 2026
e4f4bae
chore(chaotic-openapi): update views for RequestContext alias
lemito Aug 16, 2026
830323a
feat(samples): add chaotic_openapi_auth_service sample
lemito Aug 16, 2026
770bf83
test(chaotic-openapi): add view renderer unit tests
lemito Aug 16, 2026
60e5a09
docs(chaotic-openapi): document auth via RequestContext
lemito Aug 16, 2026
b2fc748
revert(chaotic-openapi): drop redundant docs, mapping and sample changes
lemito Aug 16, 2026
733f088
fix(chaotic-openapi): update handler logging test for RequestContext …
lemito Aug 17, 2026
32af417
feat(samples): demonstrate RequestContext auth in chaotic_openapi_ser…
lemito Aug 17, 2026
8a04195
refactor(samples): move greetingGet to a separate secure schema
lemito Aug 17, 2026
c996465
feat(samples): validate bearer tokens against secdist in chaotic_open…
lemito Aug 17, 2026
db145ae
feat(chaotic-openapi): add ChaoticHandlersListWithoutFactories()
lemito Aug 17, 2026
e602b54
ERROR
lemito Aug 18, 2026
a6913d9
fix(chopen)/fix ch-openapi factories
lemito Aug 18, 2026
5f22fad
fix: bad config add
lemito Aug 18, 2026
07f8538
fix(chaotic): build config.yaml with the service binary
lemito Aug 18, 2026
e5879d9
fix(chgen): reformat
lemito Aug 20, 2026
886232a
fix(chgen): reformat code
lemito Aug 20, 2026
460e610
fix(chgen): regenerate golden tests output with formatting
lemito Aug 21, 2026
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
10 changes: 10 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -4457,6 +4457,16 @@
"samples/benchmark_service/static_config.yaml":"taxi/uservices/userver/samples/benchmark_service/static_config.yaml",
"samples/benchmark_service/testsuite/conftest.py":"taxi/uservices/userver/samples/benchmark_service/testsuite/conftest.py",
"samples/benchmark_service/testsuite/test_benchmark.py":"taxi/uservices/userver/samples/benchmark_service/testsuite/test_benchmark.py",
"samples/chaotic_openapi_auth_service/CMakeLists.txt":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/CMakeLists.txt",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

не надо трогать этот файл)

"samples/chaotic_openapi_auth_service/handlers/secure/openapi.yaml":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/handlers/secure/openapi.yaml",
"samples/chaotic_openapi_auth_service/main.cpp":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/main.cpp",
"samples/chaotic_openapi_auth_service/src/auth_bearer.cpp":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/src/auth_bearer.cpp",
"samples/chaotic_openapi_auth_service/src/auth_bearer.hpp":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/src/auth_bearer.hpp",
"samples/chaotic_openapi_auth_service/src/handlers/secure/greetingget/view.cpp":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/src/handlers/secure/greetingget/view.cpp",
"samples/chaotic_openapi_auth_service/src/handlers/secure/greetingget/view.hpp":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/src/handlers/secure/greetingget/view.hpp",
"samples/chaotic_openapi_auth_service/static_config.yaml":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/static_config.yaml",
"samples/chaotic_openapi_auth_service/testsuite/conftest.py":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/testsuite/conftest.py",
"samples/chaotic_openapi_auth_service/testsuite/test_auth.py":"taxi/uservices/userver/samples/chaotic_openapi_auth_service/testsuite/test_auth.py",
"samples/chaotic_openapi_service/CMakeLists.txt":"taxi/uservices/userver/samples/chaotic_openapi_service/CMakeLists.txt",
"samples/chaotic_openapi_service/clients/test.yaml":"taxi/uservices/userver/samples/chaotic_openapi_service/clients/test.yaml",
"samples/chaotic_openapi_service/handlers/insecure/openapi.yaml":"taxi/uservices/userver/samples/chaotic_openapi_service/handlers/insecure/openapi.yaml",
Expand Down
17 changes: 17 additions & 0 deletions chaotic-openapi/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ that generates the `PEERDIR`/include lists for `ya.make` files. It is never call
`main.py`.


## View contract

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

это лишнее


For each operation the generator emits a `View` with a hand-written entry point:

```cpp
using RequestContext = userver::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps, RequestContext& context);
```

The third parameter gives the handler access to the per-request context (e.g. data set by
the auth middleware via `userver::server::auth::GetUserAuthInfo(context)` / `context.SetData`).
It is **always** passed by the runtime dispatcher (`BaseHandler` in
`include/userver/chaotic/openapi/server/handler_base.hpp`) — the legacy 2-argument
`Handle(Request&&, Deps&&)` is not supported.


# Tests

Tests are implemented at multiple levels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace {{ spec.cpp_namespace }}::{{ op.cpp_namespace() }} {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) {
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& /*context*/) {
// Handle request using dependencies from Deps (clients, caches, configs, databases...)
return {};
}
Expand Down Expand Up @@ -32,7 +35,7 @@ std::string View::GetRequestBodyForLogging(const std::string& body) {
std::string View::GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
{{ userver }}::server::request::RequestContext& context) {
RequestContext& context) {
(void)response;
(void)serialized_response;
(void)context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ struct HandlerTag;
class View final {
public:
using Deps = {{ userver }}::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = {{ userver }}::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

/* Uncomment, if you want to define a custom logging for request/response body.
* E.g. you want to log several fields, but omit the others (secrets, etc.).
Expand All @@ -40,7 +41,7 @@ public:
static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
{{ userver }}::server::request::RequestContext& context);
RequestContext& context);
*/
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace handlers::test::testme::post {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) {
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& /*context*/) {
// Handle request using dependencies from Deps (clients, caches, configs, databases...)
return {};
}
Expand All @@ -23,7 +26,7 @@ return {};
std::string View::GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context) {
RequestContext& context) {
(void)response;
(void)serialized_response;
(void)context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ struct HandlerTag;
class View final {
public:
using Deps = USERVER_NAMESPACE::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = USERVER_NAMESPACE::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

/* Uncomment, if you want to define a custom logging for request/response body.
* E.g. you want to log several fields, but omit the others (secrets, etc.).
Expand All @@ -32,7 +33,7 @@ const USERVER_NAMESPACE::server::http::HttpRequest& request);
static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context);
RequestContext& context);
*/
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ class BaseHandler final : public USERVER_NAMESPACE::server::handlers::HttpHandle
"View::GetInvalidRequestBodyForLogging requires "
"View::GetRequestBodyForLogging(const formats::json::Value&)."
);
static_assert(
requires(Request&& r, Deps&& d, USERVER_NAMESPACE::server::request::RequestContext& ctx) {
{
View::Handle(std::move(r), std::move(d), ctx)
} -> std::convertible_to<Response>;
},
"View::Handle must accept server::request::RequestContext as the third parameter: "
"static Response Handle(Request&& request, Deps&& deps, RequestContext& context). "
"The legacy 2-argument Handle(Request&&, Deps&&) is no longer supported."
);

using Factories = chaotic::openapi::server::dependencies::Factories;
using FactoriesContainer = USERVER_NAMESPACE::components::Container<Factories>;
Expand All @@ -165,7 +175,7 @@ class BaseHandler final : public USERVER_NAMESPACE::server::handlers::HttpHandle
USERVER_NAMESPACE::server::request::RequestContext& context
) const {
auto deps = factories_.Get().template Make<HandlerTag>();
auto response = View::Handle(std::move(request), std::move(deps));
auto response = View::Handle(std::move(request), std::move(deps), context);
auto serialized = SerializeResponse(response, http_request);
if constexpr (impl::ViewHasGetResponseForLogging<View, Response>) {
context.SetData<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace handlers::simple::formpost {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) { return {}; }
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& /*context*/
) {
return {};
}

std::string View::GetRequestBodyForLogging(const std::string& /*body*/) { return {}; }

std::string View::GetResponseForLogging(
const Response& /*response*/,
const std::string& /*serialized_response*/,
USERVER_NAMESPACE::server::request::RequestContext& /*context*/
RequestContext& /*context*/
) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ struct HandlerTag;
class View final {
public:
using Deps = USERVER_NAMESPACE::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = USERVER_NAMESPACE::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

static std::string GetRequestBodyForLogging(const std::string& body);

static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context
RequestContext& context
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace handlers::simple::greetget {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) { return {}; }
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& /*context*/
) {
return {};
}

std::string View::GetResponseForLogging(
const Response& /*response*/,
const std::string& /*serialized_response*/,
USERVER_NAMESPACE::server::request::RequestContext& /*context*/
RequestContext& /*context*/
) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ struct HandlerTag;
class View final {
public:
using Deps = USERVER_NAMESPACE::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = USERVER_NAMESPACE::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context
RequestContext& context
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

namespace handlers::simple::headersget {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) { return {}; }
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& context
) {
Response200 response;
const auto* user_id = context.GetDataOptional<std::string>("x-user-id");
response.X_String = user_id ? *user_id : "";
response.body = response.X_String;
return response;
}

std::string View::GetResponseForLogging(
const Response& /*response*/,
const std::string& /*serialized_response*/,
USERVER_NAMESPACE::server::request::RequestContext& /*context*/
RequestContext& /*context*/
) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ struct HandlerTag;
class View final {
public:
using Deps = USERVER_NAMESPACE::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = USERVER_NAMESPACE::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context
RequestContext& context
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace handlers::simple::multipartpost {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) { return {}; }
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& /*context*/
) {
return {};
}

std::string View::GetRequestBodyForLogging(const std::string& /*body*/) { return {}; }

std::string View::GetResponseForLogging(
const Response& /*response*/,
const std::string& /*serialized_response*/,
USERVER_NAMESPACE::server::request::RequestContext& /*context*/
RequestContext& /*context*/
) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ struct HandlerTag;
class View final {
public:
using Deps = USERVER_NAMESPACE::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = USERVER_NAMESPACE::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

static std::string GetRequestBodyForLogging(const std::string& body);

static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context
RequestContext& context
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace handlers::simple::multipost {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) { return {}; }
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& /*context*/
) {
return {};
}

std::string View::GetResponseForLogging(
const Response& /*response*/,
const std::string& /*serialized_response*/,
USERVER_NAMESPACE::server::request::RequestContext& /*context*/
RequestContext& /*context*/
) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ struct HandlerTag;
class View final {
public:
using Deps = USERVER_NAMESPACE::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = USERVER_NAMESPACE::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context
RequestContext& context
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace handlers::simple::octetget {

Response View::Handle(Request&& /*request*/, Deps&& /*deps*/) { return {}; }
Response View::Handle(
Request&& /*request*/,
Deps&& /*deps*/,
RequestContext& /*context*/
) {
return {};
}

std::string View::GetRequestBodyForLogging(const std::string& /*body*/) { return {}; }

std::string View::GetResponseForLogging(
const Response& /*response*/,
const std::string& /*serialized_response*/,
USERVER_NAMESPACE::server::request::RequestContext& /*context*/
RequestContext& /*context*/
) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ struct HandlerTag;
class View final {
public:
using Deps = USERVER_NAMESPACE::chaotic::openapi::server::dependencies::ForHandler<HandlerTag>;
using RequestContext = USERVER_NAMESPACE::server::request::RequestContext;

static Response Handle(Request&& request, Deps&& deps);
static Response Handle(Request&& request, Deps&& deps, RequestContext& context);

static std::string GetRequestBodyForLogging(const std::string& body);

static std::string GetResponseForLogging(
const Response& response,
const std::string& serialized_response,
USERVER_NAMESPACE::server::request::RequestContext& context
RequestContext& context
);
};

Expand Down
Loading
Loading