Skip to content

Commit 6855482

Browse files
committed
feat docs: use schemas for documentation in gRPC
Tests: протестировано в CI, проверено локально что все поля отображаются и форматируются приятно для глаза (или хотя бы как было раньше) commit_hash:60b4cec9fe77021674d09980c12341e203a5941f
1 parent f43a5fe commit 6855482

File tree

29 files changed

+211
-168
lines changed

29 files changed

+211
-168
lines changed

.mapping.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@
17431743
"core/src/logging/tp_logger_test.cpp":"taxi/uservices/userver/core/src/logging/tp_logger_test.cpp",
17441744
"core/src/logging/tp_logger_utils.cpp":"taxi/uservices/userver/core/src/logging/tp_logger_utils.cpp",
17451745
"core/src/logging/tp_logger_utils.hpp":"taxi/uservices/userver/core/src/logging/tp_logger_utils.hpp",
1746+
"core/src/middlewares/factory_component_base.yaml":"taxi/uservices/userver/core/src/middlewares/factory_component_base.yaml",
17461747
"core/src/middlewares/impl/middleware_pipeline_config.cpp":"taxi/uservices/userver/core/src/middlewares/impl/middleware_pipeline_config.cpp",
17471748
"core/src/middlewares/impl/middlewares_graph.cpp":"taxi/uservices/userver/core/src/middlewares/impl/middlewares_graph.cpp",
17481749
"core/src/middlewares/impl/middlewares_graph.hpp":"taxi/uservices/userver/core/src/middlewares/impl/middlewares_graph.hpp",
@@ -1753,6 +1754,7 @@
17531754
"core/src/middlewares/pipeline.yaml":"taxi/uservices/userver/core/src/middlewares/pipeline.yaml",
17541755
"core/src/middlewares/pipeline_test.cpp":"taxi/uservices/userver/core/src/middlewares/pipeline_test.cpp",
17551756
"core/src/middlewares/runner.cpp":"taxi/uservices/userver/core/src/middlewares/runner.cpp",
1757+
"core/src/middlewares/runner_component_base.yaml":"taxi/uservices/userver/core/src/middlewares/runner_component_base.yaml",
17561758
"core/src/net/blocking/get_addr_info.cpp":"taxi/uservices/userver/core/src/net/blocking/get_addr_info.cpp",
17571759
"core/src/net/blocking/get_addr_info_test.cpp":"taxi/uservices/userver/core/src/net/blocking/get_addr_info_test.cpp",
17581760
"core/src/os_signals/component.cpp":"taxi/uservices/userver/core/src/os_signals/component.cpp",

