From 888c042d3eb1b2efdcf04c4c1d1108eb446a40b5 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Fri, 29 Mar 2024 16:14:21 -0700 Subject: [PATCH] feat: add example to $schema links --- transforms.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/transforms.go b/transforms.go index 13a21f4e..882d35f4 100644 --- a/transforms.go +++ b/transforms.go @@ -56,11 +56,22 @@ func (t *SchemaLinkTransformer) addSchemaField(oapi *OpenAPI, content *MediaType return true } + // Create an example so it's easier for users to find the schema URL when + // they are reading the documentation. + server := "https://example.com" + for _, s := range oapi.Servers { + if s.URL != "" { + server = s.URL + break + } + } + schema.Properties["$schema"] = &Schema{ Type: TypeString, Format: "uri", Description: "A URL to the JSON Schema for this object.", ReadOnly: true, + Examples: []any{server + t.schemasPath + "/" + path.Base(content.Schema.Ref) + ".json"}, } return false }