Skip to content

How to add nullable type when using MAP_VALUES_AS_ADDITIONAL_PROPERTIES? #400

Closed Answered by CarstenWickner
namgaxilem asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @namgaxilem,

For now, you might want to give this a try:

configBuilder.forTypesInGeneral().withAdditionalPropertiesResolver((scope, context) -> {
        if (scope.getType().isInstanceOf(Map.class)) {
            ObjectNode schema = context.getGeneratorConfig().createObjectNode();
            ArrayNode anyOf = schema.putArray(context.getKeyword(SchemaKeyword.TAG_ANYOF));
            anyOf.addObject().put(context.getKeyword(SchemaKeyword.TAG_TYPE), context.getKeyword(SchemaKeyword.TAG_TYPE_NULL));
            anyOf.add(context.createStandardDefinitionReference(scope.getTypeParameterFor(Map.class, 1), null));
            return schema;
        }
        return null;
    });

Need to find …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@namgaxilem
Comment options

Answer selected by namgaxilem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants