-
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.
Refactor
JsonSchemaMapper
to use JsonSchemaMapperContext
- Loading branch information
Steven Yuan
committed
Aug 11, 2023
1 parent
8c401c1
commit 1c437c1
Showing
23 changed files
with
178 additions
and
136 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
23 changes: 0 additions & 23 deletions
23
smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperV2.java
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
smithy-openapi-traits/src/main/resources/META-INF/smithy/manifest
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 |
---|---|---|
@@ -1 +1 @@ | ||
smithy.openapi.smithy | ||
smithy.openapi.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
58 changes: 58 additions & 0 deletions
58
smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.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,58 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.openapi; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.node.Node; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
import software.amazon.smithy.openapi.traits.SpecificationExtensionTrait; | ||
import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
||
@SmithyInternalApi | ||
public final class OpenApiUtils { | ||
private OpenApiUtils() {} | ||
|
||
/** | ||
* Gets the specification extension name for a given meta trait. | ||
* | ||
* Either an explicitly configured extension name in specificationExtensionTrait, or a normalization of the shape | ||
* ID. The normalization replaces all "." and "#" in a shapeId to "-". | ||
* | ||
* @param metaTraitId Trait shape to get the extension name. | ||
* @return Extension name for the given trait shape. | ||
*/ | ||
public static String getSpecificationExtensionName( | ||
ShapeId metaTraitId, | ||
SpecificationExtensionTrait specificationExtensionTrait | ||
) { | ||
return specificationExtensionTrait.getAs() | ||
.orElse("x-" + metaTraitId.toString().replaceAll("[.#]", "-")); | ||
} | ||
|
||
/** | ||
* Return specification extensions attached to a given shape. | ||
* | ||
* @param shape Shape to get extensions for. | ||
* @param model Model the shape belongs to. | ||
* @return map of specification extension names to node values | ||
*/ | ||
public static Map<String, Node> getSpecificationExtensionsMap(Model model, Shape shape) { | ||
Map<String, Node> specificationExtensions = new LinkedHashMap<String, Node>(); | ||
shape.getAllTraits().forEach((traitId, trait) -> | ||
// Get Applied Trait | ||
model.getShape(traitId) | ||
// Get SpecificationExtensionTrait on the Applied Trait | ||
.flatMap(traitShape -> traitShape.getTrait(SpecificationExtensionTrait.class)) | ||
// Get specification extension name from the Applied Trait and SpecificationExtensionTrait | ||
.map(specificationExtension -> getSpecificationExtensionName(traitId, specificationExtension)) | ||
// Put the specification extension name and Applied Meta trait into the map. | ||
.ifPresent(name -> specificationExtensions.put(name, trait.toNode()))); | ||
return specificationExtensions; | ||
} | ||
} |
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
Oops, something went wrong.