-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support serializing traits into specification extensions in OpenAPI (#…
…1609) ## `smithy.openapi#specificationExtension` Adds a meta trait `smithy.openapi#specificationExtension` that can be used to annotate traits to indicate they should be serialized into specification extension (`x-*`) properties when converting to OpenAPI. This is supported on shapes, operations, and services. By default the extension will be named by the shape ID replacing `#` & `.` with `-` prefixed with `x-`, otherwise the extension can be specified using the `as` property. A new package `smithy-openapi-traits` is introduced to contain the `smithy.openapi#specificationExtension` trait. ## `JsonSchemaMapper` and `JsonSchemaShapeVisitor` BREAKING CHANGE: Technically, `JsonSchemaMapper` has a breaking change from a functional interface to a normal interface, but we are anticipating customers are not using `JsonSchemaMapper` as a functional interface since it was not annotated with `@FunctionalInterface`. `JsonSchemaMapper` is updated to use `updateSchema(JsonSchemaMapperContext, Schema.Builder)` in `JsonSchemaShapeVisitor`, which will call the existing `updateSchema(Shape, Schema.Builder, JsonSchemaConfig)` by default when not implemented for backwards compatibility. ## `smithy-openapi` Support is added for `smithy.openapi#specificationExtension` by implementing `SpecificationExtensionsMapper` for operations and services and updating `OpenApiJsonSchemaMapper` for shapes. --------- Co-authored-by: Steven Yuan <[email protected]>
- Loading branch information
Showing
29 changed files
with
1,107 additions
and
9 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
55 changes: 55 additions & 0 deletions
55
...y-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java
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 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.jsonschema; | ||
|
||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
|
||
/** | ||
* Context for a JSON schema mapping. | ||
*/ | ||
public class JsonSchemaMapperContext { | ||
private final Model model; | ||
private final Shape shape; | ||
private final JsonSchemaConfig config; | ||
|
||
JsonSchemaMapperContext( | ||
Model model, | ||
Shape shape, | ||
JsonSchemaConfig config | ||
) { | ||
this.model = model; | ||
this.shape = shape; | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Gets the Smithy model being converted. | ||
* | ||
* @return Returns the Smithy model. | ||
*/ | ||
public Model getModel() { | ||
return model; | ||
} | ||
|
||
/** | ||
* Gets the Smithy shape being mapped. | ||
* | ||
* @return Returns the Smithy shape. | ||
*/ | ||
public Shape getShape() { | ||
return shape; | ||
} | ||
|
||
/** | ||
* Gets the JSON schema configuration object. | ||
* | ||
* @return Returns the JSON schema config object. | ||
*/ | ||
public JsonSchemaConfig getConfig() { | ||
return config; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
description = "This module provides Smithy traits that are used in converting a Smithy model to OpenAPI." | ||
|
||
ext { | ||
displayName = "Smithy :: OpenAPI Traits" | ||
moduleName = "software.amazon.smithy.openapi.traits" | ||
} | ||
|
||
dependencies { | ||
api project(":smithy-model") | ||
} |
Oops, something went wrong.