core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ list(APPEND EMBED_FILES
138138
src/dynamic_config/updater/component.yaml
139139
src/engine/task_processors_load_monitor.yaml
140140
src/logging/component.yaml
141+
src/middlewares/factory_component_base.yaml
141142
src/middlewares/pipeline.yaml
143+
src/middlewares/runner_component_base.yaml
142144
src/server/component.yaml
143145
src/server/handlers/auth/auth_checker_settings_component.yaml
144146
src/server/handlers/auth/digest/auth_checker_settings_component.yaml

core/include/userver/middlewares/pipeline.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ std::string EndOfGroup() {
7070

7171
/// @brief A base component to create middlewares pipeline.
7272
///
73-
/// ## Static options:
74-
/// Name | Description | Default value
75-
/// ---- | ----------- | -------------
76-
/// middlewares | middlewares names and configs to use | `{}`
73+
/// ## Static options of @ref middlewares::impl::AnyMiddlewarePipelineComponent :
74+
/// @include{doc} scripts/docs/en/components_schema/core/src/middlewares/pipeline.md
75+
///
76+
/// Options inherited from @ref components::ComponentBase :
77+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
7778
///
7879
/// ## Config example:
7980
///

core/include/userver/middlewares/runner.hpp

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,21 @@ void LogConfiguration(std::string_view component_name, const std::vector<std::st
5050

5151
void LogValidateError(std::string_view middleware_name, const std::exception& e);
5252

53+
yaml_config::Schema GetMiddlewareFactoryComponentBaseSchema();
54+
55+
yaml_config::Schema GetRunnerComponentBaseSchema();
56+
5357
} // namespace impl
5458

5559
/// @ingroup userver_base_classes
5660
///
5761
/// @brief Base class for middleware factory component.
62+
///
63+
/// ## Static options of @ref middlewares::MiddlewareFactoryComponentBase :
64+
/// @include{doc} scripts/docs/en/components_schema/core/src/middlewares/factory_component_base.md
65+
///
66+
/// Options inherited from @ref components::ComponentBase :
67+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
5868
template <typename MiddlewareBaseType, typename HandlerInfo>
5969
class MiddlewareFactoryComponentBase : public impl::WithMiddlewareDependencyComponentBase {
6070
public:
@@ -86,16 +96,7 @@ class MiddlewareFactoryComponentBase : public impl::WithMiddlewareDependencyComp
8696
virtual yaml_config::Schema GetMiddlewareConfigSchema() const { return GetStaticConfigSchema(); }
8797

8898
static yaml_config::Schema GetStaticConfigSchema() {
89-
return yaml_config::MergeSchemas<components::ComponentBase>(R"(
90-
type: object
91-
description: base class for grpc-server middleware
92-
additionalProperties: false
93-
properties:
94-
enabled:
95-
type: string
96-
description: the flag to enable/disable middleware in the pipeline
97-
defaultDescription: true
98-
)");
99+
return impl::GetMiddlewareFactoryComponentBaseSchema();
99100
}
100101

101102
/// @cond
@@ -123,38 +124,19 @@ additionalProperties: false
123124
/// The Ordered list of middlewares `RunnerComponentBase` takes from Pipeline component.
124125
/// So, 'Pipeline' is responsible for the order of middlewares. `RunnerComponentBase` is responsible for creating
125126
/// middlewares and overriding configs.
127+
///
128+
/// ## Static options of @ref middlewares::RunnerComponentBase :
129+
/// @include{doc} scripts/docs/en/components_schema/core/src/middlewares/runner_component_base.md
130+
///
131+
/// Options inherited from @ref components::ComponentBase :
132+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
126133
template <typename MiddlewareBase, typename HandlerInfo>
127134
class RunnerComponentBase
128135
: public components::ComponentBase,
129136
public impl::PipelineCreatorInterface<MiddlewareBase, HandlerInfo> {
130137
public:
131138
static yaml_config::Schema GetStaticConfigSchema() {
132-
return yaml_config::MergeSchemas<components::ComponentBase>(R"(
133-
type: object
134-
description: base class for all the gRPC service components
135-
additionalProperties: false
136-
properties:
137-
disable-user-pipeline-middlewares:
138-
type: boolean
139-
description: flag to disable groups::User middlewares from pipeline
140-
defaultDescription: false
141-
disable-all-pipeline-middlewares:
142-
type: boolean
143-
description: flag to disable all middlewares from pipeline
144-
defaultDescription: false
145-
middlewares:
146-
type: object
147-
description: overloads of configs of middlewares per service
148-
additionalProperties:
149-
type: object
150-
description: a middleware config
151-
additionalProperties: true
152-
properties:
153-
enabled:
154-
type: boolean
155-
description: enable middleware in the list
156-
properties: {}
157-
)");
139+
return impl::GetRunnerComponentBaseSchema();
158140
}
159141

160142
protected:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type: object
2+
description: base class for grpc-server middleware
3+
additionalProperties: false
4+
properties:
5+
enabled:
6+
type: string
7+
description: the flag to enable/disable middleware in the pipeline
8+
defaultDescription: true

core/src/middlewares/pipeline.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ properties:
1313
enabled:
1414
type: boolean
1515
description: enable middleware in the list
16+
defaultDescription: true
1617
properties: {}

core/src/middlewares/runner.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
#include <userver/formats/yaml/value_builder.hpp>
88
#include <userver/logging/log.hpp>
99
#include <userver/yaml_config/impl/validate_static_config.hpp>
10+
#include <userver/yaml_config/merge_schemas.hpp>
1011

1112
#include <userver/middlewares/groups.hpp>
1213

14+
#ifndef ARCADIA_ROOT
15+
#include "generated/src/middlewares/factory_component_base.yaml.hpp" // Y_IGNORE
16+
#include "generated/src/middlewares/runner_component_base.yaml.hpp" // Y_IGNORE
17+
#endif
18+
1319
USERVER_NAMESPACE_BEGIN
1420

1521
namespace middlewares::impl {
@@ -34,7 +40,7 @@ MiddlewareDependencyBuilder MakeDefaultUserDependency() {
3440
}
3541

3642
void LogConfiguration(std::string_view component_name, const std::vector<std::string>& names) {
37-
LOG_INFO() << fmt::format("Middlewares configuration for {}: [{}]", component_name, fmt::join(names, ", "));
43+
LOG_INFO("Middlewares configuration for {}: [{}]", component_name, fmt::join(names, ", "));
3844
}
3945

4046
void LogValidateError(std::string_view middleware_name, const std::exception& e) {
@@ -46,6 +52,16 @@ void LogValidateError(std::string_view middleware_name, const std::exception& e)
4652
<< e;
4753
}
4854

55+
yaml_config::Schema GetMiddlewareFactoryComponentBaseSchema() {
56+
return yaml_config::MergeSchemasFromResource<
57+
components::ComponentBase>("src/middlewares/factory_component_base.yaml");
58+
}
59+
60+
yaml_config::Schema GetRunnerComponentBaseSchema() {
61+
return yaml_config::MergeSchemasFromResource<components::ComponentBase>("src/middlewares/runner_component_base.yaml"
62+
);
63+
}
64+
4965
} // namespace middlewares::impl
5066

5167
USERVER_NAMESPACE_END
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
type: object
2+
description: base class for all the gRPC service components
3+
additionalProperties: false
4+
properties:
5+
disable-user-pipeline-middlewares:
6+
type: boolean
7+
description: flag to disable groups::User middlewares from pipeline
8+
defaultDescription: false
9+
disable-all-pipeline-middlewares:
10+
type: boolean
11+
description: flag to disable all middlewares from pipeline
12+
defaultDescription: false
13+
middlewares:
14+
type: object
15+
description: overloads of configs of middlewares per service
16+
additionalProperties:
17+
type: object
18+
description: a middleware config
19+
additionalProperties: true
20+
properties:
21+
enabled:
22+
type: boolean
23+
description: enable middleware in the list
24+
properties: {}

grpc/include/userver/ugrpc/client/client_factory_component.hpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ using MiddlewareRunnerComponentBase = USERVER_NAMESPACE::middlewares::RunnerComp
2020

2121
} // namespace impl
2222

23-
// clang-format off
24-
2523
/// @ingroup userver_components
2624
///
2725
/// @brief Provides a ClientFactory in the component system
@@ -43,28 +41,20 @@ using MiddlewareRunnerComponentBase = USERVER_NAMESPACE::middlewares::RunnerComp
4341
/// ## Service config
4442
/// As per https://github.com/grpc/grpc/blob/master/doc/service_config.md
4543
/// service config should be distributed via the name resolution process.
46-
/// We allow setting default service_config: pass desired JSON literal
47-
/// to `default-service-config` parameter
44+
/// We allow setting default service_config: pass desired JSON literal to `default-service-config` parameter
4845
///
49-
/// ## Static options:
50-
/// The default component name for static config is `"grpc-client-factory"`.
46+
/// ## Static options of @ref ugrpc::client::ClientFactoryComponent :
47+
/// @include{doc} scripts/docs/en/components_schema/grpc/src/ugrpc/client/client_factory_component.md
5148
///
52-
/// Name | Description | Default value
53-
/// ---- | ----------- | -------------
54-
/// auth-type | authentication method, see @ref grpc_ssl_authentication "Authentication" | -
55-
/// ssl-credentials-options | TLS/SSL options, see @ref grpc_ssl_authentication "Authentication" | -
56-
/// retry-config | retry configuration for outgoing RPCs | {}
57-
/// channel-args | a map of channel arguments, see gRPC Core docs | {}
58-
/// default-service-config | default service config, see above | -
59-
/// channel-count | Number of underlying grpc::Channel objects | 1
60-
/// middlewares | middlewares names to use | -
61-
/// disable-user-pipeline-middlewares | a flag to disable groups::User middlewares from pipeline | false
62-
/// disable-all-pipeline-middlewares | a flag to disable all middlewares from the pipeline | false
49+
/// Options inherited from @ref middlewares::RunnerComponentBase :
50+
/// @include{doc} scripts/docs/en/components_schema/core/src/middlewares/runner_component_base.md
51+
///
52+
/// Options inherited from @ref components::ComponentBase :
53+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
54+
///
55+
/// The default component name for static config is `"grpc-client-factory"`.
6356
///
6457
/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
65-
66-
// clang-format on
67-
6858
class ClientFactoryComponent final : public impl::MiddlewareRunnerComponentBase {
6959
public:
7060
/// @ingroup userver_component_names

grpc/include/userver/ugrpc/client/common_component.hpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,23 @@ USERVER_NAMESPACE_BEGIN
1717

1818
namespace ugrpc::client {
1919

20-
// clang-format off
21-
2220
/// @ingroup userver_components
2321
///
2422
/// @brief Contains common machinery that's required for all ugrpc clients
2523
///
26-
/// ## Static options:
27-
/// The component name for static config is `"grpc-client-common"`.
24+
/// ## Static options of @ref ugrpc::client::CommonComponent :
25+
/// @include{doc} scripts/docs/en/components_schema/grpc/src/ugrpc/client/common_component.md
2826
///
29-
/// Name | Description | Default value
30-
/// ---- | ----------- | -------------
31-
/// blocking-task-processor | the task processor for blocking channel creation | -
32-
/// native-log-level | min log level for the native gRPC library | 'error'
33-
/// proxy-address | proxy server address | ''
34-
/// servicemesh-settings | settings for service mesh integration | -
27+
/// Options inherited from @ref components::ComponentBase :
28+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
29+
///
30+
/// The component name for static config is `"grpc-client-common"`.
3531
///
3632
/// @see ugrpc::client::ClientFactoryComponent
37-
38-
// clang-format on
3933
class CommonComponent final : public components::ComponentBase {
4034
public:
4135
/// @ingroup userver_component_names
42-
/// @brief The default name of ugrpc::client::CommonComponent
36+
/// @brief The default name of @ref ugrpc::client::CommonComponent
4337
static constexpr std::string_view kName = "grpc-client-common";
4438

4539
CommonComponent(const components::ComponentConfig& config, const components::ComponentContext& context);

0 commit comments

Comments
 (0)