diff --git a/README.md b/README.md index f7a3b49..3e06a39 100644 --- a/README.md +++ b/README.md @@ -303,10 +303,27 @@ Links to external documentation. ```yaml # __externalDocs.yaml externalDocs: + +# docs.yaml description: DummyJSON Documentation url: https://dummyjson.com/docs ``` +The `externalDocs` field provides links to additional documentation outside the API spec. It can be used at: +- **Global level** (as shown above) - links to overall API documentation +- **Operation level** - links to specific endpoint guides + +Tools like Swagger UI render these links prominently for easy access to tutorials, guides, and examples. + +**Try it:** +```bash +# View the external documentation +curl https://dummyjson.com/docs + +# Or open in browser +open https://dummyjson.com/docs +``` + ## Usage ```swift diff --git a/Sources/YAMLMerger/YAMLMerger.swift b/Sources/YAMLMerger/YAMLMerger.swift index 5a32d5d..9efee68 100644 --- a/Sources/YAMLMerger/YAMLMerger.swift +++ b/Sources/YAMLMerger/YAMLMerger.swift @@ -33,7 +33,14 @@ public struct YAMLMerger { } private func cleanedContent(_ text: String) -> String { - let regex = try! NSRegularExpression(pattern: "(\\n\\s*){2,}", options: []) + let pattern = "(\\n\\s*){2,}" + let regex: NSRegularExpression + do { + regex = try NSRegularExpression(pattern: pattern, options: []) + } catch { + // If the regex pattern fails to compile, return the original text unchanged. + return text + } let range = NSRange(location: 0, length: text.utf16.count) return regex.stringByReplacingMatches(in: text, options: [], range: range, withTemplate: "\n\n") } @@ -53,7 +60,7 @@ public struct YAMLMerger { if !isFirstFile { output += "\n" // only between files } - output += content + output += cleanedContent(content) isFirstFile = false } } diff --git a/Tests/YAMLMergerTests/CombinedSpec.yaml b/Tests/YAMLMergerTests/CombinedSpec.yaml index 63ea39b..1063cc3 100644 --- a/Tests/YAMLMergerTests/CombinedSpec.yaml +++ b/Tests/YAMLMergerTests/CombinedSpec.yaml @@ -482,8 +482,8 @@ webhooks: description: Webhook received successfully '400': description: Bad request - -schemas: +components: + schemas: AuthResponse: diff --git a/Tests/YAMLMergerTests/Schema/01_Info/.gitkeep b/Tests/YAMLMergerTests/Schema/01_Info/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Tests/YAMLMergerTests/Schema/01_Info/api-info.yaml b/Tests/YAMLMergerTests/Schema/01_Info/api-info.yaml new file mode 100644 index 0000000..aeaa6d9 --- /dev/null +++ b/Tests/YAMLMergerTests/Schema/01_Info/api-info.yaml @@ -0,0 +1,9 @@ + title: OpenAPI Generation Demo + version: 1.0.0 + description: Demonstration of OpenAPI specification generation using YAMLMerger + contact: + name: API Support + email: support@example.com + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html diff --git a/Tests/YAMLMergerTests/Schema/08_ExternalDocs/docs.yaml b/Tests/YAMLMergerTests/Schema/08_ExternalDocs/docs.yaml new file mode 100644 index 0000000..27f7f3a --- /dev/null +++ b/Tests/YAMLMergerTests/Schema/08_ExternalDocs/docs.yaml @@ -0,0 +1,2 @@ + description: DummyJSON Documentation + url: https://dummyjson.com/docs