Skip to content

Commit bcb2d10

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

File tree

6 files changed

+47
-49
lines changed

6 files changed

+47
-49
lines changed

mysql/include/userver/storages/mysql/component.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Cluster;
2020

2121
namespace storages::mysql {
2222

23-
// clang-format off
2423
/// @ingroup userver_components
2524
///
2625
/// @brief MySQL/MariaDB client component
@@ -44,13 +43,11 @@ namespace storages::mysql {
4443
/// primary detection and always considers the first host in `hosts` list
4544
/// an only primary node in the cluster.
4645
///
47-
/// ## Static options (more to come)
48-
/// Name | Description | Default value
49-
/// -------------------------|---------------------------------------------|---------------
50-
/// initial_pool_size | initial connection pool size (per host) | 5
51-
/// max_pool_size | maximum connection pool size (per host) | 10
46+
/// ## Static options of @ref storages::mysql::Component :
47+
/// @include{doc} scripts/docs/en/components_schema/mysql/src/storages/mysql/component.md
5248
///
53-
// clang-format on
49+
/// Options inherited from @ref components::ComponentBase :
50+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
5451
class Component final : public components::ComponentBase {
5552
public:
5653
/// Component constructor

rabbitmq/include/userver/urabbitmq/component.hpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Client;
2020

2121
namespace components {
2222

23-
// clang-format off
2423
/// @ingroup userver_components
2524
///
2625
/// @brief RabbitMQ (AMQP 0.9.1) client component
@@ -42,17 +41,11 @@ namespace components {
4241
///
4342
/// @snippet samples/rabbitmq_service/tests/conftest.py RabbitMQ service sample - secdist
4443
///
45-
/// ## Static options:
46-
/// Name | Description | Default value
47-
/// ----------------------- | -------------------------------------------------------------------- | ---------------
48-
/// secdist_alias | name of the key in secdist config | components name
49-
/// min_pool_size | minimum connections pool size (per host) | 5
50-
/// max_pool_size | maximum connections pool size (per host, consumers excluded) | 10
51-
/// max_in_flight_requests | per-connection limit for requests awaiting response from the broker | 5
52-
/// use_secure_connection | whether to use TLS for connections | true
44+
/// ## Static options of @ref components::RabbitMQ :
45+
/// @include{doc} scripts/docs/en/components_schema/rabbitmq/src/urabbitmq/component.md
5346
///
54-
// clang-format on
55-
47+
/// Options inherited from @ref components::ComponentBase :
48+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
5649
class RabbitMQ final : public ComponentBase {
5750
public:
5851
/// Component constructor

rabbitmq/include/userver/urabbitmq/consumer_component_base.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ USERVER_NAMESPACE_BEGIN
1111

1212
namespace urabbitmq {
1313

14-
// clang-format off
1514
/// @ingroup userver_base_classes
1615
///
1716
/// @brief Base component for your consumers.
@@ -33,13 +32,11 @@ namespace urabbitmq {
3332
///
3433
/// @snippet samples/rabbitmq_service/static_config.yaml RabbitMQ consumer sample - static config
3534
///
36-
/// ## Static options:
37-
/// Name | Description
38-
/// rabbit_name | Name of the RabbitMQ component to use for consumption
39-
/// queue | Name of the queue to consume from
40-
/// prefetch_count | prefetch_count for the consumer, limits the amount of in-flight messages
35+
/// ## Static options @ref urabbitmq::ConsumerComponentBase :
36+
/// @include{doc} scripts/docs/en/components_schema/rabbitmq/src/urabbitmq/consumer_component_base.md
4137
///
42-
// clang-format on
38+
/// Options inherited from @ref components::ComponentBase :
39+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
4340
class ConsumerComponentBase : public components::ComponentBase {
4441
public:
4542
ConsumerComponentBase(const components::ComponentConfig& config, const components::ComponentContext& context);

rabbitmq/src/urabbitmq/consumer_component_base.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ properties:
1010
description: a queue to consume from
1111
prefetch_count:
1212
type: integer
13-
description: prefetch_count for the consumer
13+
description: prefetch_count for the consumer, limits the amount of in-flight
14+
messages

rocks/include/userver/storages/rocks/component.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ USERVER_NAMESPACE_BEGIN
1313

1414
namespace storages::rocks {
1515

16-
// clang-format off
17-
1816
/// @ingroup userver_components
1917
///
2018
/// @brief RocksDB client component.
21-
/// ## Static options:
22-
/// Name | Description | Default value
23-
/// ---------------------------------- | ------------------------------------------------ | ---------------
24-
/// task-processor | name of the task processor to run the blocking file operations | -
25-
/// db-path | path to database file | -
26-
27-
// clang-format on
28-
19+
///
20+
/// ## Static options of @ref storages::rocks::Component :
21+
/// @include{doc} scripts/docs/en/components_schema/rocks/src/storages/rocks/component.md
22+
///
23+
/// Options inherited from @ref components::ComponentBase :
24+
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md | -
2925
class Component : public components::ComponentBase {
3026
public:
3127
Component(const components::ComponentConfig&, const components::ComponentContext&);

scripts/docs/components_schema_to_table.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,32 @@ def normalize_default_value(data) -> str:
1818
return data
1919

2020

21+
def merge_descriptions(yaml, other):
22+
if yaml.get('description') and other.get('description'):
23+
description = yaml['description'].strip()
24+
if not description.endswith('.'):
25+
description += '.'
26+
description += ' <i>Each of the elements:</i> ' + other['description']
27+
28+
value_merged = yaml.copy()
29+
value_merged['description'] = description
30+
return value_merged
31+
elif yaml.get('description'):
32+
return yaml
33+
else:
34+
return other
35+
36+
2137
def visit_object(yaml, prefix: str = ''):
2238
properties = yaml.get('properties', {})
2339

2440
for key, value in properties.items():
2541
if value.get('type') == 'array':
2642
if value['items'].get('type') == 'object':
2743
yield from visit_object(value['items'], prefix + key + '.[].')
28-
elif value.get('description') and value['items'].get('description'):
29-
description = value['description'].strip()
30-
if not description.endswith('.'):
31-
description += '.'
32-
description += ' Each of the array elements: ' + value['items']['description']
33-
34-
value_cloned = value.copy()
35-
value_cloned['description'] = description
36-
yield (prefix + key + '.[]', value_cloned)
37-
elif value.get('description'):
38-
yield (prefix + key + '.[]', value)
3944
else:
40-
yield (prefix + key + '.[]', value['items'])
45+
value_merged = merge_descriptions(value, value['items'])
46+
yield (prefix + key + '.[]', value_merged)
4147
elif value.get('type') == 'object':
4248
yield from visit_object(value, prefix + key + '.')
4349
else:
@@ -46,8 +52,16 @@ def visit_object(yaml, prefix: str = ''):
4652
additionals = yaml.get('additionalProperties')
4753
if additionals is True:
4854
yield (prefix + '*', yaml)
49-
elif additionals:
55+
elif not additionals:
56+
return
57+
elif additionals.get('type') == 'object':
5058
yield from visit_object(yaml['additionalProperties'], prefix + '*.')
59+
elif additionals.get('type') == 'array':
60+
value_merged = merge_descriptions(yaml, additionals['items'])
61+
yield (prefix + '*.[]', value_merged)
62+
else:
63+
value_merged = merge_descriptions(yaml, additionals)
64+
yield (prefix + '*', value_merged)
5165

5266

5367
def format_schema(yaml) -> str:

0 commit comments

Comments
 (0)