25
25
import org .apache .commons .lang3 .NotImplementedException ;
26
26
import org .apache .logging .log4j .LogManager ;
27
27
import org .apache .logging .log4j .Logger ;
28
+ import org .opensearch .client .codegen .model .overrides .Overrides ;
29
+ import org .opensearch .client .codegen .model .overrides .PropertyOverride ;
28
30
import org .opensearch .client .codegen .openapi .HttpStatusCode ;
29
31
import org .opensearch .client .codegen .openapi .In ;
30
32
import org .opensearch .client .codegen .openapi .JsonPointer ;
@@ -48,14 +50,17 @@ public class SpecTransformer {
48
50
@ Nonnull
49
51
private final OperationGroupMatcher matcher ;
50
52
@ Nonnull
53
+ private final Overrides overrides ;
54
+ @ Nonnull
51
55
private final Namespace root = new Namespace ();
52
56
@ Nonnull
53
57
private final Set <OpenApiSchema > visitedSchemas = new HashSet <>();
54
58
@ Nonnull
55
59
private final Map <OpenApiSchema , Type > schemaToType = new ConcurrentHashMap <>();
56
60
57
- public SpecTransformer (@ Nonnull OperationGroupMatcher matcher ) {
61
+ public SpecTransformer (@ Nonnull OperationGroupMatcher matcher , @ Nonnull Overrides overrides ) {
58
62
this .matcher = Objects .requireNonNull (matcher , "matcher must not be null" );
63
+ this .overrides = Objects .requireNonNull (overrides , "overrides must not be null" );
59
64
}
60
65
61
66
@ Nonnull
@@ -285,9 +290,12 @@ private void visitInto(OpenApiSchema schema, ObjectShape shape) {
285
290
final var additionalProperties = new ArrayList <OpenApiSchema >();
286
291
final var required = collectObjectProperties (schema , properties , additionalProperties );
287
292
288
- properties .forEach (
289
- (k , v ) -> shape .addBodyField (new Field (k , mapType (v ), required .contains (k ), v .getDescription ().orElse (null ), null ))
290
- );
293
+ final var overrides = this .overrides .getSchema (schema .getPointer ());
294
+
295
+ properties .forEach ((k , v ) -> {
296
+ var type = overrides .flatMap (so -> so .getProperty (k )).flatMap (PropertyOverride ::getMappedType ).orElseGet (() -> mapType (v ));
297
+ shape .addBodyField (new Field (k , type , required .contains (k ), v .getDescription ().orElse (null ), null ));
298
+ });
291
299
292
300
if (!additionalProperties .isEmpty ()) {
293
301
var valueSchema = additionalProperties .size () == 1 ? additionalProperties .get (0 ) : OpenApiSchema .ANONYMOUS_UNTYPED ;
0 commit comments