|
1 | 1 | //===----------------------------------------------------------------------===//
|
2 |
| -// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. |
| 2 | +// Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. |
3 | 3 | //
|
4 | 4 | // Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | // you may not use this file except in compliance with the License.
|
|
31 | 31 | /// <https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object>
|
32 | 32 | open module org.openapis.v3.Schema
|
33 | 33 |
|
34 |
| -import "Schema.pkl" |
| 34 | +import "Extension.pkl" |
35 | 35 | import "Reference.pkl"
|
| 36 | +import "Schema.pkl" |
36 | 37 |
|
37 | 38 | /// The basic type of the value represented by this schema.
|
38 | 39 | ///
|
@@ -291,6 +292,15 @@ deprecated: Boolean?
|
291 | 292 | /// value can be used to contain the example with escaping where necessary.
|
292 | 293 | example: Any?
|
293 | 294 |
|
| 295 | +/// Custom properties starting with x- extend OpenAPI with additional information |
| 296 | +/// or functionality. |
| 297 | +/// |
| 298 | +/// This is a child property because Pkl modules cannot express both known names |
| 299 | +/// and arbitrary names. |
| 300 | +/// |
| 301 | +/// <https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions> |
| 302 | +hidden extensions: Mapping<Extension.Key, Any>? |
| 303 | + |
294 | 304 | /// Helps inform of alternative schemas.
|
295 | 305 | ///
|
296 | 306 | /// When request bodies or response payloads may be one of a number of different
|
@@ -367,16 +377,18 @@ class PropertySchema extends Schema {
|
367 | 377 | xml: Xml?
|
368 | 378 | }
|
369 | 379 |
|
370 |
| -hidden renderers: Mapping<String, ValueRenderer> = new { |
371 |
| - ["json"] = new JsonRenderer {} |
372 |
| - ["yaml"] = new YamlRenderer {} |
373 |
| - ["pcf"] = new PcfRenderer {} |
374 |
| -} |
375 |
| - |
376 | 380 | output {
|
377 | 381 | // It's pretty common to have OpenAPI written in YAML. Therefore, we support the YAML format too.
|
378 |
| - renderer = let (format = read?("prop:pkl.outputFormat") ?? "json") |
379 |
| - if (renderers.containsKey(format)) |
380 |
| - renderers[format] |
381 |
| - else throw("Unsupported output format: `\(format)`. Supported formats are `json`, `yaml` and `pcf`.") |
| 382 | + // noinspection TypeMismatch |
| 383 | + local const format: "json"|"yaml"|"pcf" = read?("prop:pkl.outputFormat") ?? "json" |
| 384 | + |
| 385 | + local const renderers: Mapping<String, ValueRenderer> = new { |
| 386 | + ["json"] = new JsonRenderer {} |
| 387 | + ["yaml"] = new YamlRenderer {} |
| 388 | + ["pcf"] = new PcfRenderer {} |
| 389 | + } |
| 390 | + |
| 391 | + renderer = (renderers[format]) { |
| 392 | + converters = Extension.converters |
| 393 | + } |
382 | 394 | }
|
0 commit comments