Skip to content

Commit

Permalink
feat(java): Allow overrides of package prefixes (#5374)
Browse files Browse the repository at this point in the history
* feat(java): Allow overrides of package prefixes

* Make package prefix abstract in ICustomConfig

* Begin adding test

* add test config

* Add test output

* update test

* update all test

* Add changelog entry

* chore: update changelog

* update ete tests

* Reset snapshot to match main

---------

Co-authored-by: Alberto <alberto@buildwithfern.com>
Co-authored-by: ajgateno <ajgateno@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 7d877b6 commit 04d1b5c
Show file tree
Hide file tree
Showing 51 changed files with 2,639 additions and 12 deletions.
5 changes: 5 additions & 0 deletions fern/pages/changelogs/java-sdk/2024-12-10.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 2.4.0
**`(feat):`** We now support overriding sdk package prefixes by adding a "package-prefix" key under the java-sdk generator
configuration.


Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Optional;
import org.immutables.value.Value;

public interface ICustomConfig {
Expand Down Expand Up @@ -58,6 +59,9 @@ default Boolean disableRequiredPropertyBuilderChecks() {
return false;
}

@JsonProperty("package-prefix")
Optional<String> packagePrefix();

enum JsonInclude {
NON_EMPTY("non-empty"),
NON_ABSENT("non-absent");
Expand Down
16 changes: 12 additions & 4 deletions generators/java/sdk/src/main/java/com/fern/java/client/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ public void runInGithubModeHook(
IntermediateRepresentation ir,
JavaSdkCustomConfig customConfig,
GithubOutputMode githubOutputMode) {
ClientPoetClassNameFactory clientPoetClassNameFactory = new ClientPoetClassNameFactory(
AbstractPoetClassNameFactory.getPackagePrefixWithOrgAndApiName(ir, generatorConfig.getOrganization()));
List<String> packagePrefixTokens = customConfig
.packagePrefix()
.map(List::of)
.orElseGet(() -> AbstractPoetClassNameFactory.getPackagePrefixWithOrgAndApiName(
ir, generatorConfig.getOrganization()));
ClientPoetClassNameFactory clientPoetClassNameFactory = new ClientPoetClassNameFactory(packagePrefixTokens);
List<AuthScheme> resolvedAuthSchemes =
new FeatureResolver(ir, generatorConfig, generatorExecClient).getResolvedAuthSchemes();
ClientGeneratorContext context = new ClientGeneratorContext(
Expand Down Expand Up @@ -152,8 +156,12 @@ public void runInPublishModeHook(
IntermediateRepresentation ir,
JavaSdkCustomConfig customConfig,
GeneratorPublishConfig publishOutputMode) {
ClientPoetClassNameFactory clientPoetClassNameFactory = new ClientPoetClassNameFactory(
AbstractPoetClassNameFactory.getPackagePrefixWithOrgAndApiName(ir, generatorConfig.getOrganization()));
List<String> packagePrefixTokens = customConfig
.packagePrefix()
.map(List::of)
.orElseGet(() -> AbstractPoetClassNameFactory.getPackagePrefixWithOrgAndApiName(
ir, generatorConfig.getOrganization()));
ClientPoetClassNameFactory clientPoetClassNameFactory = new ClientPoetClassNameFactory(packagePrefixTokens);
List<AuthScheme> resolvedAuthSchemes =
new FeatureResolver(ir, generatorConfig, generatorExecClient).getResolvedAuthSchemes();
ClientGeneratorContext context = new ClientGeneratorContext(
Expand Down
9 changes: 9 additions & 0 deletions generators/java/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
- changelogEntry:
- summary: |
We now support overriding sdk package prefixes by adding a "package-prefix" key under the java-sdk generator
configuration.
type: feat
createdAt: '2024-12-10'
irVersion: 46
version: 2.4.0

- changelogEntry:
- summary: |
The rootProject.name is now set in settings.gradle and ci.yml uses ./gradlew sonatypeCentralUpload for publishing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ exports[`fern api update unioned > fern api update unioned 1`] = `
},
"servers": [
{
"url": "https://api.example.com",
"description": "Production",
"url": "https://try.microcks.io/rest/Train+Travel+API/1.0.0",
"description": "Mock Server",
"x-internal": false
},
{
"url": "https://try.microcks.io/rest/Train+Travel+API/1.0.0",
"description": "Mock Server",
"url": "https://api.example.com",
"description": "Production",
"x-internal": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ exports[`fern api update > fern api update 1`] = `
},
"servers": [
{
"url": "https://api.example.com",
"description": "Production",
"url": "https://try.microcks.io/rest/Train+Travel+API/1.0.0",
"description": "Mock Server",
"x-internal": false
},
{
"url": "https://try.microcks.io/rest/Train+Travel+API/1.0.0",
"description": "Mock Server",
"url": "https://api.example.com",
"description": "Production",
"x-internal": false
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "object",
"properties": {
"title": {
"type": "string"
},
"rating": {
"type": "number"
}
},
"required": [
"title",
"rating"
],
"additionalProperties": false,
"definitions": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "object",
"properties": {
"id": {
"$ref": "#/definitions/imdb.MovieId"
},
"title": {
"type": "string"
},
"rating": {
"type": "number"
}
},
"required": [
"id",
"title",
"rating"
],
"additionalProperties": false,
"definitions": {
"imdb.MovieId": {
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "string",
"definitions": {}
}
Loading

0 comments on commit 04d1b5c

Please sign in to comment.