Skip to content

fix(validator): reject type "null" in OAS 3.0 documents#365

Merged
erraggy merged 1 commit intomainfrom
fix/validator-null-type-oas30
Apr 18, 2026
Merged

fix(validator): reject type "null" in OAS 3.0 documents#365
erraggy merged 1 commit intomainfrom
fix/validator-null-type-oas30

Conversation

@erraggy
Copy link
Copy Markdown
Owner

@erraggy erraggy commented Apr 18, 2026

Summary

  • OAS 3.0.x only allows type to be one of array, boolean, integer, number, object, string. The "null" type was introduced in OAS 3.1+ (JSON Schema 2020-12). Previously the validator silently accepted type: "null" on 3.0 documents.
  • Plumb the parsed OAS version onto the Validator via a new oasVersion field (set in ValidateParsed) and add a "null" case to validateSchemaTypeConstraints that emits an error when the document is OAS 3.0.x.
  • OAS 3.1+ continues to accept both scalar type: "null" and the type-array form (e.g. ["string", "null"]) — this PR only tightens the 3.0 path.

Fixes #362.

Error message

✗ null is not a valid type for OpenAPI 3.0; valid types are: array, boolean, integer, number, object, string. Use "nullable: true" instead.

Scope note

The issue mentions a related pattern — specs that carry both nullable: true (3.0 idiom) and anyOf: [{type: "null"}] (3.1 idiom). That cross-idiom check is intentionally deferred to keep this PR tight and focused on the primary reported bug.

Test plan

  • New TestValidate_NullType_OAS30_Rejected covers all 3.0.x minor versions (3.0.0 through 3.0.4)
  • TestValidate_NullType_OAS31_Allowed regression guard — 3.1.0 still accepts type: "null"
  • TestValidate_StringType_OAS30_Allowed regression guard — valid 3.0 types still pass
  • make check passes locally (lint 0 issues, 8568 tests, validator coverage 89.4%)
  • CI green

🤖 Generated with Claude Code

In OAS 3.0.x, the only valid schema types are array, boolean, integer,
number, object, and string. The "null" type was introduced in OAS 3.1+
(JSON Schema 2020-12). Previously, validateSchemaTypeConstraints silently
accepted type: "null" on 3.0 documents because its switch had no "null"
case and no version check.

This change plumbs the parsed OAS version onto the Validator via a new
oasVersion field (set in ValidateParsed) and adds a "null" case to the
schema type switch that emits an error when the document is OAS 3.0.x.
OAS 3.1+ continues to accept both scalar type: "null" and the type-array
form (e.g. ["string", "null"]).

Fixes #362
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@erraggy has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 29 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 55 minutes and 29 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e0682a14-0850-4ba8-9dfe-6ca8db338a44

📥 Commits

Reviewing files that changed from the base of the PR and between 91814fe and 70e824b.

📒 Files selected for processing (3)
  • validator/schema.go
  • validator/schema_test.go
  • validator/validator.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/validator-null-type-oas30

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.76%. Comparing base (91814fe) to head (70e824b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #365   +/-   ##
=======================================
  Coverage   84.75%   84.76%           
=======================================
  Files         194      194           
  Lines       27458    27469   +11     
=======================================
+ Hits        23272    23283   +11     
  Misses       2842     2842           
  Partials     1344     1344           
Files with missing lines Coverage Δ
validator/schema.go 65.38% <100.00%> (+2.37%) ⬆️
validator/validator.go 92.80% <100.00%> (+0.05%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@erraggy erraggy merged commit bdfe66f into main Apr 18, 2026
8 checks passed
@erraggy erraggy deleted the fix/validator-null-type-oas30 branch April 18, 2026 01:44
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.

validator: type: "null" not flagged as invalid in OAS 3.0 documents

1 participant