teamcarma / swagger-jaxrs-doclet

This fork is no longer actively maintained, please switch to https://github.com/conorroche/swagger-doclet
Apache License 2.0
81 stars 38 forks source link

Support conversion for value types in models #110

Open bedag-moo opened 9 years ago

bedag-moo commented 9 years ago

We sometimes use custom value types to enforce type safety in our model, and register converters to unwrap these values into strings. Is there any way we can have the doclet recognize these type replacements when generating the swagger documentation?

Specifically, I have something like:

public class Model {
    public TechId id;
}

@XmlJavaTypeAdapter(TechId.XmlConverter.class)
public class TechId {
    private final UUID uuid;

    public TechId(String s) {
        uuid = UUID.fromString(s);
    }

    @Override
    public String toString() {
        uuid.toString();
    }

    public static class XmlConverter extends XmlAdapter<String, TechId> {
        @Override
        public TechId unmarshal(String v) throws Exception {
            return new TechId(v);
        }

        @Override
        public String marshal(TechId v) throws Exception {
            return v.toString();
        }
    }
}

and was hoping for the doclet to recognize the type replacement, but it didn't, i.e. the type of Model.id is not string, but TechId with a property uuid.

bedag-moo commented 9 years ago

Meanwhile, I found the -stringTypePrefixes option, which can act as a work around. I must have missed it in the wall of options.

Still, if it isn't too much trouble, it would be nice for the doclet to detect the type mapping automatically.