Skip to content

API: add python client option (fhirpy|none), default fhirpy; deprecate fhirpyClient#187

Merged
ryukzak merged 2 commits into
mainfrom
api/python-client-option
Jun 18, 2026
Merged

API: add python client option (fhirpy|none), default fhirpy; deprecate fhirpyClient#187
ryukzak merged 2 commits into
mainfrom
api/python-client-option

Conversation

@ryukzak

@ryukzak ryukzak commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Generator/library change extracted from the python-fhirpy-default work (per review): introduce a client option for the Python generator and make fhirpy the default, plus a type-checking fix for fhirpy + snake_case models.

.python({ client })

Replace the boolean fhirpyClient with:

client?: "fhirpy" | "none"   // default: "fhirpy"
  • "fhirpy" — models extend FhirpyBaseModel (fhirpy AsyncFHIRClient compatible).
  • "none" — plain Pydantic models, no client-specific code.
  • fhirpyClient is kept and @deprecated — it still works (logs a one-line warning and is translated: true"fhirpy", false"none"). Explicit client wins.
  • Default is now "fhirpy" — callers that want plain models opt in with client: "none".
.python({ fhirpyClient: true })   // deprecated
.python({ client: "fhirpy" })     // or just omit it — fhirpy is the default
.python({ client: "none" })       // plain models

fhirpy + snake_case type-checking fix

FhirpyBaseModel now declares a TYPE_CHECKING-only settable resourceType: str = "". fhirpy's TResource is bound to a ResourceProtocol with a settable resourceType; snake_case models expose the discriminator as resource_type (alias resourceType) and only set resourceType at runtime via __pydantic_init_subclass__, which mypy can't see — so fhirpy calls failed type-checking. The annotation is settable (satisfies the protocol bound + class access), defaulted (so the pydantic mypy plugin treats it as optional, not a required ctor arg), and runtime-invisible.

Tests

  • Existing python writer tests made explicit (client: "none") to keep testing plain generation.
  • New tests: default → fhirpy (FhirpyBaseModel + fhirpy_base_model.py present), "none" → plain (absent), deprecated fhirpyClient: true → fhirpy.
  • tsc + biome clean; no snapshot changes.

Foundation for the example PRs (#185 / #186); merges independently to main.

ryukzak added 2 commits June 18, 2026 17:43
…kers

fhirpy AsyncFHIRClient is generic over TResource, bound to a ResourceProtocol with a
settable resourceType. snake_case models expose the discriminator as resource_type
(alias resourceType) and only set resourceType at runtime via __pydantic_init_subclass__,
which mypy cannot see. Declare a TYPE_CHECKING-only settable instance annotation
(resourceType: str = "") so the models satisfy the protocol bound and class access,
with no runtime change.
Replace the boolean fhirpyClient with client: "fhirpy" | "none" on .python({}).
client wins; fhirpyClient is the deprecated fallback (logs a warning, still translated);
the default is now "fhirpy". Add tests for the default, "none", and the deprecated path.
@ryukzak ryukzak merged commit f374607 into main Jun 18, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant