jwg4/flask-selfdoc

Question about Form Data

OsymandiasII opened this issue · 5 comments

Hello

In the 2nd example picture (/doc/private) you have a Form Data section under the Description for the route /post.
I checked the examples, but i can get it to work for me.
I have a template with this

<div class="desc">
                Description : {{doc.docstring}}
</div>

that display the content of what i put between """ ... """ in my code, and in your example you do this :

 """Create a new post.
    Form Data: title, content, authorid.
    """

'Create a new post ' i corectly going in the description and 'Form Data' i going to form data, however when i do the same thing, both go into the description.

How did you manage to add the FormData rule ?

Thanks

jwg4 commented

I don't know off the top of my head if this is correct or not - I'll check and get back to you (or fix it)!

Great. The best stuff would be if you can give the user the option to add custom rules, but if you can add the a rule for FormData its nice too.

jwg4 commented

The info about Form Data in the docstring isn't processed in any special way. It's just that the way it is formatted in the HTML makes it look that Form Data is an individual data field. Actually, it's just part of the docstring which appears as 'Description'.

You can add an arbitrary property to an endpoint just by putting it as a keyword argument to the autodoc.doc decorator.

In the endpoint from the example. that would mean replacing this:
@auto.doc(groups=['posts', 'private'])
with this:
@auto.doc(groups=['posts', 'private'], form_data="title, content. authorid")

If you want to have a space in the name of the field, it's a little trickier, you have to do:
@auto.doc(groups=['posts', 'private'], **{"Form Data":"title, content. authorid"})

I will update the docs to make this clearer, and also add tests to make sure this functionality actually works as intended.

jwg4 commented

@OsymandiasII did this solve your problem?

Yes 😄