In split/multi-file projects - Option for referencing via the root document
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript, openapi
調査の方向性
No implementation files or tests are named. Start by locating the split/multi-file reference generation and CLI option entry points, then compare them with the attached current and proposed examples. Done should include an option that consistently emits root-file section references, including the unresolved nested subsection case, with coverage for the documented examples.
索引モデルが issue の本文から書いたものです。
説明
Enhancement request for split/multi-file process. Only reference the root YAML file and then reference by section of the root file.
For example, a split schema file currently references another schema file by $ref: "schemas/SchemaName.yaml". My request is to allow a CLI flag/option to change these references to look like $ref: "../../root.yaml#components/schemas/SchemaName" where the reference looks at the root YAML file and specifies the section from that file.
Reason for request:
One use case I encountered is maintaining multiple versions (e.g. 0.1.0 and 0.2.0) of a schema with the same name. Differentiating between the two in the API is outside the scope of this issue. The best way to maintain concurrent versions is to utilize OpenAPI's oneOf to reference multiple possible schemas.
Example code snippet:
components:
schemas:
TheSchema:
oneOf:
- $ref: "components/schemas/TheSchema_0.1.0.yaml"
- $ref: "components/schemas/TheSchema_0.2.0.yaml"
This versioning occurs AFTER utilizing openapi-format to split an OpenAPI file. However, there are two reasons this change is convenient:
- It keeps the file references simple
- only one file reference all the time, only need to track the relative depth
- section references within the root YAML look the same as the original YAML file (plus the prepended root YAML file path, of course)
- Adding multiple version references requires only two things:
- the root YAML be updated using
oneOf(see example above) - the addition of the schema files
- all references to the multiple schema versions propagate downstream to any schemas/paths/etc which reference it, without any other changes
- the root YAML be updated using
Current behavior:
The root OpenAPI file references other sections via path to the split files. However, whenever something is referenced (e.g a schema referencing another schema, a path referencing a schema, etc.) outside of the root file, it references the file directly rather than the root YAML and corresponding section/item. Below is a brief snippet example of a root YAML, schema, and path for that schema:
# root.yaml
openapi: 3.0.3
info:
title: splitting example
version: 0.0.1
paths:
/some-schemas:
$ref: "paths/someschemas.yaml"
components:
schemas:
SomeSchema:
$ref: "components/schemas/SomeSchema.yaml"
# components/schemas/SomeSchema.yaml
# The file AnotherSchema.yaml was not included here to keep the examples short.
description: "SomeSchema description"
required:
- someSchemaProperty
properties:
someSchemaProperty:
description: "someSchemaProperty description"
type: string
nullable: false
anotherSchema:
allOf:
- $ref: "schemas/AnotherSchema.yaml"
- nullable: false
- description: "AnotherSchema used in SomeSchema"
# paths/someschemas.yaml
post:
tags:
- SomeSchema
summary: "SomeSchema path summary"
description: "SomeSchema path description"
operationId: post-some-schema
parameters: []
requestBody:
description: "SomeSchema path request body"
content:
application/json:
schema:
$ref: "../components/schemas/SomeSchema.yaml"
responses:
"200":
description: "SomeSchema path response"
content:
application/json:
schema:
$ref: "../components/schemas/SomeSchema.yaml"
Proposed behavior:
Keep the root YAML the same. Within other split files, refer back to the root YAML file and then refer to the section instead. Example of the change mirrors the above examples, but with $ref path changes:
# root.yaml
openapi: 3.0.3
info:
title: splitting example
version: 0.0.1
paths:
/some-schemas:
$ref: "paths/someschemas.yaml"
components:
schemas:
SomeSchema:
$ref: "components/schemas/SomeSchema.yaml"
# components/schemas/SomeSchema.yaml
# The file AnotherSchema.yaml was not included here to keep the examples short.
description: "SomeSchema description"
required:
- someSchemaProperty
properties:
someSchemaProperty:
description: "someSchemaProperty description"
type: string
nullable: false
anotherSchema:
allOf:
- $ref: "../../root.yaml#components/schemas/AnotherSchema"
- nullable: false
- description: "AnotherSchema used in SomeSchema"
# paths/someschemas.yaml
post:
tags:
- SomeSchema
summary: "SomeSchema path summary"
description: "SomeSchema path description"
operationId: post-some-schema
parameters: []
requestBody:
description: "SomeSchema path request body"
content:
application/json:
schema:
$ref: "../root.yaml#components/schemas/SomeSchema"
responses:
"200":
description: "SomeSchema path response"
content:
application/json:
schema:
$ref: "../root.yaml#components/schemas/SomeSchema"
Final notes:
I attached two zip files with a full working example of the current and proposed behavior. I thought it may help to see the full file/path structure. I tested both of them and they both validate and render correctly for me.
The only issue that I can think of is when referencing a sub-section of a schema. For example, if the property from schema A references a property from Schema B. The reference $ref: "schemas/AnotherSchema.yaml#properties/aProperty" works correctly while using the proposed method reference $ref: "../../root.yaml#components/schemas/AnotherSchema/properties/aProperty" does not. I am not sure if there is a workaround at the moment.
current-openapi-format-split-example.zip
proposed-openapi-format-split-example.zip
- 主要言語
- JavaScript
- スター
- 177
- フォーク
- 30
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
thim81/openapi-format のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
thim81/openapi-format#238 · コメント 1 件 · 担当者 1 名 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
thim81/openapi-format#239 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
thim81/openapi-format#237 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
thim81/openapi-format#232 · コメント 3 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
thim81/openapi-format#196 · コメント 3 件 ·
thim81/openapi-format の issue をすべて見る
似ている issue
-
Mend: dependency security vulnerability untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
opensearch-project/security-dashboards-plugin#2543 ·
メンテナーはふだん 1 日以内に返信
-
[quality] refresh-radar-reports.yml runs on ubuntu-latest while every other job pins ubuntu-24.04オープンagent/quality hive/hosted-available-lke648397-260827-5n31 quality testing
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
godotengine/godot-website#1432 ·
-
Add: Mooz Retroオープンchannels:add check:passed
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信