Skip to content

Commit

Permalink
Merge pull request #343 from danielgtaylor/schema-link-example
Browse files Browse the repository at this point in the history
feat: add example to $schema links
  • Loading branch information
danielgtaylor committed Mar 29, 2024
2 parents a741488 + 888c042 commit 10e15d1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 10e15d1

Please sign in to comment.