File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 1
1
"""Java code generator for a given schema salad definition."""
2
2
import os
3
+ import re
3
4
import shutil
4
5
import string
5
6
from io import StringIO
28
29
# may even confuse things a bit so turning these off be default.
29
30
USE_ONE_OR_LIST_OF_TYPES = False
30
31
32
+ BASIC_JAVA_IDENTIFIER_RE = re .compile (r"[^0-9a-zA-Z]+" )
33
+
31
34
32
35
def _ensure_directory_and_write (path : Path , contents : str ) -> None :
33
36
_safe_makedirs (path .parent )
@@ -857,6 +860,7 @@ def expand_resource_template_to(resource: str, path: Path) -> None:
857
860
for example_name in os .listdir (self .examples ):
858
861
if example_name .startswith ("valid" ):
859
862
basename = os .path .basename (example_name ).rsplit ("." , 1 )[0 ]
863
+ basename = re .sub (BASIC_JAVA_IDENTIFIER_RE , "_" , basename )
860
864
example_tests += """
861
865
@org.junit.Test
862
866
public void test{basename}ByString() throws Exception {{
@@ -882,7 +886,7 @@ def expand_resource_template_to(resource: str, path: Path) -> None:
882
886
doc = (java.util.Map<String, Object>) YamlUtils.mapFromString(yaml);
883
887
RootLoader.loadDocument(doc, url.toString());
884
888
}}""" .format (
885
- basename = basename . replace ( "-" , "_" ). replace ( "." , "_" ) ,
889
+ basename = basename ,
886
890
example_name = example_name ,
887
891
)
888
892
You can’t perform that action at this time.
0 commit comments