-
Notifications
You must be signed in to change notification settings - Fork 28
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
misc: add visibility
build setting
#951
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a4f1190
Generate internal-only clients with internal visibility
lauzadis 2440471
changelog
lauzadis 3515130
ktlint
lauzadis 46bbf12
Fix test shape ID
lauzadis 51d6df8
Replace toList import
lauzadis f88aaa5
Also remove endpoints-related constructs from the API
lauzadis 5621498
ktlintFormat
lauzadis 8733525
a word
lauzadis 7f14f8d
Reduce configuration to single `visibility` member under new `api` se…
lauzadis 506da38
Make `visibility` an enum value defaulting to `public`
lauzadis 245559f
Use `#L` instead of `$visibility`
lauzadis 7c43ce9
ktlint
lauzadis 816d6bf
update docs
lauzadis c5d14d4
add tests
lauzadis c3b41cf
update lowercase function
lauzadis a249bef
Throw IllegalArgumentException, override toString
lauzadis c0ec3a3
ktlint
lauzadis 4b58f2e
add test for explicit `public` visibility
lauzadis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "b6288fbe-a409-473c-a6ac-12c3c310b963", | ||
"type": "misc", | ||
"description": "Generate internal-only clients with `internal` visibility" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ private const val PACKAGE_NAME = "name" | |
private const val PACKAGE_VERSION = "version" | ||
private const val PACKAGE_DESCRIPTION = "description" | ||
private const val BUILD_SETTINGS = "build" | ||
private const val API_SETTINGS = "api" | ||
|
||
// Optional specification of sdkId for models that provide them, otherwise Service's shape id name is used | ||
private const val SDK_ID = "sdkId" | ||
|
@@ -37,6 +38,7 @@ data class KotlinSettings( | |
val pkg: PackageSettings, | ||
val sdkId: String, | ||
val build: BuildSettings = BuildSettings.Default, | ||
val api: ApiSettings = ApiSettings.Default, | ||
) { | ||
|
||
/** | ||
|
@@ -91,11 +93,13 @@ data class KotlinSettings( | |
// Load the sdk id from configurations that define it, fall back to service name for those that don't. | ||
val sdkId = config.getStringMemberOrDefault(SDK_ID, serviceId.name) | ||
val build = config.getObjectMember(BUILD_SETTINGS) | ||
val api = config.getObjectMember(API_SETTINGS) | ||
return KotlinSettings( | ||
serviceId, | ||
PackageSettings(packageName, version, desc), | ||
sdkId, | ||
BuildSettings.fromNode(build), | ||
ApiSettings.fromNode(api), | ||
) | ||
} | ||
} | ||
|
@@ -170,8 +174,7 @@ data class BuildSettings( | |
fun fromNode(node: Optional<ObjectNode>): BuildSettings = node.map { | ||
val generateFullProject = node.get().getBooleanMemberOrDefault(ROOT_PROJECT, false) | ||
val generateBuildFiles = node.get().getBooleanMemberOrDefault(GENERATE_DEFAULT_BUILD_FILES, true) | ||
val generateMultiplatformProject = | ||
node.get().getBooleanMemberOrDefault(GENERATE_MULTIPLATFORM_MODULE, false) | ||
val generateMultiplatformProject = node.get().getBooleanMemberOrDefault(GENERATE_MULTIPLATFORM_MODULE, false) | ||
val annotations = node.get().getArrayMember(ANNOTATIONS).map { | ||
it.elements.mapNotNull { node -> | ||
node.asStringNode().map { stringNode -> | ||
|
@@ -193,3 +196,42 @@ data class BuildSettings( | |
class UnresolvableProtocolException(message: String) : CodegenException(message) | ||
|
||
private fun <T> Optional<T>.orNull(): T? = if (isPresent) get() else null | ||
|
||
/** | ||
* The visibility of code-generated classes, objects, interfaces, etc. | ||
* Valid values are `public` and `internal`. `private` not supported because codegen would not compile with private classes. | ||
*/ | ||
enum class Visibility(val value: String) { | ||
PUBLIC("public"), | ||
INTERNAL("internal"), | ||
; | ||
|
||
companion object { | ||
public fun fromValue(value: String): Visibility = when (value.lowercase()) { | ||
"internal" -> INTERNAL | ||
else -> PUBLIC | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Consider overriding |
||
|
||
/** | ||
* Contains API settings for a Kotlin project | ||
* @param visibility Enum representing the visibility of code-generated classes, objects, interfaces, etc. | ||
*/ | ||
data class ApiSettings( | ||
val visibility: Visibility = Visibility.PUBLIC, | ||
) { | ||
companion object { | ||
const val VISIBILITY = "visibility" | ||
|
||
fun fromNode(node: Optional<ObjectNode>): ApiSettings = node.map { | ||
val visibility = Visibility.fromValue(node.get().getStringMemberOrDefault(VISIBILITY, "public")) | ||
ApiSettings(visibility) | ||
}.orElse(Default) | ||
|
||
/** | ||
* Default build settings | ||
*/ | ||
val Default: ApiSettings = ApiSettings() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Correctness: This means silently ignoring the caller's intent when we don't understand it, leading to typos like
"itnernal"
being treated asPUBLIC
. I think we should throw an exception if we don't understand the input value.