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

🌿 Fern Regeneration -- January 3, 2025 #11

Merged
merged 1 commit into from
Jan 3, 2025
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
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ jobs:

- name: Publish to maven
run: |
./.publish/prepare.sh
./gradlew publish
./gradlew sonatypeCentralUpload
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
Expand Down
71 changes: 59 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'maven-publish'
id 'com.diffplug.spotless' version '6.11.0'
id 'signing'
id 'cl.franciscosolis.sonatype-central-upload' version '1.0.3'
}

repositories {
Expand All @@ -14,9 +15,9 @@ repositories {

dependencies {
api 'com.squareup.okhttp3:okhttp:4.12.0'
api 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.3'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.3'
api 'com.fasterxml.jackson.core:jackson-databind:2.17.2'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.17.2'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2'
testImplementation 'org.mockito:mockito-core:5.3.1'
testImplementation 'org.mockito:mockito-junit-jupiter:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
Expand All @@ -27,26 +28,52 @@ dependencies {
sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(Javadoc) {
failOnError false
options.addStringOption('Xdoclint:none', '-quiet')
}

spotless {
java {
palantirJavaFormat()
}
}


java {
withSourcesJar()
withJavadocJar()
}


group = 'schematichq'

version = '1.1.0'

jar {
dependsOn(":generatePomFileForMavenPublication")
archiveBaseName = "schematichq-java"
}

sourcesJar {
archiveBaseName = "schematichq-java"
}

javadocJar {
archiveBaseName = "schematichq-java"
}

signing {
sign(publishing.publications)
}

test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
}
}

publishing {
publications {
maven(MavenPublication) {
Expand All @@ -58,6 +85,12 @@ publishing {
name = 'schematic'
description = 'The official SDK of schematic'
url = 'https://buildwithfern.com'
licenses {
license {
name = 'The MIT License (MIT)'
url = 'https://mit-license.org/'
}
}
developers {
developer {
name = 'schematic'
Expand All @@ -72,14 +105,28 @@ publishing {
}
}
}
repositories {
maven {
url "$System.env.MAVEN_PUBLISH_REGISTRY_URL"
credentials {
username "$System.env.MAVEN_USERNAME"
password "$System.env.MAVEN_PASSWORD"
}
}
}
}

sonatypeCentralUpload {
username = "$System.env.MAVEN_USERNAME"
password = "$System.env.MAVEN_PASSWORD"

archives = files(
"$buildDir/libs/schematichq-java-" + version + ".jar",
"$buildDir/libs/schematichq-java-" + version + "-sources.jar",
"$buildDir/libs/schematichq-java-" + version + "-javadoc.jar"
)

pom = file("$buildDir/publications/maven/pom-default.xml")
signingKey = "$System.env.MAVEN_SIGNATURE_SECRET_KEY"
signingKeyPassphrase = "$System.env.MAVEN_SIGNATURE_PASSWORD"
}

signing {
def signingKeyId = "$System.env.MAVEN_SIGNATURE_SECRET_KEY"
def signingPassword = "$System.env.MAVEN_SIGNATURE_PASSWORD"
useInMemoryPgpKeys(signingKeyId, signingPassword)
sign publishing.publications.maven
}

sonatypeCentralUpload.dependsOn build
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 1 addition & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
rootProject.name = 'schematichq-java'

include 'sample-app'
8 changes: 8 additions & 0 deletions src/main/java/com/schematic/api/BaseSchematicBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public BaseSchematicBuilder url(String url) {
return this;
}

/**
* Sets the timeout (in seconds) for the client
*/
public BaseSchematicBuilder timeout(int timeout) {
this.clientOptionsBuilder.timeout(timeout);
return this;
}

public BaseSchematic build() {
if (apiKey == null) {
throw new RuntimeException("Please provide apiKey");
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/schematic/api/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ public final class ClientOptions {

private final OkHttpClient httpClient;

private final int timeout;

private ClientOptions(
Environment environment,
Map<String, String> headers,
Map<String, Supplier<String>> headerSuppliers,
OkHttpClient httpClient) {
OkHttpClient httpClient,
int timeout) {
this.environment = environment;
this.headers = new HashMap<>();
this.headers.putAll(headers);
Expand All @@ -35,6 +38,7 @@ private ClientOptions(
});
this.headerSuppliers = headerSuppliers;
this.httpClient = httpClient;
this.timeout = timeout;
}

public Environment environment() {
Expand Down Expand Up @@ -80,6 +84,8 @@ public static final class Builder {

private final Map<String, Supplier<String>> headerSuppliers = new HashMap<>();

private int timeout = 60;

public Builder environment(Environment environment) {
this.environment = environment;
return this;
Expand All @@ -95,11 +101,20 @@ public Builder addHeader(String key, Supplier<String> value) {
return this;
}

/**
* Override the timeout in seconds. Defaults to 60 seconds.
*/
public Builder timeout(int timeout) {
this.timeout = timeout;
return this;
}

public ClientOptions build() {
OkHttpClient okhttpClient = new OkHttpClient.Builder()
.addInterceptor(new RetryInterceptor(3))
.callTimeout(this.timeout, TimeUnit.SECONDS)
.build();
return new ClientOptions(environment, headers, headerSuppliers, okhttpClient);
return new ClientOptions(environment, headers, headerSuppliers, okhttpClient, this.timeout);
}
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/schematic/api/core/FileStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.schematic.api.core;

import java.io.InputStream;
import java.util.Objects;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import org.jetbrains.annotations.Nullable;

/**
* Represents a file stream with associated metadata for file uploads.
*/
public class FileStream {
private final InputStream inputStream;
private final String fileName;
private final MediaType contentType;

/**
* Constructs a FileStream with the given input stream and optional metadata.
*
* @param inputStream The input stream of the file content. Must not be null.
* @param fileName The name of the file, or null if unknown.
* @param contentType The MIME type of the file content, or null if unknown.
* @throws NullPointerException if inputStream is null
*/
public FileStream(InputStream inputStream, @Nullable String fileName, @Nullable MediaType contentType) {
this.inputStream = Objects.requireNonNull(inputStream, "Input stream cannot be null");
this.fileName = fileName;
this.contentType = contentType;
}

public FileStream(InputStream inputStream) {
this(inputStream, null, null);
}

public InputStream getInputStream() {
return inputStream;
}

@Nullable
public String getFileName() {
return fileName;
}

@Nullable
public MediaType getContentType() {
return contentType;
}

/**
* Creates a RequestBody suitable for use with OkHttp client.
*
* @return A RequestBody instance representing this file stream.
*/
public RequestBody toRequestBody() {
return new InputStreamRequestBody(contentType, inputStream);
}
}
79 changes: 79 additions & 0 deletions src/main/java/com/schematic/api/core/InputStreamRequestBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.schematic.api.core;

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.internal.Util;
import okio.BufferedSink;
import okio.Okio;
import okio.Source;
import org.jetbrains.annotations.Nullable;

/**
* A custom implementation of OkHttp's RequestBody that wraps an InputStream.
* This class allows streaming of data from an InputStream directly to an HTTP request body,
* which is useful for file uploads or sending large amounts of data without loading it all into memory.
*/
public class InputStreamRequestBody extends RequestBody {
private final InputStream inputStream;
private final MediaType contentType;

/**
* Constructs an InputStreamRequestBody with the specified content type and input stream.
*
* @param contentType the MediaType of the content, or null if not known
* @param inputStream the InputStream containing the data to be sent
* @throws NullPointerException if inputStream is null
*/
public InputStreamRequestBody(@Nullable MediaType contentType, InputStream inputStream) {
this.contentType = contentType;
this.inputStream = Objects.requireNonNull(inputStream, "inputStream == null");
}

/**
* Returns the content type of this request body.
*
* @return the MediaType of the content, or null if not specified
*/
@Nullable
@Override
public MediaType contentType() {
return contentType;
}

/**
* Returns the content length of this request body, if known.
* This method attempts to determine the length using the InputStream's available() method,
* which may not always accurately reflect the total length of the stream.
*
* @return the content length, or -1 if the length is unknown
* @throws IOException if an I/O error occurs
*/
@Override
public long contentLength() throws IOException {
return inputStream.available() == 0 ? -1 : inputStream.available();
}

/**
* Writes the content of the InputStream to the given BufferedSink.
* This method is responsible for transferring the data from the InputStream to the network request.
*
* @param sink the BufferedSink to write the content to
* @throws IOException if an I/O error occurs during writing
*/
@Override
public void writeTo(BufferedSink sink) throws IOException {
Source source = null;
try {
source = Okio.source(inputStream);
sink.writeAll(source);
} finally {
Util.closeQuietly(Objects.requireNonNull(source));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;

@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonDeserialize(builder = IssueTemporaryAccessTokenRequestBody.Builder.class)
Expand Down Expand Up @@ -74,7 +75,7 @@ public static ResourceTypeStage builder() {
}

public interface ResourceTypeStage {
_FinalStage resourceType(String resourceType);
_FinalStage resourceType(@NotNull String resourceType);

Builder from(IssueTemporaryAccessTokenRequestBody other);
}
Expand Down Expand Up @@ -109,8 +110,8 @@ public Builder from(IssueTemporaryAccessTokenRequestBody other) {

@java.lang.Override
@JsonSetter("resource_type")
public _FinalStage resourceType(String resourceType) {
this.resourceType = resourceType;
public _FinalStage resourceType(@NotNull String resourceType) {
this.resourceType = Objects.requireNonNull(resourceType, "resourceType must not be null");
return this;
}

Expand Down
Loading
Loading