Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/openrpc/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const run = async ({
let appApiOpenRpc = appApi && await readJson(template)
let mergedOpenRpc = await readJson(template)

//remove rpc.discover method if it exists as it got duplicated when splitting out platform & app APIs
mergedOpenRpc.methods = mergedOpenRpc.methods.filter(m => m.name !== 'rpc.discover')

const sharedSchemaList = schemas ? (await Promise.all(schemas.map(d => readDir(d, { recursive: true })))).flat() : []
const sharedSchemas = await readFiles(sharedSchemaList)
var openRpcVersion = '';
Expand Down
59 changes: 34 additions & 25 deletions src/shared/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,38 +1857,47 @@ const addExternalSchemas = (json, sharedSchemas) => {

return json
}
// TODO: make this recursive, and check for group vs schema
const removeUnusedSchemas = (json) => {
const schema = JSON.parse(JSON.stringify(json))

const recurse = (schema, path) => {
let deleted = false
Object.keys(schema).forEach(name => {
if (isSchema(schema[name])) {
const used = isDefinitionReferencedBySchema(path + '/' + name, json)

if (!used) {
delete schema[name]
deleted = true
const removeUnusedSchemas = (json) => {
let deleted = false
function removeUnusedSchemasClosure(json) {
const schema = JSON.parse(JSON.stringify(json))

const recurse = (schema, path) => {

Object.keys(schema).forEach(name => {
if (isSchema(schema[name])) {
const used = isDefinitionReferencedBySchema(path + '/' + name, json)

if (!used) {
delete schema[name]
deleted = true
}
else {
}
}
else {
else if (typeof schema[name] === 'object') {
deleted = deleted || recurse(schema[name], path + '/' + name)
}
}
else if (typeof schema[name] === 'object') {
deleted = deleted || recurse(schema[name], path + '/' + name)
}
})
return deleted
}
})
return deleted
}

if (schema.components.schemas) {
while(recurse(schema.components.schemas, '#/components/schemas')) {}
}
if (schema.components.schemas) {
deleted = deleted || recurse(schema.components.schemas, '#/components/schemas')
}

if (schema['x-schemas']) {
while(recurse(schema['x-schemas'], '#/x-schemas')) {}
if (schema['x-schemas']) {
deleted = deleted || recurse(schema['x-schemas'], '#/x-schemas')
}
return schema
}

let schema = removeUnusedSchemasClosure(json)
while(deleted) {
deleted = false
schema = removeUnusedSchemasClosure(schema)
}
return schema
}

Expand Down