-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[java] Support 'duration' format #23695
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -676,6 +676,8 @@ public void processOpts() { | |
| importMapping.put("LocalTime", "java.time.LocalTime"); | ||
| typeMapping.put("date-time-local", "LocalDateTime"); | ||
| importMapping.put("LocalDateTime", "java.time.LocalDateTime"); | ||
| typeMapping.put("duration", "Duration"); | ||
| importMapping.put("Duration", "java.time.Duration"); | ||
| if ("java8-localdatetime".equals(dateLibrary)) { | ||
| typeMapping.put("DateTime", "LocalDateTime"); | ||
| } else { | ||
|
|
@@ -1458,6 +1460,13 @@ public String toDefaultValue(CodegenProperty cp, Schema schema) { | |
| } | ||
| } | ||
| return null; | ||
| } else if (ModelUtils.isDurationSchema(schema)) { | ||
| if (schema.getDefault() != null) { | ||
| if ("java8".equals(getDateLibrary())) { | ||
| return String.format(Locale.ROOT, "Duration.parse(\"%s\")", schema.getDefault()); | ||
| } | ||
| } | ||
| return null; | ||
| } else if (ModelUtils.isStringSchema(schema)) { | ||
| if (schema.getDefault() != null) { | ||
| String _default; | ||
|
|
@@ -1548,6 +1557,10 @@ public String toDefaultValue(CodegenProperty cp, Schema schema) { | |
| if("java8".equals(getDateLibrary())) { | ||
| defaultPropertyExpression = String.format(Locale.ROOT, "java.time.LocalDateTime.parse(\"%s\")", value.asText()); | ||
| } | ||
| } else if(ModelUtils.isDurationSchema(propertySchema)) { | ||
| if("java8".equals(getDateLibrary())) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Nested Prompt for AI agents |
||
| defaultPropertyExpression = String.format(Locale.ROOT, "java.time.Duration.parse(\"%s\")", value.asText()); | ||
| } | ||
| } else if(ModelUtils.isUUIDSchema(propertySchema)) { | ||
| defaultPropertyExpression = "java.util.UUID.fromString(\"" + value.asText() + "\")"; | ||
| } else if(ModelUtils.isStringSchema(propertySchema)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import java.math.BigDecimal; | ||
| import java.time.Duration; | ||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
|
|
@@ -46,6 +47,8 @@ public class Pet { | |
|
|
||
| private LocalDateTime adoptionDate = LocalDateTime.parse("2007-12-03T10:15:30"); | ||
|
|
||
| private Duration tripDuration = Duration.parse("PT10H15M30S"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Mapping OpenAPI Prompt for AI agents |
||
|
|
||
| public Pet() { | ||
| super(); | ||
| } | ||
|
|
@@ -225,6 +228,27 @@ public void setAdoptionDate(LocalDateTime adoptionDate) { | |
| this.adoptionDate = adoptionDate; | ||
| } | ||
|
|
||
| public Pet tripDuration(Duration tripDuration) { | ||
| this.tripDuration = tripDuration; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Get tripDuration | ||
| * @return tripDuration | ||
| */ | ||
| @Valid | ||
| @Schema(name = "tripDuration", requiredMode = Schema.RequiredMode.NOT_REQUIRED) | ||
| @JsonProperty("tripDuration") | ||
| public Duration getTripDuration() { | ||
| return tripDuration; | ||
| } | ||
|
|
||
| @JsonProperty("tripDuration") | ||
| public void setTripDuration(Duration tripDuration) { | ||
| this.tripDuration = tripDuration; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
|
|
@@ -241,12 +265,13 @@ public boolean equals(Object o) { | |
| Objects.equals(this.lastFeed, pet.lastFeed) && | ||
| Objects.equals(this.dateOfBirth, pet.dateOfBirth) && | ||
| Objects.equals(this.feedingTime, pet.feedingTime) && | ||
| Objects.equals(this.adoptionDate, pet.adoptionDate); | ||
| Objects.equals(this.adoptionDate, pet.adoptionDate) && | ||
| Objects.equals(this.tripDuration, pet.tripDuration); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(atType, age, happy, price, lastFeed, dateOfBirth, feedingTime, adoptionDate); | ||
| return Objects.hash(atType, age, happy, price, lastFeed, dateOfBirth, feedingTime, adoptionDate, tripDuration); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -261,6 +286,7 @@ public String toString() { | |
| sb.append(" dateOfBirth: ").append(toIndentedString(dateOfBirth)).append("\n"); | ||
| sb.append(" feedingTime: ").append(toIndentedString(feedingTime)).append("\n"); | ||
| sb.append(" adoptionDate: ").append(toIndentedString(adoptionDate)).append("\n"); | ||
| sb.append(" tripDuration: ").append(toIndentedString(tripDuration)).append("\n"); | ||
| sb.append("}"); | ||
| return sb.toString(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Duration defaults are dropped for
java8-*variants because this branch only accepts exactjava8even thoughdurationis mapped for alljava8*libraries.Prompt for AI agents