Skip to content

Commit 154d288

Browse files
committed
feat docs: add script to gerenrate tables from schemas
Tests: протестировано локально commit_hash:42142a8312ce078f9bfe25ffb47f7e82140b42a5
1 parent 6f53c23 commit 154d288

File tree

8 files changed

+102
-37
lines changed

8 files changed

+102
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static-analyzer-report
2121
.settings*
2222
.clangd
2323
.vscode
24+
scripts/docs/en/components_schema
2425
scripts/docs/en/dynamic_configs
2526
scripts/docs/en/versions.md
2627
scripts/docs/scripts/versions.js

.mapping.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@
536536
"cmake/UserverCodegenTarget.cmake":"taxi/uservices/userver/cmake/UserverCodegenTarget.cmake",
537537
"cmake/UserverCxxCompileOptionsIfSupported.cmake":"taxi/uservices/userver/cmake/UserverCxxCompileOptionsIfSupported.cmake",
538538
"cmake/UserverEmbedFile.cmake":"taxi/uservices/userver/cmake/UserverEmbedFile.cmake",
539+
"cmake/UserverGenerateComponentsSchemaDocs.cmake":"taxi/uservices/userver/cmake/UserverGenerateComponentsSchemaDocs.cmake",
539540
"cmake/UserverGenerateDynamicConfigsDocs.cmake":"taxi/uservices/userver/cmake/UserverGenerateDynamicConfigsDocs.cmake",
540541
"cmake/UserverGrpcTargets.cmake":"taxi/uservices/userver/cmake/UserverGrpcTargets.cmake",
541542
"cmake/UserverModule.cmake":"taxi/uservices/userver/cmake/UserverModule.cmake",
@@ -4193,6 +4194,7 @@
41934194
"scripts/docker/ubuntu_install_grpc.sh":"taxi/uservices/userver/scripts/docker/ubuntu_install_grpc.sh",
41944195
"scripts/docs/README.md":"taxi/uservices/userver/scripts/docs/README.md",
41954196
"scripts/docs/clean_doxygen_logs.py":"taxi/uservices/userver/scripts/docs/clean_doxygen_logs.py",
4197+
"scripts/docs/components_schema_to_table.py":"taxi/uservices/userver/scripts/docs/components_schema_to_table.py",
41964198
"scripts/docs/customdoxygen.css":"taxi/uservices/userver/scripts/docs/customdoxygen.css",
41974199
"scripts/docs/doxygen-awesome-css/README.md":"taxi/uservices/userver/scripts/docs/doxygen-awesome-css/README.md",
41984200
"scripts/docs/doxygen-awesome-css/doxygen-awesome-darkmode-toggle.js":"taxi/uservices/userver/scripts/docs/doxygen-awesome-css/doxygen-awesome-darkmode-toggle.js",

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ include(FindPackageRequired)
190190
include(IncludeWhatYouUse)
191191
include(UserverTestsuite)
192192
include(UserverCodegenTarget)
193+
include(UserverGenerateComponentsSchemaDocs)
193194
include(UserverGenerateDynamicConfigsDocs)
194195
include(CheckCompileFlags)
195196
include(CMakePackageConfigHelpers)
@@ -366,6 +367,7 @@ if(USERVER_BUILD_TESTS)
366367
endif()
367368
endif()
368369

370+
_userver_add_target_gen_component_schemas_docs()
369371
_userver_add_target_gen_dynamic_configs_docs()
370372

