django-ninja icon indicating copy to clipboard operation
django-ninja copied to clipboard

Add description to tags

Open Ismael opened this issue 1 year ago • 2 comments

Currently the only way to add a description to the tags is to include them manually as "openapi_extra" at the NinjaAPI constructor like so:

api = NinjaAPI(openapi_extra={"tags": [{
    "name": "Account",
    "description": "An Account can have users",
}]})

It would be ideal to be able to add the description to a Router. Something like this maybe:

router = Router(tag="Account", description="An Account can have users")

Or also support externalDocs:

accountTag = Tag("Account", description="An Account can have users", externalDocs_url="http://somewhere", externalDocs_description="A description")
router = Router(tags=[accountTag])

Reference: https://swagger.io/docs/specification/grouping-operations-with-tags/

Ismael avatar Mar 12 '24 21:03 Ismael

Hi @Ismael

you can achieve it with openapi_extra:


api = NinjaAPI(
    openapi_extra={ # < ------
        'tags': [
            {
                'name': 'tag1',
                'description': 'Some description goes here',
            }
        ]
    }
)


@api.post("/hello", tags=["tag1"])
def hello(request):
    return {'hello': 'World'}


SCR-20240314-sfoo

technically it's a global record on the whole swagger doc - so I guess it make sense to define it on the NinjaAPI level

vitalik avatar Mar 14 '24 19:03 vitalik

Yes, the feature request is to have a "nicer"? way to do it. Or maybe just document how it's done?

The docs make it sound like using openapi_extra would be to add "weird" stuff. I wasn't that familiar with the spec to know that that was the spot to define tag descriptions.

Ismael avatar Mar 14 '24 23:03 Ismael