Skip to content

Fix credential form crash for array-form JSON Schema type#4678

Merged
elias-ba merged 2 commits into
mainfrom
fix/credential-schema-array-type-4647
Apr 30, 2026
Merged

Fix credential form crash for array-form JSON Schema type#4678
elias-ba merged 2 commits into
mainfrom
fix/credential-schema-array-type-4647

Conversation

@elias-ba
Copy link
Copy Markdown
Contributor

@elias-ba elias-ba commented Apr 29, 2026

Description

Picking the Browserless type from the credential modal crashes the form on render, change, and save. The credential schema parser couldn't handle JSON Schema's array form for nullable fields (["string", "null"]), which Browserless uses for the Base URL field. Now it can.

The Browserless schema is also internally contradictory (Base URL is required with minLength: 1, so "null" could never validate). That's fixed upstream in OpenFn/adaptors#1659.

Closes #4647

Validation steps

With this branch, open a project's Credentials, click "Add credential", and pick Browserless. The form should render and let you save.

Additional notes for the reviewer

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review with Claude Code)
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

`Credentials.Schema.get_types/1` assumed each property's `type` was a
single string and called `String.to_atom/1` on it directly. JSON Schema
draft-07 also allows `type` to be a list (e.g. `["string", "null"]` for
nullable fields), which the bundled Browserless schema uses for `baseUrl`.
The list reached `String.to_atom/1` and raised an `ArgumentError`,
crashing the credential form on render, on validate, and on save.

Normalize the property type before atomizing: drop `"null"` from list
forms, default to `"string"` if only `"null"` remains, and continue
mapping `"object"` to `"map"`.

Closes #4647
@github-project-automation github-project-automation Bot moved this to New Issues in Core Apr 29, 2026
@github-actions
Copy link
Copy Markdown

Reviewing the diff. The changes scope to:

  1. lib/lightning/credentials/schema.ex — adds normalize_property_type/1 helper for JSON Schema array-form types
  2. test/lightning/credentials/schema_test.exs — test coverage
  3. CHANGELOG.md — entry

This is a pure type-normalization fix in a schema-parsing helper. No DB queries, no web-layer actions, no Repo writes — only string/atom mapping over a JSON Schema map.

Security Review ✅

  • S0 (project scoping): N/A, the change is to Credentials.Schema.get_types/1, a pure JSON Schema type-normalization helper with no DB access or project-scoped query.
  • S1 (authorization): N/A, no new controller actions, LiveView handle_events, or other web-layer entrypoints are introduced.
  • S2 (audit trail): N/A, no Repo.insert/update/delete or config-resource mutations are added; the function only parses schema property types.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.86%. Comparing base (7ac004e) to head (52929f7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4678      +/-   ##
==========================================
+ Coverage   89.80%   89.86%   +0.05%     
==========================================
  Files         444      444              
  Lines       21771    21774       +3     
==========================================
+ Hits        19552    19567      +15     
+ Misses       2219     2207      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Reword changelog so it doesn't claim this PR corrects browserless.json
  (the schema fix lives in OpenFn/adaptors#1659; priv/schemas/ is
  gitignored in Lightning).
- Add a round-trip Schema.validate/2 test against an array-form `type`
  schema to prove the full pipeline (cast plus ExJsonSchema) accepts a
  valid URI and rejects an invalid one.
@elias-ba elias-ba merged commit e2c22e3 into main Apr 30, 2026
7 checks passed
@elias-ba elias-ba deleted the fix/credential-schema-array-type-4647 branch April 30, 2026 08:43
@github-project-automation github-project-automation Bot moved this from New Issues to Done in Core Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

App crash on "browserless" credential creation

3 participants