Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/contributor-license-agreement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ permissions:

jobs:
claAssistant:
if: false # disabled until a CLA exists
runs-on: ubuntu-latest
steps:
- name: "CLA Assistant"
Expand Down
29 changes: 0 additions & 29 deletions CHANGELOG.md

This file was deleted.

1 change: 0 additions & 1 deletion CLA.md

This file was deleted.

24 changes: 4 additions & 20 deletions CODING_GUIDELINES.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# Coding Guidelines

- You can validate that your code complies with these guidelines by running `stuff/php-format.py validate`
- Tabs, no spaces
- End of line should should be Unix style (`\n`), not Windows style (`\r\n`)
- Opening brackets goes in the same line as the last statement
```
if (condition) {
stuff;
}
```
- A space between keywords and parenthesis for: `if`, `else`, `while`, `switch`, `catch`, `function`
- Function calls have no space before the parentheses
- No spaces are left inside the parentheses
- A space after each comma, but without space before
- All binary operators must have one space before and one after
- There should not be more than one contiguous blank line
- There should be no empty comments
- You should not use block comments `/ * ... * /`, only line `// ...`
- Changes in functionality must be accompanied by their respective new / modified tests
- Exceptions must be used to report erroneous states. The use of functions that return true / false is allowed when they are expected values
- Use [RAII] (http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization) when appropriate, mainly in the administration of resources (files, etc ...)
- A CI action validate the code using KtLint
- On local development you can check using `./gradlew ktlintCheck`
- On local development you can reformat using `./gradlew ktlintFormat`
- Further rules can be found in `.editorconfig`
38 changes: 7 additions & 31 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,12 @@

- Contributing to KEBAB-KRAFTER is fairly easy. This document shows you how to get started.

