micronaut-openapi icon indicating copy to clipboard operation
micronaut-openapi copied to clipboard

Support for JsonAnySetter/AnyGetter wrapper classes

Open StephenOTT opened this issue 6 years ago • 2 comments

If you have a wrapping class for a Map<String, Any>, there is no model converter to correct the object. If you had a List<MyWrappingObject>, the swagger produced is

{
   "objects": [
      {
         "myObjects": { }
      }
   ]
   }

where myObjects is the field in MyWrappingObject with @JsonAnySetter and @get:JsonAnyGetter

StephenOTT avatar Feb 11 '20 20:02 StephenOTT

@croudet any suggestions on best way to deal with this? The best i could think of at the moment is to use a custom Schema on the parent property that uses this pojo, but the micronaut-opeapi generation does not override the pojo impl schema.

StephenOTT avatar Feb 17 '20 17:02 StephenOTT

I think the "solution" for this is to recommend applying the @field:Hidden annotation on the single property such as:

@Schema(name = "some-object", description = "Some Object", type = "object")
data class SomeObject(
        @JsonAnySetter
        @get:JsonAnyGetter
        @field:Hidden
        val someObject: Map<String, Any> = mutableMapOf()
)

which will generate a schema of:

    some-object:
      type: object
      description: Some Object

StephenOTT avatar Feb 19 '20 23:02 StephenOTT