@@ -45,14 +45,14 @@ def __init__(
45
45
should_p
8000
arse: Whether to parse the operation during initialization.
46
46
"""
47
47
if isinstance (operation , dict ):
48
- self .operation = Operation .model_validate (operation )
48
+ self ._operation = Operation .model_validate (operation )
49
49
elif isinstance (operation , str ):
50
- self .operation = Operation .model_validate_json (operation )
50
+ self ._operation = Operation .model_validate_json (operation )
51
51
else :
52
- self .operation = operation
52
+ self ._operation = operation
53
53
54
- self .params : List [ApiParameter ] = []
55
- self .return_value : Optional [ApiParameter ] = None
54
+ self ._params : List [ApiParameter ] = []
55
+ self ._return_value : Optional [ApiParameter ] = None
56
56
if should_parse :
57
57
self ._process_operation_parameters ()
58
58
self ._process_request_body ()
@@ -67,13 +67,13 @@ def load(
67
67
return_value : Optional [ApiParameter ] = None ,
68
68
) -> 'OperationParser' :
69
69
parser = cls (operation , should_parse = False )
70
- parser .params = params
71
- parser .return_value = return_value
70
+ parser ._params = params
71
+ parser ._return_value = return_value
72
72
return parser
73
73
74
74
def _process_operation_parameters (self ):
75
75
"""Processes parameters from the OpenAPI operation."""
76
- parameters = self .operation .parameters or []
76
+ parameters = self ._operation .parameters or []
77
77
for param in parameters :
78
78
if isinstance (param , Parameter ):
79
79
original_name = param .name
@@ -86,7 +86,7 @@ def _process_operation_parameters(self):
86
86
# param.required can be None
87
87
required = param .required if param .required is not None else False
88
88
89
- self .params .append (
89
+ self ._params .append (
90
90
ApiParameter (
91
91
original_name = original_name ,
92
92
param_location = location ,
@@ -98,7 +98,7 @@ def _process_operation_parameters(self):
98
98
99
99
def _process_request_body (self ):
100
100
"""Processes the request body from the OpenAPI operation."""
101
- request_body = self .operation .requestBody
101
+ request_body = self ._operation .requestBody
102
102
if not request_body :
103
103
return
104
104
@@ -114,7 +114,7 @@ def _process_request_body(self):
114
114
if schema and schema .type == 'object' :
115
115
properties = schema .properties or {}
116
116
for prop_name , prop_details in properties .items ():
117
- self .params .append (
117
+ self ._params .append (
118
118
ApiParameter (
119
119
original_name = prop_name ,
120
120
param_location = 'body' ,
@@ -124,7 +124,7 @@ def _process_request_body(self):
124
124
)
125
125
126
126
elif schema and schema .type == 'array' :
127
- self .params .append (
127
+ self ._params .append (
128
128
ApiParameter (
129
129
original_name = 'array' ,
130
130
param_location = 'body' ,
@@ -133,7 +133,7 @@ def _process_request_body(self):
133
133
)
134
134
)
135
135
else :
136
- self .params .append (
136
+ self ._params .append (
137
137
# Empty name for unnamed body param
138
138
ApiParameter (
139
139
original_name = '' ,
@@ -147,7 +147,7 @@ def _process_request_body(self):
147
147
def _dedupe_param_names (self ):
148
148
"""Deduplicates parameter names to avoid conflicts."""
149
149
params_cnt = {}
150
- for param in self .params :
150
+ for param in self ._params :
151
151
name = param .py_name
152
152
if name not in params_cnt :
153
153
params_cnt [name ] = 0
@@ -157,7 +157,7 @@ def _dedupe_param_names(self):
157
157
158
158
def _process_return_value (self ) -> Parameter :
159
159
"""Returns a Parameter object representing the return type."""
160
- responses = self .operation .responses or {}
160
+ responses = self ._operation .responses or {}
161
161
# Default to Any if no 2xx response or if schema is missing
162
162
return_schema = Schema (type = 'Any' )
163
163
@@ -174,50 +174,50 @@ def _process_return_value(self) -> Parameter:
174
174
return_schema = content [mime_type ].schema_
175
175
break
176
176
177
- self .return_value = ApiParameter (
177
+ self ._return_value = ApiParameter (
178
178
original_name = '' ,
179
179
param_location = '' ,
180
180
param_schema = return_schema ,
181
181
)
182
182
183
183
def get_function_name (self ) -> str :
184
184
"""Returns the generated function name."""
185
- operation_id = self .operation .operationId
185
+ operation_id = self ._operation .operationId
186
186
if not operation_id :
187
187
raise ValueError ('Operation ID is missing' )
188
188
return to_snake_case (operation_id )[:60 ]
189
189
190
190
def get_return_type_hint (self ) -> str :
191
191
"""Returns the return type hint string (like 'str', 'int', etc.)."""
192
- return self .return_value .type_hint
192
+ return self ._return_value .type_hint
193
193
194
194
def get_return_type_value (self ) -> Any :
195
195
"""Returns the return type value (like str, int, List[str], etc.)."""
196
- return self .return_value .type_value
196
+ return self ._return_value .type_value
197
197
198
198
def get_parameters (self ) -> List [ApiParameter ]:
199
199
"""Returns the list of Parameter objects."""
200
- return self .params
200
+ return self ._params
201
201
202
202
def get_return_value (self ) -> ApiParameter :
203
203
"""Returns the list of Parameter objects."""
204
- return self .return_value
204
+ return self ._return_value
205
205
206
206
def get_auth_scheme_name (self ) -> str :
207
207
"""Returns the name of the auth scheme for this operation from the spec."""
208
- if self .operation .security :
209
- scheme_name = list (self .operation .security [0 ].keys ())[0 ]
208
+ if self ._operation .security :
209
+ scheme_name = list (self ._operation .security [0 ].keys ())[0 ]
210
210
return scheme_name
211
211
return ''
212
212
213
213
def get_pydoc_string (self ) -> str :
214
214
"""Returns the generated PyDoc string."""
215
- pydoc_params = [param .to_pydoc_string () for param in self .params ]
215
+ pydoc_params = [param .to_pydoc_string () for param in self ._params ]
216
216
pydoc_description = (
217
- self .operation .summary or self .operation .description or ''
217
+ self ._operation .summary or self ._operation .description or ''
218
218
)
219
219
pydoc_return = PydocHelper .generate_return_doc (
220
- self .operation .responses or {}
220
+ self ._operation .responses or {}
221
221
)
222
222
pydoc_arg_list = chr (10 ).join (
223
223
f' { param_doc } ' for param_doc in pydoc_params
@@ -236,12 +236,12 @@ def get_json_schema(self) -> Dict[str, Any]:
236
236
"""Returns the JSON schema for the function arguments."""
237
237
properties = {
238
238
p .py_name : jsonable_encoder (p .param_schema , exclude_none = True )
239
- for p in self .params
239
+ for p in self ._params
240
240
}
241
241
return {
242
242
'properties' : properties ,
243
- 'required' : [p .py_name for p in self .params if p .required ],
244
- 'title' : f"{ self .operation .operationId or 'unnamed' } _Arguments" ,
243
+ 'required' : [p .py_name for p in self ._params if p .required ],
244
+ 'title' : f"{ self ._operation .operationId or 'unnamed' } _Arguments" ,
245
245
'type' : 'object' ,
246
246
}
247
247
@@ -253,11 +253,11 @@ def get_signature_parameters(self) -> List[inspect.Parameter]:
253
253
inspect .Parameter .POSITIONAL_OR_KEYWORD ,
254
254
annotation = param .type_value ,
255
255
)
256
- for param in self .params
256
+ for param in self ._params
257
257
]
258
258
259
259
def get_annotations (self ) -> Dict [str , Any ]:
260
260
"""Returns a dictionary of parameter annotations for the function."""
261
- annotations = {p .py_name : p .type_value for p in self .params }
261
+ annotations = {p .py_name : p .type_value for p in self ._params }
262
262
annotations ['return' ] = self .get_return_type_value ()
263
263
return annotations
0 commit comments