Skip to content

Commit bb87db2

Browse files
committed
Update addError to give precedence to newly added schemas
HttpApiSchema.UnionUnify creates a union whose members are listed in the order of `[...firstArgUnionMembers, ...secondArgUnionMembers]`. When encoding a union, Schema will try each member in the order that they appear. So the `addError` method on each of the HttpApi* classes, by passing the user-provided schema as a second argument, causes older schemas that encompass newer schemas to take precedence over the newer ones. By flipping the argument order, users are now able to use `addError` with a schema that (partly) encompasses an older one, to override the encoding behaviour of value conforming to that schema.
1 parent ec6cb5d commit bb87db2

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

packages/platform/src/HttpApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ const Proto = {
176176
return makeProto({
177177
groups: this.groups,
178178
errorSchema: HttpApiSchema.UnionUnify(
179-
this.errorSchema,
180179
schema.annotations(HttpApiSchema.annotations({
181180
status: annotations?.status ?? HttpApiSchema.getStatusError(schema)
182-
}))
181+
})),
182+
this.errorSchema
183183
),
184184
annotations: this.annotations,
185185
middlewares: this.middlewares

packages/platform/src/HttpApiEndpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,12 @@ const Proto = {
697697
return makeProto({
698698
...this,
699699
errorSchema: HttpApiSchema.UnionUnify(
700-
this.errorSchema,
701700
schema.pipe(
702701
Schema.annotations(HttpApiSchema.annotations({
703702
status: annotations?.status ?? HttpApiSchema.getStatusError(schema)
704703
}))
705-
)
704+
),
705+
this.errorSchema
706706
)
707707
})
708708
},

packages/platform/src/HttpApiGroup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ const Proto = {
307307
topLevel: this.topLevel,
308308
endpoints: this.endpoints,
309309
errorSchema: HttpApiSchema.UnionUnify(
310-
this.errorSchema,
311310
schema.annotations(HttpApiSchema.annotations({
312311
status: annotations?.status ?? HttpApiSchema.getStatusError(schema)
313-
}))
312+
})),
313+
this.errorSchema
314314
),
315315
annotations: this.annotations,
316316
middlewares: this.middlewares

0 commit comments

Comments
 (0)