@@ -72,14 +72,25 @@ Options:
7272 --tokenUrl <tokenUrl> The tokenUrl for openIdConnect -> oauth2 transformation
7373 -d, --delete-examples-with-id If set, delete any JSON Schema examples that have an `id` property
7474 --oidc-to-oath2 <scopes> Convert openIdConnect security to oath2.
75+ --convertJsonComments If used, convert `$comment` in JSON schemas
76+ to `x-comment`. If omitted, delete
77+ all `$comment` in JSON schemas.
78+ (Use `--verbose` to log deletion
79+ to stdout)
7580 -s, --scopes <scopes> If set, this JSON/YAML file describes the OpenID scopes.
7681 This is an alias for --oidc-to-oath2
7782 -v, --verbose Verbose output
7883 -V, --version output the version number
7984 -h, --help display help for command
8085```
8186
82- The verbose mode logs the changes to standard error output stream.
87+ The verbose mode logs all changes to standard error output stream.
88+
89+ The tool returns a 0 status code upon success or a non-zero status code
90+ if it finds constructs that cannot be down-converted, such as
91+ using ` contentMediaType: application/octet-stream ` with a ` format `
92+ other than ` binary ` , or if a schema has ` contentEncoding: base64 `
93+ and has an existing ` format ` that is not already ` base64 ` .
8394
8495The tool only supports local file-based documents, not URLs.
8596Download such files to convert:
@@ -170,8 +181,8 @@ mySchema:
170181This also applies to the schema used in parameters or in `requestBody` objects
171182and in responses.
172183
173- **Note** This transformation is disabled by default because it breaks `openapi-generator` 5.4 in
174- cases where the referenced schema is an array.
184+ **Note** This transformation is disabled by default because it breaks
185+ ` openapi-generator ` 5.4 in cases where the referenced schema is an array.
175186It generates Typescript types for such cases as
176187
177188` ` ` typescript
@@ -223,7 +234,7 @@ components:
223234 const: '1.0.0'
224235` ` `
225236
226- becomes
237+ becomes
227238
228239` ` ` yaml
229240components:
@@ -235,7 +246,7 @@ components:
235246 - '1.0.0'
236247` ` `
237248
238- # ## Convert type arrays to nullable
249+ # ## ⤓ Convert type arrays to nullable
239250
240251If a schema has a type array of exactly two values, and one of them
241252is the string `'null'`, the type is converted to the non-null string item,
@@ -302,11 +313,11 @@ be possible (`properties`, `allOf` etc.)
302313
303314(Contributions welcome.)
304315
305- # ## Remove `unevaluatedProperties`
316+ # ## ⤓ Remove `unevaluatedProperties`
306317
307318The tool removes the `unevaluatedProperties` value, introduced in later
308319versions of JSON Schema,
309- as this is not supported in OAS 3.0 JSON Schema Draft 4
320+ as this is not supported in JSON Schema Draft 4
310321used in OAS 3.0.
311322
312323` ` ` yaml
@@ -331,14 +342,27 @@ becomes
331342 ...
332343` ` `
333344
334- # ## Rename `$comment` as `x-comment`
345+ The tool removes any `$id` or `$schema` keywords that may appear
346+ inside schema objects.
347+
348+ # ## ⤓ Convert `$comment` to `x-comment`
349+
350+ JSON Schema introduced `$comment` in schemas in 2020-12.
351+ Since OAS 3.0 uses JSON Schema Draft 4, and some tools
352+ will flag `$comment` as invalid, this tool removes these comments.
335353
336- The tool renames the `$comment` keyword in schema objects as `x-comment`
337- as `$comment` is not supported in OAS 3.0 JSON Schema Draft 4
338- used in OAS 3.0. and can cause problems with some tools.
339- ` x-comment` is more easily ignored since it does not start with `$`.
354+ An earlier version of the tool converted `$comment` to `x-comment`
355+ However, other tools which do not allow `$comment` may not not support
356+ ` x-comment` either.
357+
358+ Use the `--convert-schema-comments` CLI option or set
359+ ` convertSchemaComments` to `true`
360+ in the `Converter` constructor options
361+ to requst conversion of
362+ ` $comment` to `x-comment` rather than deleting `$comment`.
363+
364+ For example,
340365
341- For exmample,
342366` ` ` yaml
343367 Problems:
344368 title: Problems
@@ -365,16 +389,70 @@ becomes
365389 $ref : ' #/components/schemas/apiProblem'
366390` ` `
367391
368- ### Remove schema ` $id` and `$schema`
392+ ### Convert ` contentEncoding: base64` to `format: byte`
393+
394+ JSON Schema Draft 7 and later uses `contentEncoding` to specify
395+ [the encoding of non-JSON string content]
396+ (https://json-schema.org/understanding-json-schema/reference/non_json_data).
397+ Draft 4 supports `format : byte` for `Base64` encoded strings.
398+
399+ This tool converts `type : string` schemas as follows:
400+
401+ <!-- markdownlint-disable MD033 -->
402+ <table>
403+
404+ <tr>
405+ <th>OAS 3.1 schema</th>
406+ <th>OAS 3.0 schema</th>
407+ </tr>
408+ 2
409+ <tr>
410+ <td>
411+ <pre>
412+ type : string
413+ contentEncoding : base64
414+ </pre>
415+ </td>
416+ <td>
417+ <pre>
418+ type : string
419+ format : byte
420+ </pre>
421+ </td>
422+ </tr>
423+
424+ <tr>
425+ <td>
426+ <pre>
427+ type : string
428+ contentMediaType : ' application/octet-stream'
429+ </pre>
430+ </td>
431+ <td>
432+ <pre>
433+ type : string
434+ format : binary
435+ </pre>
436+ </td>
437+ </tr>
438+ </table>
369439
370- The tool removes any `$id` or `$schema` keywords that may appear
371- inside schema objects.
372440
373441# # Unsupported down conversions
374442
443+ Currently, the tool does not support the following situations.
444+ Contributions welcome!
445+
375446* `openapi-down-convert` does not convert `exclusiveMinimum` and `exclusiveMaximum`
376- as defined in JSON Schema 2012-12; these handled differently in JSON Schema Draft 4
377- used in OAS 3.0. Contributions welcome!
378- * Webhooks are not addressed. Contributions welcome!
447+ as defined in JSON Schema 2012-12; these handled differently in JSON Schema Draft 4
448+ used in OAS 3.0.
449+ * Webhooks are not addressed.
379450* The tool only supports self-contained documents. It does not follow or resolve
380- external `$ref` documents embedded in the source document.
451+ external `$ref` documents embedded in the source document.
452+ * Request body and response body `content` object transformations, such as
453+ reversing `content : { 'application/octet-stream': {} }` as
454+ described in [Migrating from OpenAPI 3.0 to 3.1.0](https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0)
455+ * Converting other `contentEncoding` values (`7bit`, `8bit`, `binary`,
456+ `quoted-printable`, `base16`, `base32`) (Note : ` contentEncoding: base64` is supported by
457+ converting to `format : byte` as listed above.)
458+ * Converting `contentMediaType: 'type/subtype` to `media: { type: 'type/subtype'}` for non-JSON data.
0 commit comments