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

show more available method signatures in embedded API viewer #982

Merged
merged 1 commit into from
Jan 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* 1.57 (unreleased)
* Allow `DashboardPortletContext` to be extended
([#981](https://github.com/jenkinsci/job-dsl-plugin/pull/981))
* Show more available method signatures in embedded API viewer
([#982](https://github.com/jenkinsci/job-dsl-plugin/pull/982))
* 1.56 (January 06 2016)
* Fixed support for
[Config File Provider Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,43 @@ class EmbeddedApiDocGenerator {
}
knownMethods.addAll(extensions*.name)

methods.each { JSONObject method ->
if (!hasOptionalClosureSignature(method)) {
knownMethods.remove(method.getString('name'))
}
}

Map<String, DescribableModel> symbols = findDescribableModels(extensibleContextClass, knownMethods)
symbols.sort().each { String symbol, DescribableModel model ->
methods << generateMethod(symbol, model)
JSONObject method = methods.find { it.getString('name') == symbol } as JSONObject
if (method) {
method.getJSONArray('signatures').add(generateSignature(model))
} else {
methods << generateMethod(symbol, model)
}
}
}
}

private static boolean hasOptionalClosureSignature(JSONObject method) {
method.getJSONArray('signatures').any { JSONObject signature ->
isOptionalClosureSignature(signature)
}
}

private static boolean isOptionalClosureSignature(JSONObject signature) {
if (!signature.has('parameters')) {
return true
}
JSONArray parameters = signature.getJSONArray('parameters')
if (parameters.size() > 1) {
return false
} else if (parameters.empty) {
return true
}
parameters[0].getString('type') == 'Closure'
}

/**
* Generates an extension method for an {@link ContextExtensionPoint} of a built-in context.
*/
Expand Down
4 changes: 4 additions & 0 deletions job-dsl-plugin/src/test/resources/expected-dsl.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
}
],
"extension": true
},
{
"parameters": [],
"generated": true
}
]
},
Expand Down