## General
- The [documentation guide](https://docs) is the ideal beginner to explore the project and to get started.

## Submitting changes

- Fork this repo
- <https://github.com/diconium/mcc-network-generator/fork>
- Check out a new branch base and name it to what you intend to do:
- Example:
````
$ git checkout -b BRANCH_NAME
````
If you get an error, you may need to fetch fooBar first by using
````
$ git remote update && git fetch
````
- Use one branch per fix / feature
- Commit your changes
- Please provide a git message that explains what you've done
- Please make sure your commits follow the [conventions](https://github.com/diconium/mcc-network-generator/CONTRIBUTING.md#commit-messages)
- Commit to the forked repository
- Example:
````
$ git commit -am 'Add some fooBar'
````
- Push to the branch
- Example:
````
$ git push origin BRANCH_NAME
````
- Make a pull request
- Make sure you send the PR to the <code>fooBar</code> branch

- Fork this repo https://github.com/diconium/kebab-krafter
- Check out a new branch from your fork and give it a meaningful name:
- Use one branch per fix / feature
- Commit your changes to the forked repository. Please provide a meaningful commit message
- Push your branch to your fork
- Open a pull request
- If you want to contribute, but unsure if the idea of new feature or fix is the righ direction, feel free to open an issue https://github.com/diconium/kebab-krafter/issues so we can have a chat about it.
1 change: 0 additions & 1 deletion LICENSE_GUIDELINES.md

This file was deleted.

124 changes: 39 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,6 @@ Available for:
<br> - Swift client (hopefully)
</p>

[//]: # (Alternative logos)
[//]: # (<p align="center">)

[//]: # ( <a href="docs/kebab-krafter-0.png" rel="noopener">)

[//]: # ( <img width=200px height=200px src="docs/kebab-krafter-0.png" alt="Project logo"></a>)

[//]: # (</p>)
[//]: # (<p align="center">)

[//]: # ( <a href="docs/kebab-krafter-1.png" rel="noopener">)

[//]: # ( <img width=200px height=200px src="docs/kebab-krafter-1.png" alt="Project logo"></a>)

[//]: # (</p>)

[//]: # ()
[//]: # (<p align="center">)

[//]: # ( <a href="docs/kebab-krafter-2.png" rel="noopener">)

[//]: # ( <img width=200px height=200px src="docs/kebab-krafter-2.png" alt="Project logo"></a>)

[//]: # (</p>)

[//]: # ()
[//]: # (<p align="center">)

[//]: # ( <a href="docs/kebab-krater-11.png" rel="noopener">)

[//]: # ( <img width=200px height=200px src="docs/kebab-krater-11.png" alt="Project logo"></a>)

[//]: # (</p>)

[//]: # ()
[//]: # (<p align="center">)

[//]: # ( <a href="docs/kebab-krafter-22.png" rel="noopener">)

[//]: # ( <img width=200px height=200px src="docs/kebab-krafter-22.png" alt="Project logo"></a>)

[//]: # (</p>)

---

## 📝 Table of Contents
Expand All @@ -72,16 +29,16 @@ Available for:
- [Authors](#authors)
- [Acknowledgments](#acknowledgement)

## 🧐 About <a name = "about"></a>
## About

A gradle plugin to auto-generate network interfaces from a set of swagger API documentation.
Kebab-Krafter is a gradle plugin to auto-generate network interfaces from a set of swagger API documentation.

## 🏁 Getting Started <a name = "getting_started"></a>
## Getting Started <a name = "getting_started"></a>

To start using the plugin just add to your `build.gradle.kts` file:

```kotlin
id("com.diconium.mobile.tools.kebab-krafter") version "version"
id("com.diconium.mobile.tools.kebab-krafter") version "latest_version"
```

### Generate Ktor Server
Expand All @@ -107,67 +64,64 @@ ktorServer {
}
```

From the example above the a `InstallRoutes.kt` is generated in the `root.package.name.for.the.generated.code` with an extension function for Ktor `fun Route.installGeneratedRoutes(locator: ServiceLocator)`

It also generates all the necessary `data class` models and controller `interfaces` that satisfy the API in a nicely unit testable way.

The `contextSpec` is a joker card to extract any metadata needed from the `Ktor.ApplicationCall` before passing to the controller. In the sample app you can see it extracting the `accept-language` header into `Locale` object. Making the context an interface is advisable, so that it's trivial to unit test the controller by creating a `FakeContext()`
and with that you can execute `./gradlew generateKtorServer` to auto-genearted a `Route.installGeneratedRoutes`, all the `data classes` using `kotlinx-serialization` and the interfaces for each endpoint in the following format:

The `ServiceLocator` is a very simple `get<T>` interface that can be adapted to any dependency injection you want to use. For example using Koin it would be something like:

```kotlin
class KoinServiceLocator(private val koin: Koin) : ServiceLocator {
override fun <T : Any> getService(type: KClass<T>): T = koin.get(type)
```Kotlin
public interface GetPathName {
public fun CallScope.execute(pathParameters, queryParameters, body) : ResponseBody
}
```

### Implement the Server
From that you just have to implement the interfaces!

With that generated code in place, all you gotta do is implement the interfaces and install the routes on the Ktor instance.
#### The contextSpec

Check the `sample/` app with the "Pet Store" for a full example.
The `contextSpec` is a "joker-card" to extract any metadata needed from the `Ktor.ApplicationCall` before passing to the controller. In the sample app you can see it extracting the `accept-language` header into a `Locale` object.

## 🔧 Running the tests <a name = "tests"></a>
In the snippet above the context was named `CallScope` in the package `com.myserver.api`, a simple example for it would be:

Explain how to run the automated tests for this system.
```Kotlin
interface CallScope {
val locale: Locale // define meta-data your controller needs from the request

### Break down into end to end tests
companion object {

Explain what these tests test and why

```
Give an example
// define a factory function to create the object
fun from(call: ApplicationCall): CallScope = CallScopeImpl(call)
}
}
```

### And coding style tests
Making this context an interface is advisable, so that it's trivial to unit test the controller by creating a `FakeContext()`

Explain what these tests test and why

```
Give an example
```Kotlin
// implement the real object separetely, to make it trivial to implement unit tests.
private class CallScopeImpl(private val call: ApplicationCall) : CallScope {
override val locale: Locale by lazy {
call.request.acceptLanguage().toLocale()
}
}
```

## 🎈 Usage <a name="usage"></a>
#### The ServiceLocator

Add notes about how to use the system.
The generated `installGeneratedRoutes` receives a object of type `ServiceLocator` located in the same package of the `installGeneratedRoutes`.

## Documentation
The `ServiceLocator` is a very simple `get<T>` interface that can be adapted to any dependency injection you want to use. For example using Koin it would be something like:

Please see [documentation guide](https://docs)
```kotlin
class KoinServiceLocator(private val koin: Koin) : ServiceLocator {
override fun <T : Any> getService(type: KClass<T>): T = koin.get(type)
}
```

## 🚀 Deployment <a name = "deployment"></a>
### Further Examples

Add additional notes about how to deploy this on a live system.
Check the `sample/` app with the "Pet Store" for a full example.

## ✍️ Authors <a name = "authors"></a>
## Authors <a name = "authors"></a>

- [@rvp-diconium](https://github.com/rvp-diconium)

See also the list of [contributors](https://github.com/diconium/mcc-network-generator/contributors) who participated in
this project.

## 🎉 Acknowledgements <a name = "acknowledgement"></a>

- Hat tip to anyone whose code was used
- Inspiration
- References
1 change: 0 additions & 1 deletion SECURITY.md

This file was deleted.

7 changes: 6 additions & 1 deletion sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.diconium.mobile.tools.kebabkrafter.generator.KtorMapper
import com.diconium.mobile.tools.kebabkrafter.generator.KtorTransformer
import com.diconium.mobile.tools.kebabkrafter.models.BaseSpecModel
import com.diconium.mobile.tools.kebabkrafter.models.Endpoint
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

private val ktorVersion: String = "2.3.12"
private val kotlinVersion: String = "1.9.24"
Expand Down Expand Up @@ -51,7 +52,11 @@ tasks.test {
}

kotlin {
jvmToolchain(17)
jvmToolchain(21)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
optIn.add("com.diconium.mobile.tools.kebabkrafter.KebabKrafterUnstableApi")
}
}

ktlint {
Expand Down
Loading