From 57b6b533efde1ade235ccd8d10cb1b4e5d10bb8a Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 25 Sep 2024 17:20:38 -0400 Subject: [PATCH] Improve respec-oas with support for array types in oneOf. --- components/Credential.yml | 3 +++ respec-oas.js | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/components/Credential.yml b/components/Credential.yml index f6a4711..fab6ed5 100644 --- a/components/Credential.yml +++ b/components/Credential.yml @@ -90,10 +90,13 @@ components: type: object description: The subject "proof": + type: object description: An optional proof for credentials that are secured using proof sets or chains. oneOf: - type: object - type: array + items: + type: object example: { "@context": diff --git a/respec-oas.js b/respec-oas.js index 61d33a2..eec80da 100644 --- a/respec-oas.js +++ b/respec-oas.js @@ -285,11 +285,16 @@ function renderJsonSchemaObject(schema) { } else if(schema.oneOf) { objectRendering += ' either '; let itemCount = 0; - for(item of schema.oneOf) { + for(const item of schema.oneOf) { if(item.type === 'string') { objectRendering += 'a string'; } else if(item.type === 'object') { objectRendering += renderJsonSchemaObject(item); + } else if(item.type === 'array') { + objectRendering += 'an array'; + if(item.items) { + objectRendering += ` of ${item.items.type}(s)`; + } } itemCount += 1; @@ -307,7 +312,7 @@ function renderJsonSchemaObject(schema) { } } else { objectRendering += 'an object of the following form:
'; - for(property in schema.properties) { + for(const property in schema.properties) { const value = schema.properties[property]; objectRendering += renderJsonSchemaProperty(property, value); }