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

Update scalafmt-core to 3.8.5 #264

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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# Scala Steward: Reformat with scalafmt 3.8.2
c1761dd17f98157d61fc8639d12803b6eafc1346

# Scala Steward: Reformat with scalafmt 3.8.5
b7f2450d5730e0e660f23d9ff350d8a2f00bdcf2
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.8.3
version = 3.8.5
maxColumn = 140
rewrite.rules = [RedundantBraces, RedundantParens, SortImports]
runner.dialect = scala3
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ lazy val examples = (projectMatrix in file("examples"))
.dependsOn(ox)

val compileDocs: TaskKey[Unit] = taskKey[Unit]("Compiles docs module throwing away its output")
compileDocs := {
compileDocs :=
(docs.jvm(scala2.head) / mdoc).toTask(" --out target/sttp-openai-docs").value
}

lazy val docs = (projectMatrix in file("generated-docs")) // important: it must not be docs/
.enablePlugins(MdocPlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ object ChatRequestBody {

/** OpenAI's JSON schema support imposes two requirements:
*
* 1. All fields must be `required`:
* https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required
*
* 1. All fields must be `required`: https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required
* 2. `additionalProperties: false` must always be set in objects:
* https://platform.openai.com/docs/guides/structured-outputs/additionalproperties-false-must-always-be-set-in-objects
*
* We implement these by folding over the JSON structure.
* However, if a schema uses discriminated unions (indicated by a `discriminator` property),
* we skip forcing `additionalProperties: false` to preserve flexibility in selecting sub-schemas.
* We implement these by folding over the JSON structure. However, if a schema uses discriminated unions (indicated by a
* `discriminator` property), we skip forcing `additionalProperties: false` to preserve flexibility in selecting sub-schemas.
*/
private val schemaFolder: Json.Folder[Json] = new Json.Folder[Json] {
lazy val onNull = Json.Null
Expand All @@ -50,21 +47,20 @@ object ChatRequestBody {
def onString(value: String): Json = Json.fromString(value)
def onArray(value: Vector[Json]): Json = Json.fromValues(value.map(_.foldWith(this)))
def onObject(value: JsonObject): Json = {
val state = value.toList.foldRight(FolderState(Nil, false, Nil)) {
case ((k, v), acc) =>
if (k == "properties")
acc.copy(
fields = (k, v.foldWith(this)) :: acc.fields,
addAdditionalProperties = true,
requiredProperties = v.asObject.fold(List.empty[String])(_.keys.toList)
)
else if (k == "type")
acc.copy(
fields = (k, v.foldWith(this)) :: acc.fields,
addAdditionalProperties = acc.addAdditionalProperties || v.asString.contains("object")
)
else
acc.copy(fields = (k, v.foldWith(this)) :: acc.fields)
val state = value.toList.foldRight(FolderState(Nil, false, Nil)) { case ((k, v), acc) =>
if (k == "properties")
acc.copy(
fields = (k, v.foldWith(this)) :: acc.fields,
addAdditionalProperties = true,
requiredProperties = v.asObject.fold(List.empty[String])(_.keys.toList)
)
else if (k == "type")
acc.copy(
fields = (k, v.foldWith(this)) :: acc.fields,
addAdditionalProperties = acc.addAdditionalProperties || v.asString.contains("object")
)
else
acc.copy(fields = (k, v.foldWith(this)) :: acc.fields)
}

// Detect if this object is part of a discriminated union by checking for a "discriminator" property.
Expand Down