Add --useDeserializer opt-in code generation flag#396
Draft
afloren-palantir wants to merge 12 commits into
Draft
Add --useDeserializer opt-in code generation flag#396afloren-palantir wants to merge 12 commits into
afloren-palantir wants to merge 12 commits into
Conversation
When --nullSafeDeserialization is enabled (default off): - Each generated type (object, union, enum, flavorized alias) exports a ConjureType descriptor constant (_TypeName) alongside its type/class - Generated service methods wrap bridge responses with deserialize(descriptor, result) from conjure-client - Non-throwing services wrap with IConjureResult including deserialize - Streaming (octet-stream) endpoints are unaffected Flag-off output is byte-identical to today's output (non-breaking). Requires conjure-client with the companion deserialization engine. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generate changelog in
|
The flag is about enabling the full schema-driven deserializer, not narrowly about null safety. Renaming to useDeserializer better conveys the broader scope: integer/safelong range validation, double NaN conversion, optional→undefined coercion, and null collection handling. Updated CLI description to enumerate the §5.6 behaviours the engine applies. Added references to issues #48, #78, #156 in the doc comment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 tasks
Use Array<T> instead of T[] for non-simple (import-qualified) types as required by the project's tslint array-type rule. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Aligns with conjure-client renaming: string→stringType, boolean→booleanType, any→anyType (avoids tslint keyword-clash violations in the runtime package). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- generateType.ts: use named ITypeName import instead of inline import() form; ITypeName[] is consistent with buildDescriptorExpr.ts - generateThrowingEndpoint.ts: break long object argument over multiple lines - generateNonThrowingEndpoint.ts: wrap long template literal argument Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview✨ Features
|
Tests cover all four type generators (enum, object, union, flavorized alias) verifying descriptor constants are emitted with the correct builder expressions when useDeserializer is true, and are absent when the flag is off. Also tests throwing and non-throwing service generators for the deserialize() wrapping, cross-type reference() descriptors, void/binary exemptions, and flag-off regression. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…pplyFromJson Replaces the monolithic useDeserializer flag with three composable, incrementally-adoptable flags: - generateJsonTypes: emits IFooJSON interfaces with wire-accurate nullability (collections become T | null | undefined; object/union references use IBarJSON). Zero runtime cost. - generateFromJson: emits fromFooJson(json: IFooJSON): IFoo per-type deserializer functions applying Conjure 5.6 rules (null collections -> empty, recursive object deserialization). Implicitly enables generateJsonTypes. (Future: toFooJson serializer follows the same pattern.) - applyFromJson: automatically pipes service responses through the appropriate fromFooJson by updating the bridge call generic and appending .then(fromFooJson). Exempt for binary (octet-stream) endpoints. Addresses #48. Removes: - src/utils/buildDescriptorExpr.ts (ConjureType descriptor machinery) - _TypeName descriptor constants - deserialize() service response wrapping - --useDeserializer CLI flag Adds: - src/utils/resolveJsonTsType.ts: JSON-accurate type string resolution - src/utils/buildFromJsonExpr.ts: field-level and service-level expression builders Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ith _ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rts lint rule Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
Adds
--useDeserializeropt-in CLI flag (defaultfalse, non-breaking) that enables schema-driven response deserialization for all generated services. Addresses the serde layer requested in #48 and the downstream issues it would fix (#78, #156).What the flag does
_TypeNameConjureTypedescriptor constant alongside its existing type/classbridge.call(...)responses withdeserialize(_ReturnTypeDescriptor, result)fromconjure-clientWithErrors) services similarly wrap results including deserializationapplication/octet-stream) endpoints are unaffected§5.6 behaviours applied at runtime (via conjure-client engine)
list/set/mapnull →[]/{}(addresses Collection types should be optional #78)optionalnull →undefined(addresses Have a single way to represent absent values: use undefined #156)double"NaN"/"Infinity"strings → JSnumbervalues (addresses Serialization/deserialization layer (translate the string "NaN" to the js Number.NaN value) #48)integer32-bit range validation;safelongsafe-integer range validationDepends on: palantir/conjure-typescript-runtime#197 (the
deserializeengine in conjure-client)Test plan
yarn testpasses with flag off — output unchanged from baselineyarn testpasses with flag on —_TypeNameconstants emitted, service calls wrapped withdeserialize--useDeserializerflag visible in--helpoutput🤖 Generated with Claude Code