Skip to content

Commit

Permalink
Update grlc specs to add examples for parameters based on default whe…
Browse files Browse the repository at this point in the history
…re appropriate.
  • Loading branch information
bherr2 committed Dec 19, 2024
1 parent 7e22601 commit 92f8794
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/library/grlc/grlc-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,22 @@ export async function getGrlcSpec(name) {
delete spec.next_commit;
delete spec.prov;

// Find parameter defaults and set them as examples where appropriate to allow for better user experience
setExampleFromDefault(spec);

return spec;
}

function setExampleFromDefault(spec) {
for (const pathSpec of Object.values(spec.paths ?? {})) {
for (const methodSpec of Object.values(pathSpec)) {
for (const paramSpec of methodSpec.parameters ?? []) {
if (paramSpec && paramSpec.name !== 'endpoint') {
if (paramSpec.schema?.default) {
paramSpec.schema.example = paramSpec.schema.default;
}
}
}
}
}
}

0 comments on commit 92f8794

Please # to comment.