22Request details for a CLI Operation
33"""
44
5- from typing import List , Optional
5+ from typing import Dict , List , Optional , Tuple
66
77from openapi3 .paths import MediaType
88from openapi3 .schemas import Schema
9+ from typing_extensions import Self
910
1011from linodecli .baked .parsing import simplify_description
1112from linodecli .baked .response import OpenAPIResponse
@@ -26,7 +27,7 @@ def __init__( # pylint: disable=too-many-arguments
2627 is_parent : bool = False ,
2728 parent : Optional [str ] = None ,
2829 depth : int = 0 ,
29- option_path : Optional [List [ str ]] = None ,
30+ option_variants : Optional [Dict [ Tuple , Self ]] = None ,
3031 ) -> None :
3132 """
3233 Parses a single Schema node into a argument the CLI can use when making
@@ -46,6 +47,8 @@ def __init__( # pylint: disable=too-many-arguments
4647 :type parent: Optional[str]
4748 :param depth: The depth of this argument, or how many parent arguments this argument has.
4849 :type depth: int
50+ :param option_variants: A mapping of options, defined using oneOf in the to spec,
51+ to a variant of this argument.
4952 """
5053 #: The name of this argument, mostly used for display and docs
5154 self .name = name
@@ -124,15 +127,18 @@ def __init__( # pylint: disable=too-many-arguments
124127 "instead of object's properties! This is a programming error."
125128 )
126129
127- self .option_path = option_path
130+ #: A mapping between option keys and argument variants.
131+ #: This is necessary because argparse requires a merged list of options
132+ #: but we still want to preserve these arguments for use in help pages.
133+ self .option_variants = option_variants or {}
128134
129135
130136def _parse_request_model (
131137 schema : Schema ,
132138 prefix : Optional [str ] = None ,
133139 parent : Optional [str ] = None ,
134140 depth : int = 0 ,
135- option_path : List [ str ] = None ,
141+ option_path : Optional [ Tuple [ str , ...] ] = None ,
136142) -> List [OpenAPIRequestArg ]:
137143 """
138144 Parses an OpenAPI schema into a list of OpenAPIRequest objects
@@ -149,29 +155,8 @@ def _parse_request_model(
149155 :rtype: list[OpenAPIRequestArg]
150156 """
151157
152- if option_path is None :
153- option_path = []
154-
155158 args = []
156159
157- if isinstance (schema , dict ):
158- schema = Schema (schema ["path" ], schema , schema ._root )
159-
160- for i , entry in enumerate (schema .oneOf or []):
161- if isinstance (entry , dict ):
162- entry = Schema (schema .path + ["oneOf" , i + 1 ], entry , schema ._root )
163-
164- args += _parse_request_model (
165- entry ,
166- prefix = prefix ,
167- parent = parent ,
168- depth = depth ,
169- option_path = option_path + [entry .title ],
170- )
171-
172- if schema .oneOf is not None :
173- return args
174-
175160 properties , required = _aggregate_schema_properties (schema )
176161
177162 if properties is None :
@@ -218,7 +203,6 @@ def _parse_request_model(
218203 is_parent = True ,
219204 parent = parent ,
220205 depth = depth ,
221- option_path = option_path ,
222206 )
223207 )
224208
@@ -238,7 +222,6 @@ def _parse_request_model(
238222 prefix = prefix ,
239223 parent = parent ,
240224 depth = depth ,
241- option_path = option_path ,
242225 )
243226 )
244227
0 commit comments