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

Allow documenting route parameters #677

Merged
merged 2 commits into from
May 27, 2023
Merged

Allow documenting route parameters #677

merged 2 commits into from
May 27, 2023

Conversation

wilbrt
Copy link
Contributor

@wilbrt wilbrt commented May 24, 2023

Fixes #167

@akheron
Copy link
Owner

akheron commented May 24, 2023

Parameters can have non-unique names, as long as they appear in a different "parts" of the request.

From the OpenAPI spec:

4.8.12 Parameter Object §
Describes a single operation parameter.

A unique parameter is defined by a combination of a name and location.

[...]

in | string | REQUIRED. The location of the parameter. Possible values are "query", "header", "path" or "cookie".

There are two options for solving this:

  1. Instead of a single @reqparam tag, add separate tags @query, @header, @routeParam, @cookie to document parameters appearing in different places. (I used @routeParam instead of @path because typera exposes captured route parts in request.routeParams).
  2. Add a more generic @param IN NAME DESCRIPTION. The IN part would be either query, header, path, or cookie, as per the OpenAPI spec.

I don't really have an opinion about which one is better.

@wilbrt
Copy link
Contributor Author

wilbrt commented May 25, 2023

Ah, I didn't think of that. The @reqparam tag has now been split into @query, @header, @routeParam and @cookie as suggested.

@akheron
Copy link
Owner

akheron commented May 25, 2023

Great stuff!

One more thing: This now seems to set schema.example instead of description 🤔 There would also be example on the "top level" of the parameter.

Eventually users would probably want to set either description or example or both. I'm not sure how to solve this in a clean way. Adding JSDoc tags for descriptions and examples adds quite a bit of noise.

@wilbrt
Copy link
Contributor Author

wilbrt commented May 26, 2023

Works now as planned,I think. Not 100% sure about the current routeParam validation implementation.

wilbrt and others added 2 commits May 27, 2023 10:34
Implemented routeParam descriptions and validation
@akheron akheron changed the title Add pathparameter support Allow documenting route parameters May 27, 2023
@akheron akheron merged commit b8e0131 into akheron:main May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support documentation for path parameters
2 participants