Using withDefaultResolver() or withEnumResolver() in groovy code results in error #468
-
| 
         When I use either  Below is my code: class CreatePipelineJsonSchema {
    static void main(String[] args) {
        SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_7, OptionPreset.PLAIN_JSON);
        configBuilder.forFields()
                .withRequiredCheck(field ->  field.getAnnotationConsideringFieldAndGetter(Required.class)!= null);
        configBuilder.forFields().withDefaultResolver(field -> {
            JsonProperty annotation = field.getAnnotationConsideringFieldAndGetter(JsonProperty.class);
            return annotation == null || annotation.defaultValue().isEmpty() ? null : annotation.defaultValue();
        });
        SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES).build();
        SchemaGenerator generator = new SchemaGenerator(config);
        JsonNode jsonSchema = generator.generateSchema(ConfigurationForSchema.class);
        Gson gson = new GsonBuilder().setPrettyPrinting().create()
       def sdf = gson.fromJson(jsonSchema.toString(), JsonObject.class)
         gson.toJson(sdf)
        File schemaFile = new File("pipeline-schema.json")
        schemaFile.createNewFile()
        CommonUtils.writeToFile(schemaFile.getAbsolutePath(), gson.toJson(sdf))
    }
}This is my annotated field @Required
@JsonProperty(defaultValue = "BuildKit")
private String toolI am seeing the same behavior  when using   How can I implement defaults and enumerate values for a string?  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
| 
         Hi @eyammer, This looks like a Groovy specific issue: your arrow/lambda functions are being instantiated as a "proxy" – or rather the default implementation of the  The   | 
  
Beta Was this translation helpful? Give feedback.
Hi @eyammer,
This looks like a Groovy specific issue: your arrow/lambda functions are being instantiated as a "proxy" – or rather the default implementation of the
StatefulConfiginterface'sresetAfterSchemaGeneration()method – and that "proxy" is then rejected by the Java module system.The
StatefulConfiginterface was introduced with version4.29.0.Can you please try your code against version
4.28.0of the schema generator, to confirm that this is to blame?