Ask a Question

Support for reference types (e.g. AtomicReference<String>)

dpr
Visitor

Support for reference types (e.g. AtomicReference<String>)

I recently posted this question on Stackoverflow but there not too much going on. Thus is decided to go for the cross post...

 

Basically I want swagger to handle Java's `AtomicReference` similar to the way `java.util.Optional` is handled during generation of the API specs. Jackson supports this out-of-the-box (and Optional with some extensions) but I found no way to make swagger handle this as desired.

 

I got a domain class:

 

 

@JsonInclude(value = Include.NON_NULL)
public class MyDomainObject {
  private AtomicReference<String> description;

  public AtomicReference<String> getDescription() {
    return description;
  }

  public void setDescription(AtomicReference<String> description) {
    this.description = description;
  }
}

 

 

 

And the corresponding type definition in the generated swagger looks like this:

 

 

definitions:
  MyDomainObject:
    type: "object"
    properties:
      description:
        $ref: "#/definitions/AtomicReferenceString"

  AtomicReferenceString:
    type: "object"
    properties:
      opaque:
        type: "string"
      acquire:
        type: "string"
      plain:
        type: "string"

 

 

 

But this is not correct as a JSON value for this type would look like this:

 

 

{
  description: "Some valuable text"
}

 

 

 

That is the swagger should simply look like this:

 

 

MyDomainObject:
  type: "object"
  properties:
    description:
      type: "string"

 

 

 

Is there a way to make swagger unwarp the `AtomicReference` as it does with `java.util.Optional` already?

0 REPLIES 0
cancel
Showing results for 
Search instead for 
Did you mean: