Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

convertTo 3.1 drops nullable on allOf schemas (follow-up to #172)

未关闭
#239 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
api

调研方向

Start at the openapiConvertVersion entry point and reproduce the issue with the provided 3.0.3 document, comparing the allOf and oneOf conversions. Done means nullable allOf schemas preserve null acceptance through an anyOf-style representation while the existing oneOf behavior remains correct.

由索引模型根据 Issue 内容生成。

描述

Converting 3.0 → 3.1 with convertTo: '3.1' drops nullable: true when the schema has allOf and no type. The converted schema then rejects null, which the original allowed. #172 fixed this for anyOf and oneOf, but allOf is still affected.

The pattern is common in GitHub's REST API description. For example, label.archived_by is { nullable: true, allOf: [{ $ref: '#/components/schemas/simple-user' }] }.

Reproduction (openapi-format 1.33.7, Node 24):

import { openapiConvertVersion } from 'openapi-format';

const doc = {
  openapi: '3.0.3',
  info: { title: 't', version: '1' },
  paths: {},
  components: {
    schemas: {
      User: { type: 'object', properties: { login: { type: 'string' } } },
      Label: {
        type: 'object',
        properties: {
          archived_by: { nullable: true, allOf: [{ $ref: '#/components/schemas/User' }] },
          milestone: { nullable: true, oneOf: [{ type: 'string' }, { type: 'integer' }] },
        },
      },
    },
  },
};

const { data } = await openapiConvertVersion(doc, { convertTo: '3.1' });
console.log(JSON.stringify(data.components.schemas.Label.properties, null, 2));

Actual:

{
  "archived_by": { "allOf": [{ "$ref": "#/components/schemas/User" }] },
  "milestone": { "oneOf": [{ "type": "string" }, { "type": "integer" }, { "type": "null" }] }
}

milestone (oneOf) is converted correctly. archived_by (allOf) loses nullable entirely.

Expected, for example:

"archived_by": {
  "anyOf": [
    { "allOf": [{ "$ref": "#/components/schemas/User" }] },
    { "type": "null" }
  ]
}

Adding { "type": "null" } to the allOf list itself wouldn't work, since a value can't match both a User and null. The null has to sit alongside the allOf, for example in an anyOf.

主要语言
JavaScript
星标
177
派生
30
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

thim81/openapi-format 的其他 Issue

查看 thim81/openapi-format 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。