Skip to content

Commit 719c8d1

Browse files
authored
chore: Improve Generator Script (#381)
* add missing generator param * add setup script * Update Generator Config
1 parent 669d610 commit 719c8d1

File tree

7 files changed

+29
-234
lines changed

7 files changed

+29
-234
lines changed

.github/workflows/spec-update.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ jobs:
5252
with:
5353
token: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
5454

55+
- name: "Setup Java"
56+
uses: actions/setup-java@v4
57+
with:
58+
distribution: "sapmachine"
59+
java-version: ${{ env.JAVA_VERSION }}
60+
cache: 'maven'
61+
62+
- name: "Install Baseline SDK Version"
63+
# this is needed as otherwise "process sources" will fail on e.g. orchestration module, if the core module isn't in the maven cache
64+
run: |
65+
mvn install -DskipTests
66+
5567
- name: "Checkout or Create Branch"
5668
id: branch
5769
# Checkout branch if it exists, otherwise create it
@@ -98,14 +110,6 @@ jobs:
98110
echo "spec_diff=false" >> "$GITHUB_OUTPUT"
99111
fi
100112
101-
- name: "Setup java"
102-
uses: actions/setup-java@v4
103-
if: steps.spec_diff.outputs.spec_diff == 'true'
104-
with:
105-
distribution: "temurin"
106-
java-version: ${{ env.JAVA_VERSION }}
107-
cache: 'maven'
108-
109113
- name: "Generate"
110114
id: generate
111115
if: steps.spec_diff.outputs.spec_diff == 'true'

core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
<removeOperationIdPrefixDelimiter>\.</removeOperationIdPrefixDelimiter>
193193
<removeOperationIdPrefixCount>3</removeOperationIdPrefixCount>
194194
<aiSdkConstructor>true</aiSdkConstructor>
195+
<useOneOfCreators>true</useOneOfCreators>
195196
</additionalProperties>
196197
</configuration>
197198
</execution>

core/src/main/java/com/sap/ai/sdk/core/model/KpiResultRowItem.java

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -11,123 +11,8 @@
1111

1212
package com.sap.ai.sdk.core.model;
1313

14-
import com.fasterxml.jackson.annotation.JsonAnyGetter;
15-
import com.fasterxml.jackson.annotation.JsonAnySetter;
16-
import com.fasterxml.jackson.annotation.JsonIgnore;
1714
import com.google.common.annotations.Beta;
18-
import java.util.LinkedHashMap;
19-
import java.util.Map;
20-
import java.util.NoSuchElementException;
21-
import java.util.Objects;
22-
import java.util.Set;
23-
import javax.annotation.Nonnull;
24-
import javax.annotation.Nullable;
2515

2616
/** KpiResultRowItem */
27-
@Beta // CHECKSTYLE:OFF
28-
public class KpiResultRowItem
29-
// CHECKSTYLE:ON
30-
{
31-
@JsonAnySetter @JsonAnyGetter
32-
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
33-
34-
/** Default constructor for KpiResultRowItem. */
35-
protected KpiResultRowItem() {}
36-
37-
/**
38-
* Get the names of the unrecognizable properties of the {@link KpiResultRowItem}.
39-
*
40-
* @return The set of properties names
41-
*/
42-
@JsonIgnore
43-
@Nonnull
44-
public Set<String> getCustomFieldNames() {
45-
return cloudSdkCustomFields.keySet();
46-
}
47-
48-
/**
49-
* Get the value of an unrecognizable property of this {@link KpiResultRowItem} instance.
50-
*
51-
* @deprecated Use {@link #toMap()} instead.
52-
* @param name The name of the property
53-
* @return The value of the property
54-
* @throws NoSuchElementException If no property with the given name could be found.
55-
*/
56-
@Nullable
57-
@Deprecated
58-
public Object getCustomField(@Nonnull final String name) throws NoSuchElementException {
59-
if (!cloudSdkCustomFields.containsKey(name)) {
60-
throw new NoSuchElementException("KpiResultRowItem has no field with name '" + name + "'.");
61-
}
62-
return cloudSdkCustomFields.get(name);
63-
}
64-
65-
/**
66-
* Get the value of all properties of this {@link KpiResultRowItem} instance including
67-
* unrecognized properties.
68-
*
69-
* @return The map of all properties
70-
*/
71-
@JsonIgnore
72-
@Nonnull
73-
public Map<String, Object> toMap() {
74-
final Map<String, Object> declaredFields = new LinkedHashMap<>(cloudSdkCustomFields);
75-
return declaredFields;
76-
}
77-
78-
/**
79-
* Set an unrecognizable property of this {@link KpiResultRowItem} instance. If the map previously
80-
* contained a mapping for the key, the old value is replaced by the specified value.
81-
*
82-
* @param customFieldName The name of the property
83-
* @param customFieldValue The value of the property
84-
*/
85-
@JsonIgnore
86-
public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) {
87-
cloudSdkCustomFields.put(customFieldName, customFieldValue);
88-
}
89-
90-
@Override
91-
public boolean equals(@Nullable final java.lang.Object o) {
92-
if (this == o) {
93-
return true;
94-
}
95-
if (o == null || getClass() != o.getClass()) {
96-
return false;
97-
}
98-
final KpiResultRowItem kpiResultRowItem = (KpiResultRowItem) o;
99-
return Objects.equals(this.cloudSdkCustomFields, kpiResultRowItem.cloudSdkCustomFields);
100-
}
101-
102-
@Override
103-
public int hashCode() {
104-
return Objects.hash(cloudSdkCustomFields);
105-
}
106-
107-
@Override
108-
@Nonnull
109-
public String toString() {
110-
final StringBuilder sb = new StringBuilder();
111-
sb.append("class KpiResultRowItem {\n");
112-
cloudSdkCustomFields.forEach(
113-
(k, v) ->
114-
sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
115-
sb.append("}");
116-
return sb.toString();
117-
}
118-
119-
/**
120-
* Convert the given object to string with each line indented by 4 spaces (except the first line).
121-
*/
122-
private String toIndentedString(final java.lang.Object o) {
123-
if (o == null) {
124-
return "null";
125-
}
126-
return o.toString().replace("\n", "\n ");
127-
}
128-
129-
/** Create a new {@link KpiResultRowItem} instance. No arguments are required. */
130-
public static KpiResultRowItem create() {
131-
return new KpiResultRowItem();
132-
}
133-
}
17+
@Beta
18+
public interface KpiResultRowItem {}

core/src/main/java/com/sap/ai/sdk/core/model/TrckTagName.java

Lines changed: 11 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -11,123 +11,25 @@
1111

1212
package com.sap.ai.sdk.core.model;
1313

14-
import com.fasterxml.jackson.annotation.JsonAnyGetter;
15-
import com.fasterxml.jackson.annotation.JsonAnySetter;
16-
import com.fasterxml.jackson.annotation.JsonIgnore;
1714
import com.google.common.annotations.Beta;
18-
import java.util.LinkedHashMap;
19-
import java.util.Map;
20-
import java.util.NoSuchElementException;
21-
import java.util.Objects;
22-
import java.util.Set;
2315
import javax.annotation.Nonnull;
24-
import javax.annotation.Nullable;
2516

2617
/** TrckTagName */
27-
@Beta // CHECKSTYLE:OFF
28-
public class TrckTagName
29-
// CHECKSTYLE:ON
30-
{
31-
@JsonAnySetter @JsonAnyGetter
32-
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
33-
34-
/** Default constructor for TrckTagName. */
35-
protected TrckTagName() {}
36-
37-
/**
38-
* Get the names of the unrecognizable properties of the {@link TrckTagName}.
39-
*
40-
* @return The set of properties names
41-
*/
42-
@JsonIgnore
43-
@Nonnull
44-
public Set<String> getCustomFieldNames() {
45-
return cloudSdkCustomFields.keySet();
46-
}
47-
48-
/**
49-
* Get the value of an unrecognizable property of this {@link TrckTagName} instance.
50-
*
51-
* @deprecated Use {@link #toMap()} instead.
52-
* @param name The name of the property
53-
* @return The value of the property
54-
* @throws NoSuchElementException If no property with the given name could be found.
55-
*/
56-
@Nullable
57-
@Deprecated
58-
public Object getCustomField(@Nonnull final String name) throws NoSuchElementException {
59-
if (!cloudSdkCustomFields.containsKey(name)) {
60-
throw new NoSuchElementException("TrckTagName has no field with name '" + name + "'.");
61-
}
62-
return cloudSdkCustomFields.get(name);
63-
}
64-
65-
/**
66-
* Get the value of all properties of this {@link TrckTagName} instance including unrecognized
67-
* properties.
68-
*
69-
* @return The map of all properties
70-
*/
71-
@JsonIgnore
72-
@Nonnull
73-
public Map<String, Object> toMap() {
74-
final Map<String, Object> declaredFields = new LinkedHashMap<>(cloudSdkCustomFields);
75-
return declaredFields;
76-
}
18+
@Beta
19+
public interface TrckTagName {
20+
/** Helper class to create a String that implements {@link TrckTagName}. */
21+
record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value)
22+
implements TrckTagName {}
7723

7824
/**
79-
* Set an unrecognizable property of this {@link TrckTagName} instance. If the map previously
80-
* contained a mapping for the key, the old value is replaced by the specified value.
25+
* Creator to enable deserialization of a String.
8126
*
82-
* @param customFieldName The name of the property
83-
* @param customFieldValue The value of the property
27+
* @param val the value to use
28+
* @return a new instance of {@link InnerString}.
8429
*/
85-
@JsonIgnore
86-
public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) {
87-
cloudSdkCustomFields.put(customFieldName, customFieldValue);
88-
}
89-
90-
@Override
91-
public boolean equals(@Nullable final java.lang.Object o) {
92-
if (this == o) {
93-
return true;
94-
}
95-
if (o == null || getClass() != o.getClass()) {
96-
return false;
97-
}
98-
final TrckTagName trckTagName = (TrckTagName) o;
99-
return Objects.equals(this.cloudSdkCustomFields, trckTagName.cloudSdkCustomFields);
100-
}
101-
102-
@Override
103-
public int hashCode() {
104-
return Objects.hash(cloudSdkCustomFields);
105-
}
106-
107-
@Override
30+
@com.fasterxml.jackson.annotation.JsonCreator
10831
@Nonnull
109-
public String toString() {
110-
final StringBuilder sb = new StringBuilder();
111-
sb.append("class TrckTagName {\n");
112-
cloudSdkCustomFields.forEach(
113-
(k, v) ->
114-
sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
115-
sb.append("}");
116-
return sb.toString();
117-
}
118-
119-
/**
120-
* Convert the given object to string with each line indented by 4 spaces (except the first line).
121-
*/
122-
private String toIndentedString(final java.lang.Object o) {
123-
if (o == null) {
124-
return "null";
125-
}
126-
return o.toString().replace("\n", "\n ");
127-
}
128-
129-
/** Create a new {@link TrckTagName} instance. No arguments are required. */
130-
public static TrckTagName create() {
131-
return new TrckTagName();
32+
static InnerString create(@Nonnull final String val) {
33+
return new InnerString(val);
13234
}
13335
}

document-grounding/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
141141
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
142142
<useOneOfInterfaces>true</useOneOfInterfaces>
143+
<useOneOfCreators>true</useOneOfCreators>
143144
</additionalProperties>
144145
</configuration>
145146
</execution>

orchestration/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
188188
<useOneOfInterfaces>true</useOneOfInterfaces>
189189
<removeEnumValuePrefix>true</removeEnumValuePrefix>
190+
<useOneOfCreators>true</useOneOfCreators>
190191
</additionalProperties>
191192
</configuration>
192193
</execution>

prompt-registry/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<removeOperationIdPrefixDelimiter>\.</removeOperationIdPrefixDelimiter>
152152
<removeOperationIdPrefixCount>3</removeOperationIdPrefixCount>
153153
<useOneOfInterfaces>true</useOneOfInterfaces>
154+
<useOneOfCreators>true</useOneOfCreators>
154155
</additionalProperties>
155156
</configuration>
156157
</execution>

0 commit comments

Comments
 (0)