From 92f87940dbe80e40a4407314b594496d992511fa Mon Sep 17 00:00:00 2001 From: "Bruce W. Herr II" Date: Thu, 19 Dec 2024 10:16:21 -0500 Subject: [PATCH] Update grlc specs to add examples for parameters based on default where appropriate. --- src/library/grlc/grlc-spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/library/grlc/grlc-spec.js b/src/library/grlc/grlc-spec.js index 0b47671..36403b5 100644 --- a/src/library/grlc/grlc-spec.js +++ b/src/library/grlc/grlc-spec.js @@ -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; + } + } + } + } + } +}