validate: [tracking] hard-rules spec-compliance subcommand
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
这个 Issue 还没有评估数据。
描述
What
A new subcommand, oasdiff validate, that flags OpenAPI / JSON Schema spec violations. Strictly limited to hard rules: things the spec itself declares invalid. No style preferences, no team conventions, no config file.
Why
There is a quiet gap between two existing layers in the OpenAPI tooling stack:
- Parsing layer: the underlying parser catches structural / syntax errors at load time.
- Style / conventions layer: linters like Spectral and Redocly catch team-specific rules.
Between them sits a third layer of issues that are formally invalid per the OpenAPI / JSON Schema specs but get silently skipped at parse time and are not covered by style linters either. oasdiff validate fills that gap. Examples:
multipleOf > 0(JSON Schema §6.2.1)minimum ≤ maximumpatternis a valid regexinfo.title/info.versionnon-emptypathskeys start with/parameter.inis one ofquery/header/path/cookie
Scope discipline
A rule belongs in oasdiff validate only if it can cite a specific clause of the OpenAPI spec or referenced JSON Schema draft. If a reasonable reader could disagree with the rule, it does not belong here.
This keeps validate out of territory linters already cover well. Style conventions, naming rules, description requirements, and anything that needs a config file should go to your team's linter of choice.
Usage
$ oasdiff validate spec.yaml
spec.yaml:14:9 error parameter-name-required parameter name is required
spec.yaml:42:17 error schema-items-required type: array requires items in 3.0
2 changes: 2 error, 0 warning, 0 info
$ echo $?
1
Exit codes: 0 if no findings at error or warning severity, 1 otherwise.
Flags:
--format <fmt>: output format (text,yaml, orjson; defaulttext).--color <mode>: color mode for text output (auto,always,never; defaultauto). Matcheschangelog/breaking.
Default text output uses color highlighting per severity: error in red, warning in purple, info in cyan; rule IDs in yellow; HTTP method and path in green.
JSON / YAML output
Same shape as oasdiff changelog --format json|yaml. Numeric level matches the existing changelog and breaking-change conventions (1=info, 2=warning, 3=error).
[
{
"id": "schema-items-required",
"text": "type: array requires items in 3.0",
"level": 3,
"operation": "POST",
"path": "/users",
"section": "paths",
"source": {"file": "spec.yaml", "line": 22, "column": 17},
"fingerprint": "g7h8i9"
}
]
Listing the rules
oasdiff checks validate lists every rule ID and its message, parallel to oasdiff checks changelog.
$ oasdiff checks validate
Phase 1 coverage
Phase 1 wraps every validation check the underlying parser produces, mapped to descriptive, stable rule IDs. Categories:
- Required-field violations:
info.title,info.version,paths(3.0),jsonSchemaDialectURI,parameter.name,responsesnon-empty per operation, and others. - Mutually exclusive fields:
example.value+externalValue;license.url+identifier;schema.readOnly+writeOnly; and others. - Forbidden fields:
header.name,header.in, OAuth flow auth / token URLs at unexpected sites. - Either-or required: example must have
valueorexternalValue; link must haveoperationIdoroperationRef. - Schema items required:
type: arrayrequiresitems(3.0). - Schema both-forms exclusive:
additionalProperties,unevaluatedItems,unevaluatedPropertiescannot be both boolean and schema. - Exactly-one in content + schema: parameter / header must use
contentorschema, not both. - Server URL templates: balanced braces; every templated variable declared.
- Version mismatches: 3.1-only fields used in 3.0 specs.
- Webhook integrity: nil path items in
webhooksmap. - Structural baseline:
$refresolution,operationIduniqueness, path keys start with/,in: pathparameters required.
Phase 2 coverage (post-v1)
Native rules that the parser does not catch today. Starter set, each citing a specific spec clause:
Numeric range integrity
multipleOf > 0(JSON Schema §6.2.1)minimum ≤ maximumwhen both setexclusiveMinimum < exclusiveMaximum(3.1, both set)
String constraints
minLength ≤ maxLengthpatternis a valid Go (RE2) regexpatterndoes not use unsupported features (lookahead, backreferences)
Array constraints
minItems ≤ maxItemsminContains ≤ maxContains(3.1)contains/minContains/maxContains/prefixItems/unevaluatedItemsonly meaningful on arrays
Object constraints
minProperties ≤ maxPropertiesrequirednames not inproperties(and not covered bypatternPropertiesoradditionalProperties: true)discriminator.propertyNameinrequiredof everyoneOf/anyOfmemberdiscriminator.mappingvalues resolve to schemas in theoneOf/anyOfset
Composition
allOf/oneOf/anyOfarrays non-emptyenumnon-empty- If
constandenumboth set,constis inenum - All
enumvalues match the declaredtype
Companion GitHub Action
A new oasdiff/oasdiff-action/validate action variant is planned, mirroring the existing breaking and changelog variants. It runs the validator in CI and exits non-zero on errors. Tracked separately in oasdiff/oasdiff-action.
Rule-ID stability
Rule IDs are stable API from v1. New rules may be added in later releases; existing IDs are never renamed or repurposed. CI dashboards and external tooling can depend on them.
Status
Phase 1 implementation is gated on a new release of the underlying parser containing the typed validation errors (kin-openapi #1166 + #1180, both merged upstream 2026-05-09). Once a kin release tag is cut, Phase 1 ships immediately.
How to engage
- Comment with use cases or specific violations you'd like flagged that are missing from the Phase 1 / Phase 2 lists.
- File examples of real-world specs that trigger silent panics today (each one becomes a Phase 2 rule).
- Suggest rule IDs you'd want suppressed by default if they tend to over-fire.
- 主要语言
- Go
- 星标
- 1.4k
- 派生
- 109
- 平均合并
- 11 小时 5 分钟
- 30 天内合并 PR
- 32
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
oasdiff/oasdiff 的其他 Issue
-
`date` → `date-time` (and `time` → `date-time`) is classified as a widening, but a date is not a valid date-time可能已有人在做 @reuvenharrison 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 3/5 半天 新手友好度 68/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 75/100
维护者通常 1 天内回复
-
A required response property becoming `writeOnly` is reported at info, though it is no longer returned可能已有人在做 @reuvenharrison 今天认领。 未关闭
难度 3/5 半天 新手友好度 72/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 72/100
维护者通常 1 天内回复
相似的 Issue
-
agent-research-recommend agent-review-finding chore
难度 2/5 1-3 小时 新手友好度 78/100
jordansmall/spindrift#4821 · 1 条评论 ·
维护者通常 1 天内回复
-
area:web
难度 2/5 1-3 小时 新手友好度 82/100
praetorianer777/GoTome#178 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
oracle/go-oracledb#105 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复