This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial Kotlin support * Simplify sentence
- Loading branch information
Showing
19 changed files
with
1,059 additions
and
2 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# IntelliJ | ||
.idea/ | ||
*.iml | ||
|
||
# Genertaed files | ||
target/ |
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,42 @@ | ||
# KDoc and Javadoc to JSON converter for Spring Auto REST Docs | ||
|
||
This library is a [Dokka](https://github.com/Kotlin/dokka) extension. | ||
Dokka is a documentation engine for Kotlin, performing the same function as Javadoc for Java. | ||
Mixed-language Java/Kotlin projects are fully supported. | ||
Dokka understands standard Javadoc comments in Java files and KDoc comments in Kotlin files. | ||
The same holds true for this Dokka extension. | ||
|
||
## Usage with Maven | ||
|
||
This Dokka extension can be used with the standard `dokka-maven-plugin`. | ||
To avoid any incompatibilities, the Dokka version of the `dokka-maven-plugin` and of this extension should be the same. | ||
If this extension is included as a dependency of the plugin, the output format `auto-restdocs-json` can be used. | ||
|
||
Example usage: | ||
``` | ||
<plugin> | ||
<groupId>org.jetbrains.dokka</groupId> | ||
<artifactId>dokka-maven-plugin</artifactId> | ||
<version>${dokka.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>dokka</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>capital.scalable</groupId> | ||
<artifactId>spring-auto-restdocs-dokka-json</artifactId> | ||
<version>${spring-auto-restdocs-dokka-json.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<configuration> | ||
<outputFormat>auto-restdocs-json</outputFormat> | ||
<outputDir>${jsonDirectory}</outputDir> | ||
</configuration> | ||
</plugin> | ||
``` | ||
|
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,96 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>capital.scalable</groupId> | ||
<artifactId>spring-auto-restdocs-parent</artifactId> | ||
<version>1.0.12-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<artifactId>spring-auto-restdocs-dokka-json</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Spring Auto REST Docs Dokka JSON</name> | ||
<description>Dokka extension that produces Spring Auto REST Docs' JSON format</description> | ||
<url>https://github.com/scacap/spring-auto-restdocs</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<kotlin.version>1.2.30</kotlin.version> | ||
<junit.version>4.12</junit.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-test-junit</artifactId> | ||
<version>${kotlin.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.dokka</groupId> | ||
<artifactId>dokka-fatjar</artifactId> | ||
<version>0.9.16</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<version>2.9.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.module</groupId> | ||
<artifactId>jackson-module-kotlin</artifactId> | ||
<version>2.9.4.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jcenter</id> | ||
<url>https://jcenter.bintray.com/</url> | ||
</repository> | ||
</repositories> | ||
|
||
</project> |
85 changes: 85 additions & 0 deletions
85
...auto-restdocs-dokka-json/src/main/kotlin/capital/scalable/dokka/json/JsonFileGenerator.kt
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,85 @@ | ||
/*- | ||
* #%L | ||
* Spring Auto REST Docs Dokka JSON | ||
* %% | ||
* Copyright (C) 2015 - 2018 Scalable Capital GmbH | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package capital.scalable.dokka.json | ||
|
||
import com.google.inject.Inject | ||
import org.jetbrains.dokka.* | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.IOException | ||
import java.io.OutputStreamWriter | ||
|
||
class JsonFileGenerator @Inject constructor(val locationService: FileLocationService) : Generator { | ||
|
||
@set:Inject(optional = true) | ||
lateinit var formatService: FormatService | ||
|
||
override fun buildPages(nodes: Iterable<DocumentationNode>) { | ||
val specificLocationService = locationService.withExtension(formatService.extension) | ||
|
||
for ((_, items) in nodes.groupBy { specificLocationService.location(it) }) { | ||
if (items.any { it.kind == NodeKind.Class }) { | ||
val location = locationOverride(items.find { it.kind == NodeKind.Class }!!) | ||
val file = location.file | ||
file.parentFile?.mkdirsOrFail() | ||
try { | ||
FileOutputStream(file).use { | ||
OutputStreamWriter(it, Charsets.UTF_8).use { | ||
it.write(formatService.format(location, items)) | ||
} | ||
} | ||
} catch (e: Throwable) { | ||
println(e) | ||
} | ||
} | ||
buildPages(items.flatMap { it.members }) | ||
} | ||
} | ||
|
||
private fun locationOverride(node: DocumentationNode): FileLocation { | ||
val path = node.path | ||
// Remove class name. It is appended again below. | ||
.dropLast(1) | ||
.filter { it.name.isNotEmpty() && it.kind != NodeKind.Module } | ||
.joinToString("") { | ||
if (it.kind == NodeKind.Class) { | ||
// Parent class if the node is a nested class | ||
"${it.name}." | ||
} else { | ||
// Turn package dots into folders | ||
"${it.name.replace(".", "/")}/" | ||
} | ||
} | ||
val className = node.name | ||
return FileLocation(File(locationService.root.path, "$path$className.json")) | ||
} | ||
|
||
override fun buildOutlines(nodes: Iterable<DocumentationNode>) {} | ||
|
||
override fun buildSupportFiles() {} | ||
|
||
override fun buildPackageList(nodes: Iterable<DocumentationNode>) {} | ||
|
||
private fun File.mkdirsOrFail() { | ||
if (!mkdirs() && !exists()) { | ||
throw IOException("Failed to create directory $this") | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...o-restdocs-dokka-json/src/main/kotlin/capital/scalable/dokka/json/JsonFormatDescriptor.kt
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,40 @@ | ||
/*- | ||
* #%L | ||
* Spring Auto REST Docs Dokka JSON | ||
* %% | ||
* Copyright (C) 2015 - 2018 Scalable Capital GmbH | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package capital.scalable.dokka.json | ||
|
||
import org.jetbrains.dokka.* | ||
import org.jetbrains.dokka.Formats.FormatDescriptor | ||
import org.jetbrains.dokka.Kotlin.KotlinDescriptorSignatureProvider | ||
import org.jetbrains.dokka.Samples.DefaultSampleProcessingService | ||
import org.jetbrains.dokka.Samples.SampleProcessingService | ||
import kotlin.reflect.KClass | ||
|
||
class JsonFormatDescriptor : FormatDescriptor { | ||
override val formatServiceClass = JsonFormatService::class | ||
|
||
override val packageDocumentationBuilderClass = KotlinPackageDocumentationBuilder::class | ||
override val javaDocumentationBuilderClass = KotlinJavaDocumentationBuilder::class | ||
|
||
override val generatorServiceClass = JsonFileGenerator::class | ||
override val outlineServiceClass: KClass<out OutlineFormatService>? = null | ||
override val sampleProcessingService: KClass<out SampleProcessingService> = DefaultSampleProcessingService::class | ||
override val packageListServiceClass: KClass<out PackageListService>? = DefaultPackageListService::class | ||
override val descriptorSignatureProvider = KotlinDescriptorSignatureProvider::class | ||
} |
Oops, something went wrong.