Skip to content

Commit

Permalink
Improve respec-oas with support for array types in oneOf.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 authored and msporny committed Oct 22, 2024
1 parent ced5f7e commit 57b6b53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions components/Credential.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
9 changes: 7 additions & 2 deletions respec-oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -307,7 +312,7 @@ function renderJsonSchemaObject(schema) {
}
} else {
objectRendering += 'an object of the following form: <dl>';
for(property in schema.properties) {
for(const property in schema.properties) {
const value = schema.properties[property];
objectRendering += renderJsonSchemaProperty(property, value);
}
Expand Down

0 comments on commit 57b6b53

Please sign in to comment.