You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Resolve certain small, known C++ zero-argument functions to their literal return values by searching Redpanda source files.
217
+
Resolve a small set of known zero-argument C++ functions to their literal string return values by scanning a local Redpanda source tree.
218
218
219
-
This function looks up predefined search patterns for well-known functions (currently a small set under `model::*`), locates a local Redpanda source tree from several commonly used paths, and scans the listed files (and, if needed, the broader model directory) for a regex match that captures the string returned by the function. If a match is found the captured string is returned; if the source tree cannot be found or no match is located the function returns None.
219
+
Searches predefined files and regex patterns for the specified fully-qualified function name (e.g., "model::kafka_audit_logging_topic") and returns the captured string if found; returns None when no match or when the Redpanda source tree cannot be located.
220
220
221
221
Parameters:
222
-
function_name (str): Fully-qualified C++ function name to resolve (e.g., "model::kafka_audit_logging_topic").
222
+
function_name (str): Fully-qualified C++ function name to resolve.
223
223
224
224
Returns:
225
-
str or None: The resolved literal string returned by the C++ function, or None when unresolved (source not found or no matching pattern).
226
-
227
-
Notes:
228
-
- The function performs filesystem I/O and regex-based source searching; it does not raise on read errors but logs and continues.
229
-
- Only a small, hard-coded set of function names/patterns is supported; unknown names immediately return None.
225
+
str or None: The literal string returned by the C++ function when resolved, or `None` if unresolved.
230
226
"""
231
227
# Map function names to likely search patterns and file locations
Resolve a constexpr identifier from Redpanda source code to its literal value.
341
+
Resolve a constexpr identifier from Redpanda source code to its literal string value.
346
342
347
-
This function searches recursively through header and source files for constexpr
348
-
variable definitions. It's specifically useful for resolving identifiers like 'scram'
349
-
which are defined as constexpr string_view variables.
343
+
Searches common Redpanda source locations for constexpr string or string_view definitions matching the given identifier and returns the literal if found.
350
344
351
345
Parameters:
352
346
identifier (str): The identifier name to resolve (e.g., "scram").
353
347
354
348
Returns:
355
-
str or None: The resolved literal string value, or None if not found.
349
+
str or None: The resolved literal string valueif found, otherwise `None`.
Resolve JSON Schema types and expand C++-style default values for all properties.
897
+
Normalize property types and expand C++-style default values into JSON-compatible Python structures.
892
898
893
-
This function:
894
-
- Resolves type references found in `properties` against `definitions` (supports "$ref" and direct type names) and normalizes property "type" to a JSON Schema primitive ("object", "string", "integer", "boolean", "array", "number") with sensible fallbacks.
895
-
- Expands C++ constructor/initializer syntax and common C++ patterns appearing in default values into JSON-compatible Python values (e.g., nested constructor calls -> dicts, initializer lists -> lists, `std::nullopt` -> None, enum-like tokens -> strings).
896
-
- Ensures array-typed properties (including one_or_many_property cases) have array defaults: single-object defaults are wrapped into a one-element list and "{}" string defaults become [].
897
-
- Updates array item type information when item types reference definitions.
898
-
- Applies a final pass to convert any remaining C++-patterned defaults and to transform any `enterprise_value` strings via process_enterprise_value.
899
+
This function resolves type references in each property against the provided definitions (supports "$ref" and direct type names), normalizes property "type" to a JSON Schema primitive when possible, expands C++ constructor/initializer and common C++ literal patterns found in "default" values into Python primitives/objects/lists, ensures array-typed properties have array defaults (including handling one_or_many_property cases), updates array item type information when item types reference definitions, and converts any `enterprise_value` strings via process_enterprise_value.
899
900
900
901
Parameters:
901
-
properties (dict): Mapping of property names to property metadata dictionaries. Each property may include keys like "type", "default", "items", and "enterprise_value".
902
-
definitions (dict): Mapping of type names to JSON Schema definition dictionaries used to resolve $ref targets and to infer property shapes when expanding constructors.
902
+
properties (dict): Mapping of property names to metadata dictionaries. Relevant keys that may be modified include "type", "default", "items", and "enterprise_value".
903
+
definitions (dict): Mapping of definition names to JSON Schema definition dictionaries used to resolve $ref targets and to infer shapes for expanding constructor-style defaults.
903
904
904
905
Returns:
905
-
dict: The same `properties` mapping after in-place normalization and expansion of typesand defaults.
906
+
dict: The same `properties` mapping after in-place normalization and expansion of types, defaults, item types, and enterprise values.
"""Parse C++ constructor syntax into type name and arguments."""
921
+
"""
922
+
Parse a C++-style constructor or initializer expression into its type name and argument list.
923
+
924
+
Parses input forms such as `Type(arg1, arg2)`, `Type{arg1, arg2}`, or plain literals/enum-like tokens. For string literals the returned argument is a Python string value; for integer literals the returned argument is an int. Nested constructors and nested brace/paren groups are preserved as argument tokens.
925
+
926
+
Parameters:
927
+
s (str): The C++ expression to parse.
928
+
929
+
Returns:
930
+
tuple:
931
+
- type_name (str|None): The parsed type name for constructor forms, or `None` when `s` is a primitive literal or enum-like token.
932
+
- args (list): A list of argument tokens; tokens are raw strings for complex/nested arguments, Python `str` for quoted string literals, or `int` for integer literals.
933
+
"""
921
934
s=s.strip()
922
935
original_s=s
923
936
ifs.startswith("{") ands.endswith("}"):
@@ -964,13 +977,18 @@ def parse_constructor(s):
964
977
965
978
defprocess_cpp_patterns(arg_str):
966
979
"""
967
-
Process specific C++ patterns to user-friendly values.
980
+
Convert a C++-style expression string into a JSON-friendly literal representation.
968
981
969
-
Handles:
970
-
- net::unresolved_address("127.0.0.1", 9092) -> expands based on type definition
982
+
This function recognises common C++ patterns produced by the extractor and maps them to values suitable for JSON schema defaults and examples. Handled cases include:
971
983
- std::nullopt -> null
972
-
- fips_mode_flag::disabled -> "disabled"
973
-
- model::kafka_audit_logging_topic() -> dynamically looked up from source
984
+
- zero-argument functions (e.g., model::kafka_audit_logging_topic()) resolved from source when possible
This expands C++ constructor and initializer-list syntax into Python primitives, dictionaries, and lists suitable for JSON output. Supported transformations include:
1088
+
- String constructors and quoted literals → Python str.
1089
+
- Integer and boolean literals → Python int and bool.
1090
+
- Object constructors (Type(arg1, arg2) or Type{...}) → dict mapping constructor arguments to the object's properties when a corresponding type definition exists.
1091
+
- Nested constructors → nested dicts with their fields expanded.
1092
+
- Array initializer lists (e.g., {Type(...), Type(...)}) → Python list with each element expanded.
1093
+
- Special-case mappings for known type patterns (for example, an address-type constructor expanded into {"address", "port"} when the target type expects that shape).
1094
+
If a default cannot be resolved or the type is an enum, the original input is returned unchanged; the string "null" is converted to None. If default_str is not a string, it is returned as-is.
1071
1095
1072
-
This creates: [{address: "127.0.0.1", port: 9644}]
1096
+
Parameters:
1097
+
type_name (str): The resolved type name for the default value (e.g., "model::broker_endpoint" or a primitive type like "string").
1098
+
default_str (str | any): The C++ default expression to expand, or a non-string value already decoded.
1099
+
1100
+
Returns:
1101
+
The expanded Python representation of the default: a dict for objects, a list for arrays, a primitive (str/int/bool), None for null, or the original value/string when expansion is not possible.
0 commit comments