Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description to tags #1106

Open
Ismael opened this issue Mar 12, 2024 · 2 comments
Open

Add description to tags #1106

Ismael opened this issue Mar 12, 2024 · 2 comments

Comments

@Ismael
Copy link

Ismael commented Mar 12, 2024

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/

@vitalik
Copy link
Owner

vitalik commented Mar 14, 2024

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

@Ismael
Copy link
Author

Ismael commented Mar 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants