-
Notifications
You must be signed in to change notification settings - Fork 258
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 tags to swagger specification #230
Conversation
Codecov Report
@@ Coverage Diff @@
## master #230 +/- ##
==========================================
+ Coverage 88.18% 88.18% +<.01%
==========================================
Files 24 24
Lines 1193 1219 +26
==========================================
+ Hits 1052 1075 +23
- Misses 141 144 +3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just a couple of things to revisit.
R/parse-block.R
Outdated
@@ -179,6 +180,18 @@ parseBlock <- function(lineNum, file){ | |||
params[[name]] <- list(desc=paramMat[1,5], type=type, required=reqd) | |||
} | |||
|
|||
tagMat <- stringi::stri_match(line, regex="^#['\\*]\\s*@tag\\s+(\\S.+)\\s*") | |||
if (!is.na(tagMat[1,1])){ | |||
t <- gsub("_"," ",stri_trim_both(tagMat[1,2])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The underscore-to-space translation feels like a little too much magic to me. I think I'd prefer to just not handle whitespace for now and if people start asking for it then deal with it then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Updated in 8beafad
R/parse-globals.R
Outdated
}, | ||
apiTag={ | ||
tagMat <- stringi::stri_match(def, regex="^\\s*(\\w+)\\s+(\\S.+)\\s*$") | ||
name <- gsub("_"," ",tagMat[1,2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Updated in 8beafad
R/plumber-step.R
Outdated
@@ -133,6 +134,9 @@ PlumberEndpoint <- R6Class( | |||
if (!missing(responses)){ | |||
self$responses <- responses | |||
} | |||
if(!missing(tags) && !is.null(tags)){ | |||
self$tags <- I(tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me understand the I()
call here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only have one tag, we want to make sure it's boxed in.
In JSON we want tags: ["tagName"]
instead of tags: "tagName"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to have a comment inline for that so I don't lose track of it in the future, but that makes sense.
tests/testthat/test-globals.R
Outdated
@@ -28,7 +28,8 @@ test_that("parseGlobals works", { | |||
"#' @apiBasePath basepath", | |||
"#' @apiSchemes schemes", | |||
"#' @apiConsumes consumes", | |||
"#' @apiProduces produces") | |||
"#' @apiProduces produces", | |||
"#' @apiTag tag description") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add multiple tag definitions here for this test? And perhaps also a test that has redundant apiTag
definitions? I'd think that should fail but I don't believe that it does today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple tags added in test.
I've also added a test to check for redundant apiTag
definitions (= duplicates). Since swagger is pretty relaxed about unused tag definitions, I did not add a test to see wether all apiTag
definitions are also referenced in at least one endpoint.
R/parse-globals.R
Outdated
tagMat <- stringi::stri_match(def, regex="^\\s*(\\w+)\\s+(\\S.+)\\s*$") | ||
name <- gsub("_"," ",tagMat[1,2]) | ||
description <- tagMat[1,3] | ||
fields$tags <- rbind(fields$tags,data.frame(name=name,description=description)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we do a stringsAsFactors = FALSE here? I usually prefer it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Added in 1f509a0
Really excited to see more code decoration support! |
I saw the commits come in; let me know when this is ready for rereview and I'll take another pass! |
Ready for review! |
Looks great! I pushed one more commit for some doc updates and to add you to the DESCRIPTION file. I pulled the email from your public GitHub profile, but let me know if you'd prefer to be removed or use a different address. If that looks good, I'll go ahead and pull it in once tests pass! |
Sorry about squeezing in that last typo fix. Thanks for checking with me |
🎉 Thanks again for you contribution! |
Adding functionality to parse
tags
from plumber annotation and add to swagger-json.Example:
Which would create a swagger-ui with 4 tags:
name1
name2
randomName
name3 with whitepsace
Screenshot below: