5
5
import java .nio .file .Files ;
6
6
import java .nio .file .Path ;
7
7
import java .nio .file .StandardOpenOption ;
8
+ import java .util .ArrayList ;
8
9
import java .util .Arrays ;
9
10
import java .util .Collection ;
10
11
import java .util .Collections ;
46
47
* patch request schema will be moved to the CRD status.
47
48
*/
48
49
public class CrdResourceGen {
50
+
51
+ private static class FieldNameType {
52
+ String name ;
53
+ String type ;
54
+ FieldNameType (String name , String type ) {
55
+ this .name = name ;
56
+ this .type = type ;
57
+ }
58
+ }
59
+
60
+
49
61
private static final Logger LOG = LoggerFactory .getLogger (CrdResourceGen .class );
50
62
private static final String NODE_TEMPLATE = "{\" type\" : \" %s\" }" ;
51
63
private final Path path ;
@@ -55,6 +67,8 @@ public class CrdResourceGen {
55
67
private final ParameterResolver resolver ;
56
68
private final ObjectMapper objMapper = new ObjectMapper ();
57
69
70
+
71
+
58
72
59
73
public CrdResourceGen (Path path , Path openApiJson , Name name , CrudMapper mapper , ParameterResolver resolver ) {
60
74
super ();
@@ -112,24 +126,31 @@ private void mapProperties(JsonNode jsonNodeTree, JSONSchemaPropsBuilder specBui
112
126
private void addMissingFieldsFromPathParamMappings (Set <Entry <String , JsonNode >> fields , String prefix ) {
113
127
resolver .getPathParamMappingKeys ().stream ()
114
128
.filter (this ::oneOfCrudPathsMatches )
115
- //TODO Determine the type of the param
116
- // Use the path to determine the params and add info to param 1,2,3
117
- .flatMap (s -> resolver .paramMappingValueList (resolver .getPathParamMappings ().get (s )).stream ())
118
- .filter (v -> v .startsWith (prefix + "." ))
129
+ .flatMap (s -> {
130
+ List <String > paramMappingValueList = resolver .paramMappingValueList (resolver .getPathParamMappings ().get (s ));
131
+ List <FieldNameType > fieldEntries = new ArrayList <>();
132
+ for (int i = 0 ; i < paramMappingValueList .size (); i ++) {
133
+ fieldEntries .add (new FieldNameType (paramMappingValueList .get (i ), resolver .getParameterType (s , i )
134
+ .map (p -> p .getSchema ().getType ().toString ()).orElse ("string" )));
135
+ }
136
+ return fieldEntries .stream ();
137
+ })
138
+ .filter (v -> v .name .startsWith (prefix + "." ))
119
139
.map (v -> removePrefix (prefix , v ))
120
- .filter (v -> fields .stream ().noneMatch (e -> e .getKey ().equals (v )))
140
+ .filter (v -> fields .stream ().noneMatch (e -> e .getKey ().equals (v . name )))
121
141
.forEach (v -> {
122
142
try {
123
-
124
- fields .add (Map .entry (v , objMapper .readTree (String .format (NODE_TEMPLATE , "string" ))));
143
+ System . out . println ( v . name );
144
+ fields .add (Map .entry (v . name , objMapper .readTree (String .format (NODE_TEMPLATE , v . type ))));
125
145
} catch (JsonProcessingException e ) {
126
146
LOG .error ("Error adding JSON node" , e );
127
147
}
128
- });
148
+ });
129
149
}
130
150
131
- private String removePrefix (String prefix , String v ) {
132
- return v .substring (prefix .length () + 1 );
151
+ private FieldNameType removePrefix (String prefix , FieldNameType fieldNameType ) {
152
+ fieldNameType .name = fieldNameType .name .substring (prefix .length () + 1 );
153
+ return fieldNameType ;
133
154
}
134
155
135
156
private boolean oneOfCrudPathsMatches (String s ) {
0 commit comments