forked from smithy-lang/smithy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes smithy-lang#2400. When a member targets a structure, it becomes a schema reference when converted to JSON Schema. Previously, we didn't add member docs to the converted object, possibly because earlier versions of open api or JSON Schema did not support it. Reading through [this issue](OAI/OpenAPI-Specification#1514) the [OAI spec](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#reference-object), and the [JSON Schema Spec](https://json-schema.org/draft/2020-12/json-schema-core#section-8.2.3), it seems that OpenAPI 3.1 and JSON Schema 2020-12 support the `description` property alongside `$ref`. I wasn't able to find anything about whether it is supported in [JSON Schema 07](https://json-schema.org/draft-07/json-schema-release-notes). This commit adds a new config option, `addReferenceDescriptions` that will add the `description` property alongside `$ref` when the member has documentation. I made it opt-in through the config option so we don't cause any existing documentation to be changed unexpectedly.
- Loading branch information
1 parent
7813acb
commit c1ff12b
Showing
9 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...src/test/resources/software/amazon/smithy/jsonschema/member-documentation.jsonschema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"definitions": { | ||
"Foo": { | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"type": "string", | ||
"description": "simple docs" | ||
}, | ||
"bar": { | ||
"$ref": "#/definitions/Bar", | ||
"description": "structure docs" | ||
} | ||
} | ||
}, | ||
"Bar": { | ||
"type": "object" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...onschema/src/test/resources/software/amazon/smithy/jsonschema/member-documentation.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
$version: "2.0" | ||
|
||
namespace smithy.example | ||
|
||
structure Foo { | ||
/// simple docs | ||
foo: String | ||
|
||
/// structure docs | ||
bar: Bar | ||
} | ||
|
||
structure Bar {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...sources/software/amazon/smithy/openapi/fromsmithy/documentation-test-members.openapi.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "MyDocs", | ||
"version": "2018-01-01", | ||
"description": "Service" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"description": "Operation", | ||
"operationId": "MyDocsOperation", | ||
"responses": { | ||
"200": { | ||
"description": "MyDocsOperation 200 response", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/MyDocsOperationResponseContent" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"MyDocsOperationResponseContent": { | ||
"type": "object", | ||
"description": "Output", | ||
"properties": { | ||
"foo": { | ||
"type": "string", | ||
"description": "foo member." | ||
}, | ||
"nested": { | ||
"$ref": "#/components/schemas/Nested", | ||
"description": "nested member." | ||
} | ||
} | ||
}, | ||
"Nested": { | ||
"type": "object", | ||
"description": "Nested", | ||
"properties": { | ||
"baz": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...est/resources/software/amazon/smithy/openapi/fromsmithy/documentation-test-members.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
$version: "2.0" | ||
|
||
namespace smithy.example | ||
|
||
/// Service | ||
@aws.protocols#restJson1 | ||
service MyDocs { | ||
version: "2018-01-01", | ||
operations: [MyDocsOperation] | ||
} | ||
|
||
/// Operation | ||
@http(method: "GET", uri: "/") | ||
@readonly | ||
operation MyDocsOperation { | ||
output: Output | ||
} | ||
|
||
/// Output | ||
structure Output { | ||
/// foo member. | ||
foo: String, | ||
|
||
/// nested member. | ||
nested: Nested, | ||
} | ||
|
||
/// Nested | ||
structure Nested { | ||
baz: String, | ||
} |