Skip to content

fix: unwrap data in document_types.get(), rename schema_ → jsonSchema, add is_public#20

Merged
rarce merged 1 commit into
mainfrom
fix/issue-19-unwrap-get-and-is-public
May 7, 2026
Merged

fix: unwrap data in document_types.get(), rename schema_ → jsonSchema, add is_public#20
rarce merged 1 commit into
mainfrom
fix/issue-19-unwrap-get-and-is-public

Conversation

@rarce
Copy link
Copy Markdown
Contributor

@rarce rarce commented May 7, 2026

Closes #19

Summary

Ports docutray-node#20 to the Python SDK and closes a small gap from the docutray-node#18 port (missing is_public kwarg).

Bug fix — document_types.get() returns the raw {data} wrapper

GET /api/document-types/{id} returns { "data": {...} }, same as POST / PUT. With model_config = ConfigDict(extra="allow") on DocumentType, model_validate({"data": {...}}) did not raise — but every typed field (id, name, codeType, …) silently fell back to defaults because the actual fields were nested under data. Consumers received a DocumentType whose fields all looked empty.

Fixed sync (document_types.py:127), async (document_types.py:402), and the raw response wrappers (_response.py:803, 1023) by mirroring the unwrap pattern already used by create() / update():

return DocumentType.model_validate(
    response.json().get("data", response.json())
)

Type-only breaking change — DocumentType.schema_DocumentType.jsonSchema

The API returns this field as jsonSchema (consistent with codeType, isDraft, createdAt). The previous name schema_ never matched the wire — the field was always None. Renamed to match the API. Pre-1.0 patch releases are allowed to carry type-level breaking changes per project policy. Updated the docstring example in resources/document_types.py:124 and the README example.

Gap closed — is_public kwarg on create/update

The Node DocumentTypeCreateParams / DocumentTypeUpdateParams interfaces both expose isPublic. Added is_public: bool | None = None kwarg to all six methods (sync, async, and raw response wrappers for both create() and update()).

Acceptance criteria

  • client.document_types.get(id) returns a flat DocumentType with all fields populated (sync + async + raw wrappers).
  • DocumentType.jsonSchema replaces DocumentType.schema_. Docstring + README example updated.
  • client.document_types.create(...) and .update(...) accept is_public: bool | None = None (six methods total).
  • Tests cover get() mocked with {"data": {...}} and assert unwrapped result including jsonSchema. Tests cover is_public=True / is_public=False forwarding to body as isPublic, and is_public=None omits the field.
  • uv run pytest (340 passed), uv run mypy src (clean), uv run ruff check src tests (clean).
  • CHANGELOG [0.2.1] entry; version bumped in pyproject.toml and src/docutray/_version.py.

Out of scope

The Node PR #20 description flags an audit of other endpoints that may also be missing the {data} unwrap. In Python, KnowledgeBases.get and KnowledgeBaseDocuments.get already unwrap correctly. Status-polling endpoints (Steps.get_status, Convert.*, Identify.*) most likely are NOT wrapped, but should be confirmed in a separate issue.

Test plan

  • Unit: tests/test_resources/test_document_types.pyget() mocks {"data": {...}}, asserts doc_type.jsonSchema populated; new tests for is_public forwarding (sync create + update; existing async tests still pass against unchanged surface).
  • Full suite: 340/340 passing.
  • Smoke test against real backend once published — verify client.document_types.get() no longer returns empty fields.

🤖 Generated with Claude Code

…jsonSchema, add is_public

Closes #19

- document_types.get() (sync + async + raw response wrappers) now unwraps
  the { data } envelope returned by GET /api/document-types/{id}.
  Previously every typed field silently fell back to defaults because the
  fields were nested under data.
- Renamed DocumentType.schema_ to DocumentType.jsonSchema to match the API
  wire format. Type-only breaking change (pre-1.0 patch).
- Added is_public kwarg to create() and update() (sync + async + raw
  response wrappers) closing a gap from the docutray-node#18 port.
- Updated docstring example, README example, and tests. Bumped to 0.2.1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rarce rarce merged commit 80bc834 into main May 7, 2026
@rarce rarce deleted the fix/issue-19-unwrap-get-and-is-public branch May 7, 2026 17:09
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.

fix: port docutray-node PR #20 (unwrap get() + jsonSchema) and add is_public to DocumentTypes create/update

1 participant