-
Notifications
You must be signed in to change notification settings - Fork 16
Fix regressions in generated documentation #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vladimir-rangelov
merged 7 commits into
next-bidirectional
from
fix/regressions_in_generated_documentation
Oct 8, 2025
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1519d8c
fix: Property event is generated as a getter
vladimir-rangelov 616b9ef
fix: Generate the missing external schema documents
vladimir-rangelov d5b7987
fix: Remove all schemas in the generated documentation that are not d…
vladimir-rangelov b5935fd
refactor: Completely rewrite removeUnusedSchemas and put it in a sepa…
vladimir-rangelov f9a3b33
refactor: Rename test to test_sdk, as we want to keep test for unit t…
vladimir-rangelov 3fe18a3
test: Add unit tests for removeUnusedSchemas
vladimir-rangelov f79c89b
fix: Review comments
vladimir-rangelov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * ${method.summary} | ||
| * | ||
| * @param {'${event.name}'} event | ||
| * @param {Function} callback | ||
| ${if.deprecated} * @deprecated ${method.deprecation} | ||
| ${end.if.deprecated} */ | ||
| function listen(event: '${event.name}'${if.context}, ${event.signature.params}${end.if.context}, callback: (data: ${event.result.type}) => void): Promise<number> | ||
|
|
||
| /** | ||
| * ${method.summary} | ||
| * When using `once` the callback method will only fire once, and then disconnect your listener | ||
| * | ||
| * @param {'${event.name}'} event | ||
| * @param {Function} callback | ||
| ${if.deprecated} * @deprecated ${method.deprecation} | ||
| ${end.if.deprecated} */ | ||
| function once(event: '${event.name}'${if.context}, ${event.signature.params}${end.if.context}, callback: (data: ${event.result.type}) => void): Promise<number> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| registerEvents('${info.title}', ${events.array}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // ${method.name} is accessed via listen('${event.name}, ...) | ||
| ${if.context} | ||
| registerEventContext('${info.title}', '${event.name}', ${method.context.array})${end.if.context} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,4 @@ Response: | |
|
|
||
| ```${example.langcode} | ||
| {"jsonrpc":"2.0","id":1,"result":null} | ||
| ``` | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| registerEvents('${info.title}', ${events.array}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| Parameters: | ||
|
|
||
| | Param | Type | Required | Description | | ||
| | Param | Type | Required | Description | | ||
| | ---------------------- | -------------------- | ------------------------ | ----------------------- | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -587,4 +587,5 @@ export { | |
| dereferenceAndMergeAllOfs, | ||
| getReferencedSchema, | ||
| getAllValuesForName, | ||
| dereferenceSchema | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /* | ||
| * If not stated otherwise in this file or this component's LICENSE file the | ||
| * following copyright and licenses apply: | ||
| * | ||
| * Copyright 2025 Sky UK | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
|
|
||
| // utilities for cleaning unused schemas | ||
|
|
||
| /** | ||
| * Recursively find all $ref values in an object. | ||
| * @param {object} obj | ||
| * @param {Set<string>} refs | ||
| * @returns {Set<string>} | ||
| */ | ||
| function findRefs(obj, refs = new Set()) { | ||
| if (!obj || typeof obj !== "object") return refs; | ||
| if (Array.isArray(obj)) { | ||
| obj.forEach(item => findRefs(item, refs)); | ||
| } else { | ||
| for (const [key, value] of Object.entries(obj)) { | ||
| if (key === "$ref" && typeof value === "string") { | ||
| refs.add(value); | ||
| } else { | ||
| findRefs(value, refs); | ||
| } | ||
| } | ||
| } | ||
| return refs; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve a $ref path like "#/components/schemas/EventObject" | ||
| * inside a given object. | ||
| * @param {string} ref | ||
| * @param {object} root | ||
| * @returns {object|null} | ||
| */ | ||
| function resolveRef(ref, root) { | ||
| if (!ref.startsWith("#/")) return null; | ||
| const pathParts = ref.slice(2).split("/"); | ||
| let target = root; | ||
| for (const part of pathParts) { | ||
| if (target && typeof target === "object") target = target[part]; | ||
| else return null; | ||
| } | ||
| return target; | ||
| } | ||
|
|
||
| /** | ||
| * Collect all transitive references from an initial set of refs. | ||
| * @param {Set<string>} refSet | ||
| * @param {object} root | ||
| * @param {Set<string>} referenced | ||
| */ | ||
| function collectRefs(refSet, root, referenced = new Set()) { | ||
| const queue = [...refSet]; | ||
| while (queue.length) { | ||
| const ref = queue.pop(); | ||
| if (referenced.has(ref)) continue; | ||
| referenced.add(ref); | ||
| const target = resolveRef(ref, root); | ||
| if (target) { | ||
| const newRefs = findRefs(target); | ||
| for (const newRef of newRefs) { | ||
| if (!referenced.has(newRef)) queue.push(newRef); | ||
| } | ||
| } | ||
| } | ||
| return referenced; | ||
| } | ||
|
|
||
| /** | ||
| * Clean unused schemas from an OpenRPC-like JSON definition. | ||
| * @param {object} spec | ||
| * @returns {object} cleaned deep-cloned JSON object | ||
| */ | ||
| function removeUnusedSchemas(spec) { | ||
| const clone = | ||
| typeof structuredClone === "function" | ||
| ? structuredClone(spec) | ||
| : JSON.parse(JSON.stringify(spec)); | ||
|
|
||
| const referenced = new Set(); | ||
| const initialRefs = findRefs(clone.methods); | ||
| collectRefs(initialRefs, clone, referenced); | ||
|
|
||
| // Prune components/schemas | ||
| if (clone.components?.schemas) { | ||
| for (const key of Object.keys(clone.components.schemas)) { | ||
| const refPath = `#/components/schemas/${key}`; | ||
| if (!referenced.has(refPath)) delete clone.components.schemas[key]; | ||
| } | ||
| } | ||
|
|
||
| // Prune x-schemas | ||
| if (clone["x-schemas"]) { | ||
| for (const nsKey of Object.keys(clone["x-schemas"])) { | ||
| const ns = clone["x-schemas"][nsKey]; | ||
| for (const schemaKey of Object.keys(ns)) { | ||
| if (schemaKey === "uri") continue; | ||
| const refPath = `#/x-schemas/${nsKey}/${schemaKey}`; | ||
| if (!referenced.has(refPath)) delete ns[schemaKey]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return clone; | ||
| } | ||
|
|
||
| export { | ||
| findRefs, | ||
| collectRefs, | ||
| resolveRef, | ||
| removeUnusedSchemas | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, comment on why there is a 4 — or even better, extract it as a const. It’ll make our lives much happier when inspecting the code later 😉
applies to line 299 as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.