371373
_userver_print_features_list()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function(_userver_add_target_gen_component_schemas_docs)
2+
file(GLOB_RECURSE YAML_FILENAMES */src/*.yaml)
3+
4+
add_custom_target(
5+
userver-gen-components-schema-docs
6+
COMMENT "Generate components schema .md docs"
7+
COMMAND
8+
${USERVER_PYTHON_PATH}
9+
${CMAKE_CURRENT_SOURCE_DIR}/scripts/docs/components_schema_to_table.py
10+
-o ${CMAKE_CURRENT_BINARY_DIR}/components-schema
11+
${YAML_FILENAMES}
12+
)
13+
endfunction()

kafka/include/userver/kafka/consumer_component.hpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,7 @@ class Consumer;
3636
/// @snippet samples/kafka_service/testsuite/conftest.py Kafka service sample - secdist
3737
///
3838
/// ## Static options:
39-
/// Name | Description | Default value
40-
/// ---------------------------------- | ------------------------------------------------ | ---------------
41-
/// client_id | Client identifier. May be an arbitrary string | userver
42-
/// group_id | consumer group id (name) | --
43-
/// topics | list of topics consumer subscribes | --
44-
/// max_batch_size | maximum number of messages consumer waits for new message before calling a callback | 1
45-
/// poll_timeout | maximum amount of time consumer waits for messages for new messages before calling a callback | 1s
46-
/// max_callback_duration | duration user callback must fit not to be kicked from the consumer group | 5m
47-
/// restart_after_failure_delay | time consumer suspends execution if user-callback fails | 10s
48-
/// auto_offset_reset | action to take when there is no initial offset in offset store | smallest
49-
/// env_pod_name | environment variable to substitute `{pod_name}` substring in `group_id` | none
50-
/// security_protocol | protocol used to communicate with brokers | --
51-
/// sasl_mechanisms | SASL mechanism to use for authentication | none
52-
/// ssl_ca_location | File or directory path to CA certificate(s) for verifying the broker's key | none
53-
/// topic_metadata_refresh_interval | period of time at which topic and broker metadata is refreshed | 5m
54-
/// metadata_max_age | metadata cache max age | 15
55-
/// rd_kafka_custom_options | a map of librdkafka library additional options | '{}'
56-
/// debug_info_log_level | log level for everything debug information | debug
57-
/// operation_log_level | log level for infos about ordinary actions | info
39+
/// @include{doc} scripts/docs/en/components_schema/kafka/src/kafka/consumer_component.md
5840

5941
// clang-format on
6042

kafka/include/userver/kafka/producer_component.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,7 @@ namespace kafka {
2929
/// @snippet samples/kafka_service/testsuite/conftest.py Kafka service sample - secdist
3030
///
3131
/// ## Static options:
32-
/// Name | Description | Default value
33-
/// ---------------------------- | ------------------------------------------------ | ---------------
34-
/// client_id | Client identifier. May be an arbitrary string | userver
35-
/// delivery_timeout | time a produced message waits for successful delivery | --
36-
/// queue_buffering_max | delay to wait for messages to be transmitted to broker | --
37-
/// enable_idempotence | whether to make producer idempotent | false
38-
/// queue_buffering_max_messages | maximum number of messages waiting for delivery | 100000
39-
/// queue_buffering_max_kbytes | maximum size of messages waiting for delivery | 1048576
40-
/// message_max_bytes | maximum size of message | 1000000
41-
/// message_send_max_retries | maximum number of send request retries until `delivery_timeout` reached | 2147483647
42-
/// retry_backoff | backoff time before retrying send request, exponentially increases after each retry | 100
43-
/// retry_backoff_max | backoff upper bound | 1000
44-
/// security_protocol | protocol used to communicate with brokers | --
45-
/// sasl_mechanisms | SASL mechanism to use for authentication | none
46-
/// ssl_ca_location | file or directory path to CA certificate(s) for verifying the broker's key | none
47-
/// rd_kafka_custom_options | a map of librdkafka library additional options | '{}'
48-
/// debug_info_log_level | log level for everything debug information | debug
49-
/// operation_log_level | log level for infos about ordinary actions | info
32+
/// @include{doc} scripts/docs/en/components_schema/kafka/src/kafka/producer_component.md
5033

5134
// clang-format on
5235

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/python
2+
3+
import argparse
4+
import os
5+
import pathlib
6+
7+
import yaml
8+
9+
USERVER_ROOT = pathlib.Path(__file__).parent.parent.parent
10+
11+
12+
def normalize_default_value(data) -> str:
13+
if data is True:
14+
return 'true'
15+
elif data is False:
16+
return 'false'
17+
else:
18+
return data
19+
20+
21+
def format_schema(yaml) -> str:
22+
result = ''
23+
properties = yaml.get('properties', {})
24+
if not properties:
25+
result += 'No options'
26+
return result
27+
28+
max_key_size = max(len(key) for key in properties.keys())
29+
max_value_size = max(len(value['description']) for value in properties.values())
30+
31+
result += f'{"Name":{max_key_size}} | {"Description":{max_value_size}} | Default value\n'
32+
result += f'{"":-<{max_key_size}} | {"":-<{max_value_size}} | {"":-<16}\n'
33+
34+
for key, value in properties.items():
35+
key = key.replace('\n', ' ')
36+
description = value['description'].replace('\n', ' ')
37+
default = normalize_default_value(value.get('defaultDescription', '--'))
38+
result += f'{key:{max_key_size}} | {description:{max_value_size}} | {default}\n'
39+
40+
return result
41+
42+
43+
def parse_args():
44+
parser = argparse.ArgumentParser()
45+
parser.add_argument('-o')
46+
parser.add_argument('yaml', nargs='+')
47+
return parser.parse_args()
48+
49+
50+
def handle_file(ifname: pathlib.Path, output_dir: pathlib.Path):
51+
with open(ifname) as ifile:
52+
content = yaml.load(ifile.read(), yaml.Loader)
53+
54+
md = format_schema(content)
55+
56+
output_path = output_dir / ifname.parent.relative_to(USERVER_ROOT)
57+
os.makedirs(str(output_path), exist_ok=True)
58+
59+
output_file = output_path / (pathlib.Path(ifname).stem + '.md')
60+
print(output_file)
61+
62+
with open(output_file, 'w') as ofile:
63+
ofile.write(md)
64+
65+
66+
def main():
67+
args = parse_args()
68+
for fname in args.yaml:
69+
try:
70+
handle_file(pathlib.Path(fname), pathlib.Path(args.o))
71+
except yaml.scanner.ScannerError as err:
72+
print(f'Failed to parse YAML from file {fname}: {err}')
73+
74+
75+
if __name__ == '__main__':
76+
main()

scripts/docs/make_docs.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ CMAKE_VERSION=$("$CMAKE_COMMAND" --version | grep -oP '\d+\.\d+')
5151
echo "Building target userver-codegen."
5252
"$CMAKE_COMMAND" --build "$BUILD_DIR" --target userver-codegen
5353

54+
echo "Building target userver-gen-components-schema-docs."
55+
"$CMAKE_COMMAND" --build "$BUILD_DIR" --target userver-gen-components-schema-docs
56+
rm -rf scripts/docs/en/components_schema
57+
mkdir scripts/docs/en/components_schema
58+
cp -rf $BUILD_DIR/components-schema/* scripts/docs/en/components_schema/
59+
5460
echo "Building target userver-gen-dynamic-configs-docs."
5561
"$CMAKE_COMMAND" --build "$BUILD_DIR" --target userver-gen-dynamic-configs-docs
5662
rm -rf scripts/docs/en/dynamic_configs

0 commit comments

Comments
 (0)