OpenAPI/AsyncAPI detection matches `"openapi":`/`asyncapi:` keys inside JSON Schemas that describe OpenAPI documents, and redocly.yaml's theme section

未關閉
#272 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
半天
新手友好度
65/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
openapi, python
領域
devtools

研究方向

The detection regex is at project_validator/ecosystems/openapi.py line 50, and REDOCLY_SETTINGS is near line 170 of the same file. Start by reading how the OpenAPI profile chooses which files to scan, then run the repro from the issue (a JSON Schema with a nested openapi property, and a redocly.yaml with a top-level openapi: key). Done means both files are no longer treated as API descriptions, and real openapi.yaml files still pass.

由索引模型根據 Issue 內容生成。

描述

^\s{0,4}"(?:openapi|swagger)": matches a property key in SchemaStore's openapi-3.X.json, asyncapi's definitions/*/asyncapi.json and OAI's _archive_/schemas/v2.0/schema.json (JSON Schemas about OpenAPI), so schema repositories are judged as API-description projects and FAIL schema-declared ("5 OpenAPI files do not declare their version"); Redocly's redocly.yaml has a top-level openapi: theme section and FAILs "no info.version". An OpenAPI document has openapi: "3.x" as a string value (or swagger: "2.0") and info:; a schema has $schema/type/properties.

Evidence from the corpus audit

SchemaStore/schemastore, asyncapi/spec-json-schemas, OAI/OpenAPI-Specification / schema-declared (and detection)
  • kind: FALSE_POSITIVE
  • actual: FAIL: OpenAPI/AsyncAPI: 5 OpenAPI files do not declare their version (openapi) and info.version
    (SchemaStore); OpenAPI/AsyncAPI: 14 AsyncAPI files do not declare their version (asyncapi) and info.version
    (spec-json-schemas); OpenAPI/AsyncAPI: 1 OpenAPI file does not declare its version … _archive_/schemas/v2.0/schema.json: no openapi (OAI)
  • expected: the files are JSON Schemas that describe OpenAPI/AsyncAPI documents (or a Kustomization), not
    descriptions; they should not be found by the OpenAPI/AsyncAPI profile at all, and SchemaStore and
    spec-json-schemas should not be "OpenAPI/AsyncAPI" projects (which also yields their static-analysis,
    schema-validation, schema-compatibility and schema-examples OpenAPI FAIL/WARN lines).
  • evidence: project_validator/ecosystems/openapi.py:50:
    OPENAPI: re.compile(r"^(?:openapi|swagger)\s*:|^\s{0,4}\"(?:openapi|swagger)\"\s*:", re.MULTILINE) matches a
    property key indented by 4 spaces inside "properties" or "required".
    SchemaStore src/schemas/json/openapi-3.X.json:2: "$schema": "https://json-schema.org/draft/2020-12/schema",
    and :8: "openapi": {; src/schemas/json/grpc-api-gateway.json:9: "openapi": {;
    src/test/kustomization/openapi.json:4: "openapi": { (a Kustomization).
    spec-json-schemas definitions/1.0.0/asyncapi.json:3: "$schema": "http://json-schema.org/draft-04/schema#",
    and :18: "asyncapi": {.
    OAI _archive_/schemas/v2.0/schema.json:3: "$schema": "http://json-schema.org/draft-04/schema#", and :18:
    "swagger": {.
  • repro: a file openapi-schema.json with {"$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {\n "openapi": {"type": "string"}}}; the project is detected as OpenAPI and the file fails
    schema-declared with "no openapi" and "no info.version". A fix is to require the key at the top level (parse the
    head, or at most 2 spaces of indentation and not inside properties), or to exclude files that are JSON Schemas.
  • confidence: high
Redocly/openapi-starter / schema-declared
  • kind: FALSE_POSITIVE
  • actual: FAIL: 1 OpenAPI file does not declare its version (openapi) and info.version / redocly.yaml: no info.version
  • expected: PASS: redocly.yaml is the Redocly CLI configuration; its top-level openapi: key is Redocly's
    documentation-theme section, not a specification version. The one real description, openapi/openapi.yaml,
    declares both.
  • evidence: redocly.yaml:1: # See https://redocly.com/docs/cli/configuration/ for more information.;
    redocly.yaml:2-4: apis: / sample@v1: / root: openapi/openapi.yaml; redocly.yaml:11: openapi:;
    openapi/openapi.yaml:1: openapi: 3.1.0, :7: version: 1.0.0. The same regex as above
    (project_validator/ecosystems/openapi.py:50) matches openapi: at column 0 regardless of its value.
  • repro: redocly.yaml with apis: {a: {root: openapi.yaml}}\nopenapi:\n codeSamples: {} next to a valid
    openapi.yaml. A fix is to exclude the known Redocly config names (REDOCLY_SETTINGS already lists them,
    openapi.py:170) and/or require the key's value to look like a version (openapi: 3.x, swagger: "2.0").
  • confidence: high

Found by the regression-corpus audit (235 real repositories, one or more per ecosystem profile; corpus and expected results in corpus/). Evidence is quoted from the audited checkouts at the commits pinned in corpus/projects.toml; <checkouts>/<owner>__<repo> is such a checkout.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

主要語言
Python
星號
4
分支
1
平均合併
10 小時 41 分鐘
30 天內合併 PR
79

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

cpp-best-practices/project_validator 的其他 Issue

查看 cpp-best-practices/project_validator 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。