Repository navigation
Conversation
…hook ApiClientBase takes an optional second argument with an onDeprecation handler. It is called for operations whose descriptor carries deprecated: true and for responses with a Deprecation (RFC 9745) or Sunset (RFC 8594) header. The default handler warns once per operation via process.emitWarning (DeprecationWarning) or console.warn in browsers. Handler errors never affect the request. Refs #166 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #166 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
newUnauthenticated, newWithToken and newWithCredentials take an optional options argument that is passed to ApiClientBase, e.g. onDeprecation. Refs #166 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #166 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #166. Stacked on #313: the base branch is
feat/emit-deprecated-operations. Retarget tomasteronce #313 is merged.#313 emits deprecated operations and marks them
@deprecated. That only helps people whose editor shows JSDoc. This PR adds a runtime signal: calling a deprecated operation warns once per operation by default, and consumers can handle the deprecation themselves through a structuredonDeprecationhook.What changes
Generator
Operation.compileDescriptoraddsdeprecated: trueto the runtime descriptor of deprecated operations. Active descriptors stay as they are.Commons
OpenAPIOperationgets an optionaldeprecated?: boolean.ApiClientBasetakes an optional second constructor argumentApiClientOptionswithonDeprecation.DeprecationEvent:operationId,method,path,source: "spec" | "response-header", and optionaldeprecationandsunsetdates.defaultDeprecationHandlerwarns once per operation, process-wide.process.emitWarning(msg, { type: "DeprecationWarning", code: "MITTWALD_API_DEPRECATED_OPERATION" }). So--no-deprecation,--throw-deprecationandprocess.on("warning")work as they do for Node's own deprecations.process.emitWarning(browsers) it callsconsole.warn.Deprecation(RFC 9745) andSunset(RFC 8594) are detected on every response.Deprecationvalues: the RFC 9745 structured date (@1688169599) and the older draft values (true, HTTP-date).Sunsetheader alone also counts as a deprecation.source: "spec", plus the header dates if present.awaitresumes. A spec-deprecated operation whose request fails, e.g. with a network error, still reports.DeprecationEvent,DeprecationHandler,ApiClientOptions,defaultDeprecationHandler,emitDeprecationWarning,oncePerOperation,parseDeprecationHeaders,formatDeprecationMessage,deprecationWarningCode.@mittwald/api-clientnewUnauthenticated(options?),newWithToken(token, options?)andnewWithCredentials(email, password, options?)take an optionalMittwaldAPIClientOptionsargument (v2 and v3-next).newWithCredentialspasses it to both internal clients. Existing call sites are unchanged.Generated client (
feat: update generated client)deprecated: truelines: +206 in v2 and +98 in v3-next, which matches the counts in feat(generator): emit deprecated operations with an @deprecated tag #313.Does the mittwald API send
Deprecation/Sunsettoday?No. I checked this on 2026-10-15 against
api.mittwald.de:200responses on four deprecated operations carry noDeprecation,Sunset,LinkorWarningheader. The four operations areGET /v2/user,GET /v2/users/self/personal-information,GET /v2/user/settingsandGET /v2/user/feedback.Access-Control-Expose-Headers. Even once it sendsDeprecation/Sunset, browser clients can't read them until the API also exposes them, e.g.Access-Control-Expose-Headers: Deprecation, Sunset, Link. Node clients aren't affected.The header detection is still part of this PR, because the API is likely to send these headers later. Until then every event has
source: "spec".Why an
onDeprecationcallbackThe question is what a consumer needs when they call a deprecated operation. There are two cases:
A structured callback covers both:
operationId,method,path,sourceandsunsetas typed fields. Consumers can filter, aggregate or alert without parsing a message string.Linkto the successor.oncePerOperation, and the default handler uses it, so the default stays quiet.onDeprecation: () => {}, which is explicit, works per client and is easy to find in code review.RequestOptions.onBeforeRequest: a plain function in an options object, with no new concepts.Alternatives considered and rejected
logger: { warn(...) })onWarn(message)hooksunsetandoperationIdwould sit inside the message. It would mix deprecations with any future warning, so every handler would need to tell them apart. Its contract would be vague ("some warning"), which makes later changes risky.withEventConsistencyHandlingoperationIdor the spec'sdeprecatedflag without passing the descriptor through the Axios config. As an opt-in wrapper it would also be off by default, which defeats the purpose. Detection therefore lives inrequestFunctionFactory, where the descriptor is at hand. The existing interceptors are unchanged.console.warnin Node as well--no-deprecation,--throw-deprecation,--trace-deprecationandprocess.on("warning")wouldn't apply.process.emitWarningwithtype: "DeprecationWarning"is the idiomatic Node signal.newWithCredentialsalone creates two clients. Dedupe in the default handler plus theoncePerOperationhelper serves both use cases.RequestOptions--throw-deprecationNode still throws, becauseemitWarningthrows on the next tick, outside ourtry.@deprecatedonly (#313)Review notes
DeprecationWarningper operation and process. That is intentional. Before feat(generator): emit deprecated operations with an @deprecated tag #313, deprecated operations didn't exist in the client, so this mainly affects operations that become deprecated in a future spec.ApiClientBase's constructor only gained an optional second parameter. The generated clients don't define their own constructor, so they inherit it.requestFunctionFactorystill throws synchronously ifonBeforeRequestthrows. Only theexecutepromise is wrapped.deprecation.test.tsandApiClientBase.deprecation.test.tsin commons, and two descriptor tests inPaths.test.ts.() => {}, a throwing hook, a rejecting async hook, header parsing,Sunseton spec-deprecated operations, and network errors.yarn nx run-many -t build lintpasses.🤖 Generated with Claude Code