"""
Doc for type `Foo`.
"""
struct Foo
"""
Doc for field Foo.x
"""
x::Int
Foo() = new(2)
end
"""
Doc for type `Bar`.
"""
struct Bar end
Base.propertynames(::Bar) = (:x,)
function Base.getproperty(a::Bar,s::Symbol)
if s == :x
2
else
error("type Bar has no field $s")
end
end
function Base.show(io::IO,::Bar)
print(io,"Bar(2)")
end
Another solution I can think of is to create a getter getx(a::Bar) = a.x and document this getter and inform the users of the package that properties are documented in the corresponding getter.
If there is an explicit accessor function, it is of course good practice to document that.
But one advantage of property accessors is that you don’t have to bother with defining a function for this. How to document that is somewhat of an open question while practice evolves, but at least discoverability is fine thanks to propertynames.