fix: resolve CI linting and code quality issues
- Remove unused imports across all generator files - Remove unused variables (spec, url_params, query_params, test_name) - Fix f-strings without placeholders in auth.py and go.py - Fix duplicate BASIC auth handling with wrong indentation - Add missing pytest fixtures (sample_openapi_spec, temp_spec_file, temp_json_spec_file) - Add missing TemplateRenderError import to generator files
This commit is contained in:
@@ -6,8 +6,8 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader, TemplateSyntaxError, UndefinedError
|
||||
|
||||
from ..core import SpecParser, AuthConfig
|
||||
from ..core.exceptions import GeneratorError, TemplateRenderError
|
||||
from ..core import SpecParser
|
||||
from ..core.exceptions import TemplateRenderError
|
||||
|
||||
|
||||
class GoGenerator:
|
||||
@@ -132,7 +132,6 @@ class GoGenerator:
|
||||
"""
|
||||
test_name = self._generate_test_name(endpoint)
|
||||
params = self._generate_params(endpoint)
|
||||
url_params = self._generate_url_params(endpoint)
|
||||
|
||||
test_code = f'''
|
||||
func Test{test_name}(t *testing.T) {{
|
||||
@@ -201,11 +200,11 @@ func Test{test_name}(t *testing.T) {{
|
||||
|
||||
if param["in"] == "path":
|
||||
params.append(f'{param_name} := "test_{param_name}"')
|
||||
params.append(f'url = strings.Replace(url, "{{'+param_name+'}}", {param_name}, 1)')
|
||||
params.append('url = strings.Replace(url, "' + '{' + param_name + '}' + '", ' + param_name + ', 1)')
|
||||
|
||||
elif param["in"] == "query":
|
||||
params.append(f'q := url.Values{{{param_name}: []string{{"test"}}}}')
|
||||
params.append(f'url += "?" + q.Encode()')
|
||||
params.append('url += "?" + q.Encode()')
|
||||
|
||||
return "\n ".join(params) if params else ""
|
||||
|
||||
@@ -219,11 +218,10 @@ func Test{test_name}(t *testing.T) {{
|
||||
String containing URL parameter handling.
|
||||
"""
|
||||
path_params = [p for p in endpoint.get("parameters", []) if p["in"] == "path"]
|
||||
query_params = [p for p in endpoint.get("parameters", []) if p["in"] == "query"]
|
||||
|
||||
parts = []
|
||||
|
||||
for param in path_params:
|
||||
parts.append(f'strings.Replace(url, "{{'+param['name']+'}}", "test_' + param['name'] + '", 1)')
|
||||
parts.append('strings.Replace(url, "' + '{' + param['name'] + '}' + '", "test_' + param['name'] + '", 1)')
|
||||
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user