Fix #111: Add optionality info to API definition for nullable properties #126
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "typosaurus/ticket-111"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Resolves #111.
Plan
Implementation Plan: Add Nullable Annotations to Custom /docs API Definition
1. Modified Files & Changes
devplacepy/docs_api/_shared.pynullable: bool = Falseparameter tofield(). Store it in the field metadata dictionary.devplacepy/docs_examples.pyschema_example(): after generating a sample value via_unwrap_optional(), if the field hasnullable=Trueand the generated value is not alreadyNone, replace it withNone(JSONnull). Also append" (nullable)"to the field’s label or description in the generated example dict.devplacepy/routers/profile.py(or whereverProfileOutendpoint is defined)field()call for theprojectslist member (or the relevant response field), addnullable=Truefor each Optional field that is currently nullable. For example:field(name="updated_at", type=str, nullable=True). If the router uses a shared schema definition, add annotations there.static/js/ApiTester.js(approximate path:devplacepy/static/ordocs_api/static/)renderExpected()(line ~318), check if the field object has anullableproperty. If true, append a small badge or label like[nullable]next to the field name in the JSON sample (e.g., as a comment or in a separate column). Alternative: render the sample value asnullwith a tooltip.tests/unit/test_docs_nullable.py– Verify
field(nullable=True)sets the metadata correctly.– Verify
schema_example()producesnullfor a nullable field.– Verify the rendered JSON snippet in
ApiTester.jsincludes a nullability indicator (requires a Playwright screenshot or DOM assertion – optional if unit tests for Python logic are sufficient).2. Detailed Steps (for a competent engineer)
Step A – In
devplacepy/docs_api/_shared.py:nullable: bool = Falseto the function signature offield().field(), add a key"nullable"to the returned dict (or to the field metadata) set to the value ofnullable.Step B – In
devplacepy/docs_examples.py:_unwrap_optional()call (line ~45). After resolving the final type and generating a default sample, check if the field’s metadata dict has"nullable": True.None(JSONnull) in the output dict." (nullable)".Step C – Update router definitions:
ProjectOutorProfileOutand whosefield()calls currently lacknullable=Truefor Optional fields.nullable=Truetofield(name="updated_at", ...).Optional[...]in the Pydantic schemas but are only referenced through thefield()function for /docs (the router might not usefield()at all – if that’s the case, skip and the sample generator will infer nullability from the Pydantic model if the model is used directly. The ticket’s custom docs may not use Pydantic models directly; it usesfield()calls. We must assume that each endpoint manually lists fields viafield()– verify in the code).Step D – Modify
ApiTester.js:renderExpected()method, iterate over the fields of the example response (the sample object). If a field metadata hasnullable: true, add a small attribute or CSS class to the rendered<code>element, or insert a<span class="nullable-badge">nullable</span>after the field name for human readers.Step E – Write unit tests:
test_field_nullable_parameter()callsfield(nullable=True)and checks returned dict.test_schema_example_nullable_field()creates a mock schema with a nullable field and callsschema_example(), assertsNoneappears in output.test_api_tester_renders_nullable()uses Playwright to open the /docs page for a known endpoint and checks that the nullable badge is present.3. Definition of Done
field()function indevplacepy/docs_api/_shared.pyacceptsnullable: bool = Falseand stores it.schema_example()function indevplacepy/docs_examples.pyreturnsnullin JSON for any field markednullable=True.ProjectOutorProfileOuthave theirfield()definitions updated to passnullable=Trueon fields likeupdated_at.pytest tests/e2e/in a compatible environment to confirm).Opened automatically by Typosaurus.
Checkout
From your project repository, check out a new branch and test the changes.