Skip to content

Commit 3173950

Browse files
authored
test(generator): add edge case tests for OpenAPI parser content cleaning (#120)
Add comprehensive tests for _clean_spec_content method covering: - UTF-8 BOM removal - Smart quotes replacement - Windows line endings (CRLF to LF) - Non-breaking spaces conversion - En-dash and em-dash character conversion Refs #109
1 parent fc19ea0 commit 3173950

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

generator/tests/parser/test_openapi_parser.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,43 @@ def test_get_security_schemes(self, mock_fetch):
201201
self.assertEqual(security_schemes["bearerAuth"]["type"], "http")
202202
self.assertEqual(security_schemes["bearerAuth"]["scheme"], "bearer")
203203
self.assertEqual(security_schemes["bearerAuth"]["bearerFormat"], "JWT")
204+
205+
def test_clean_spec_content_utf8_bom(self):
206+
"""Test UTF-8 BOM removal."""
207+
parser = OpenAPIParser("dummy_url")
208+
content_with_bom = '\ufeff{"openapi": "3.0.0"}'
209+
cleaned = parser._clean_spec_content(content_with_bom)
210+
self.assertFalse(cleaned.startswith("\ufeff"))
211+
self.assertTrue(cleaned.startswith("{"))
212+
213+
def test_clean_spec_content_smart_quotes(self):
214+
"""Test smart quotes replacement."""
215+
parser = OpenAPIParser("dummy_url")
216+
content_with_smart_quotes = "“openapi”: “3.0.0”"
217+
cleaned = parser._clean_spec_content(content_with_smart_quotes)
218+
self.assertIn('"openapi": "3.0.0"', cleaned)
219+
220+
def test_clean_spec_content_windows_line_endings(self):
221+
"""Test CRLF to LF conversion."""
222+
parser = OpenAPIParser("dummy_url")
223+
content_with_crlf = '{\r\n"openapi": "3.0.0"\r\n}'
224+
cleaned = parser._clean_spec_content(content_with_crlf)
225+
self.assertNotIn("\r\n", cleaned)
226+
self.assertIn("\n", cleaned)
227+
228+
def test_clean_spec_content_non_breaking_spaces(self):
229+
"""Test non-breaking spaces conversion."""
230+
parser = OpenAPIParser("dummy_url")
231+
content_with_nbsp = '{\u00a0"openapi":\u00a0"3.0.0"\u00a0}'
232+
cleaned = parser._clean_spec_content(content_with_nbsp)
233+
self.assertNotIn("\u00a0", cleaned)
234+
self.assertIn(" ", cleaned)
235+
236+
def test_clean_spec_content_dash_characters(self):
237+
"""Test en-dash and em-dash conversion."""
238+
parser = OpenAPIParser("dummy_url")
239+
content_with_dashes = '{"desc": "en–dash, em—dash"}'
240+
cleaned = parser._clean_spec_content(content_with_dashes)
241+
self.assertNotIn("–", cleaned)
242+
self.assertNotIn("—", cleaned)
243+
self.assertIn("-", cleaned)

0 commit comments

Comments
 (0)