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-typescript examples #66

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 9 additions & 0 deletions smithy-codegen/typescript-client-codegen-gradle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Smithy TypeScript Client Codegen
Smithy TypeScript Client Codegen example built using gradle

## Building
To build this project run:
```console
./gradlew clean build
```
From the root of this template directory.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.8.0")
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
val smithyVersion: String by project

smithyCli("software.amazon.smithy:smithy-cli:$smithyVersion")

implementation(project(":example-client-integrations"))
implementation("software.amazon.smithy.typescript:smithy-typescript-codegen:0.19.0")

// Uncomment below to add various smithy dependencies (see full list of smithy dependencies in https://github.com/awslabs/smithy)
// implementation("software.amazon.smithy:smithy-model:$smithyVersion")
// implementation("software.amazon.smithy:smithy-linters:$smithyVersion")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("java-library")
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy.typescript:smithy-typescript-codegen:0.19.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package typescript.example.client.gradle;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention;

public class ExampleClientEndpointResolutionIntegration implements TypeScriptIntegration {
@Override
public List<RuntimeClientPlugin> getClientPlugins() {
return List.of(
RuntimeClientPlugin.builder()
.withConventions(
TypeScriptDependency.CONFIG_RESOLVER.dependency,
"CustomEndpoints",
Convention.HAS_CONFIG)
.build());
}

@Override
public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
LanguageTarget target
) {
// Runtime config value also be specified per platform by using the `target`
// argument, e.g.
// if (target.equals(LanguageTarget.NODE)) { ... }
if (target.equals(LanguageTarget.SHARED)) {
// This example provides an arbitrary endpoint on the shared runtime config
return Map.of("endpoint", w -> w.write("$S", "https://www.example.com"));
}
// No need to redefine endpoint for other targets since it's inherited from the
// shared target
return Collections.emptyMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package typescript.example.client.gradle;

import java.util.List;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.typescript.codegen.ApplicationProtocol;
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator;
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;

public class ExampleClientProtocolGeneratorIntegration implements TypeScriptIntegration {
// ProtocolGenerator implementation is inline for brevity, but should be in its
// own file
private static class ExampleClientProtocolGenerator implements ProtocolGenerator {
// Protocol generator for a @example.client#protocol protocol trait
@Override
public ShapeId getProtocol() {
return ShapeId.from("example.client#protocol");
}
// Implement ProtocolGenerator methods ...

@Override
public ApplicationProtocol getApplicationProtocol() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getApplicationProtocol'");
}

@Override
public void generateRequestSerializers(GenerationContext context) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateRequestSerializers'");
}

@Override
public void generateRequestDeserializers(GenerationContext context) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateRequestDeserializers'");
}

@Override
public void generateResponseSerializers(GenerationContext context) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateResponseSerializers'");
}

@Override
public void generateFrameworkErrorSerializer(GenerationContext serverContext) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateFrameworkErrorSerializer'");
}

@Override
public void generateServiceHandlerFactory(GenerationContext context) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateServiceHandlerFactory'");
}

@Override
public void generateOperationHandlerFactory(GenerationContext context, OperationShape operation) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateOperationHandlerFactory'");
}

@Override
public void generateResponseDeserializers(GenerationContext context) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateResponseDeserializers'");
}

@Override
public void generateProtocolTests(GenerationContext context) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'generateProtocolTests'");
}
}

@Override
public List<ProtocolGenerator> getProtocolGenerators() {
return List.of(new ExampleClientProtocolGenerator());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
typescript.example.client.gradle.ExampleClientProtocolGeneratorIntegration
typescript.example.client.gradle.ExampleClientEndpointResolutionIntegration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smithyVersion=1.40.0
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading