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

Add smithy-docgen to the repository #2488

Merged
merged 8 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.configureondmand=true
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
org.gradle.parallel=true
smithyGradleVersion=1.1.0
8 changes: 2 additions & 6 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ pluginManagement {
mavenCentral()
gradlePluginPortal()
}

plugins {
val smithyGradleVersion : String by settings
id("software.amazon.smithy.gradle.smithy-jar") version smithyGradleVersion
}
}

rootProject.name = "smithy"
Expand Down Expand Up @@ -42,4 +37,5 @@ include(":smithy-aws-endpoints")
include(":smithy-aws-smoke-test-model")
include(":smithy-protocol-traits")
include(":smithy-protocol-tests")
include(":smithy-trait-codegen")
include(":smithy-trait-codegen")
include(":smithy-docgen")
28 changes: 28 additions & 0 deletions smithy-docgen/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
plugins {
haydenbaker marked this conversation as resolved.
Show resolved Hide resolved
id("smithy.module-conventions")
id("smithy.integ-test-conventions")
}

description = "This module contains support for generating API documentation based on Smithy models."

extra["displayName"] = "Smithy :: DocGen"
extra["moduleName"] = "software.amazon.smithy.docgen"

dependencies {
implementation(project(":smithy-build"))
implementation(project(":smithy-codegen-core"))
implementation(project(":smithy-linters"))
implementation(project(":smithy-model"))
haydenbaker marked this conversation as resolved.
Show resolved Hide resolved
implementation(project(":smithy-utils"))

itImplementation(project(":smithy-aws-traits"))
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.docgen;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
import java.util.Set;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.build.MockManifest;
import software.amazon.smithy.build.PluginContext;
import software.amazon.smithy.build.SmithyBuildPlugin;
import software.amazon.smithy.docgen.core.SmithyDocPlugin;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;

public class PluginTest {

private static MockManifest manifest;
private static Model model;
private static SmithyBuildPlugin plugin;

@BeforeAll
public static void setup() {
manifest = new MockManifest();
model = getModel("main.smithy");
plugin = new SmithyDocPlugin();
}

@Test
public void pluginGeneratesMarkdown() {
ObjectNode settings = Node.objectNodeBuilder()
.withMember("service", "com.example#DocumentedService")
.withMember("format", "markdown")
.withMember(
"references",
Node.objectNodeBuilder()
.withMember("com.example#ExternalResource", "https://aws.amazon.com")
.build())
.build();
PluginContext context = getPluginContext(model, settings);

plugin.execute(context);

assertFalse(manifest.getFiles().isEmpty());
Set<Path> files = manifest.getFiles();
assertTrue(files.contains(Path.of("/content", "index.md")));
}

@Test
public void pluginGeneratesSphinxMarkdown() {
Model model = getModel("main.smithy");
ObjectNode settings = Node.objectNodeBuilder()
.withMember("service", "com.example#DocumentedService")
.withMember("format", "sphinx-markdown")
.withMember(
"references",
Node.objectNodeBuilder()
.withMember("com.example#ExternalResource", "https://aws.amazon.com")
.build())
.build();
PluginContext context = getPluginContext(model, settings);

plugin.execute(context);

assertFalse(manifest.getFiles().isEmpty());
Set<Path> files = manifest.getFiles();
assertTrue(files.contains(Path.of("/requirements.txt")));
assertTrue(files.contains(Path.of("/content", "conf.py")));
assertTrue(files.contains(Path.of("/content", "index.md")));
}

private static Model getModel(String path) {
return Model.assembler()
.addImport(PluginTest.class.getResource(path))
.discoverModels(PluginTest.class.getClassLoader())
.assemble()
.unwrap();
}

private static PluginContext getPluginContext(Model model, ObjectNode settings) {
return PluginContext.builder()
.fileManifest(manifest)
.model(model)
.settings(settings)
.build();
}
}
Loading
Loading