forked from opensearch-project/opensearch-api-specification
-
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.
Correct security plugin operations that take lists or return maps. (o…
…pensearch-project#127) The aws.protocols#restJson1 protocol explicitly disallows lists and maps for @httpPayload. Requires workaround due to AbstractRestProtocol being package-private, and a bug in HttpBindingIndex waiting on PR smithy-lang/smithy#1840 Signed-off-by: Thomas Farr <tsfarr@amazon.com> Signed-off-by: Alen Abeshov <a_abeshov@kbtu.kz>
- Loading branch information
Showing
28 changed files
with
501 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
const val smithyVersion = "1.31.0" | ||
const val smithyVersion = "1.33.0" |
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 |
---|---|---|
|
@@ -16,5 +16,6 @@ structure GetRole_Input{ | |
|
||
@output | ||
structure GetRole_Output { | ||
role: Role | ||
@httpPayload | ||
content: RolesMap | ||
} |
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
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 |
---|---|---|
|
@@ -17,5 +17,6 @@ structure GetUser_Input{ | |
|
||
@output | ||
structure GetUser_Output { | ||
user: User | ||
@httpPayload | ||
content: UsersMap | ||
} |
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,18 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
|
||
$version: "2" | ||
namespace OpenSearch | ||
|
||
structure PatchOperation { | ||
op: String, | ||
path: String, | ||
value: Document | ||
} | ||
|
||
list PatchOperationList { | ||
member: PatchOperation | ||
} |
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
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
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
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
67 changes: 67 additions & 0 deletions
67
...its/src/main/java/org/opensearch/smithy/openapi/protocols/OpenSearchRestJsonProtocol.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,67 @@ | ||
package org.opensearch.smithy.openapi.protocols; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.opensearch.smithy.openapi.traits.RestJsonTrait; | ||
import software.amazon.smithy.jsonschema.Schema; | ||
import software.amazon.smithy.model.knowledge.HttpBinding; | ||
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.model.shapes.StructureShape; | ||
import software.amazon.smithy.openapi.fromsmithy.Context; | ||
import software.amazon.smithy.openapi.fromsmithy.protocols.AbstractOSRestProtocol; | ||
|
||
public final class OpenSearchRestJsonProtocol extends AbstractOSRestProtocol<RestJsonTrait> { | ||
@Override | ||
public Class<RestJsonTrait> getProtocolType() { | ||
return RestJsonTrait.class; | ||
} | ||
|
||
@Override | ||
protected String getDocumentMediaType(Context<RestJsonTrait> context, Shape operationOrError, OSMessageType message) { | ||
return context.getConfig().getJsonContentType(); | ||
} | ||
|
||
@Override | ||
protected Schema createDocumentSchema(Context<RestJsonTrait> context, Shape operationOrError, List<HttpBinding> bindings, OSMessageType messageType) { | ||
if (bindings.isEmpty()) { | ||
return Schema.builder().type("object").build(); | ||
} | ||
|
||
// We create a synthetic structure shape that is passed through the | ||
// JSON schema converter. This shape only contains members that make | ||
// up the "document" members of the input/output/error shape. | ||
ShapeId container = bindings.get(0).getMember().getContainer(); | ||
StructureShape containerShape = context.getModel().expectShape(container, StructureShape.class); | ||
|
||
// Path parameters of requests are handled in "parameters" and headers are | ||
// handled in headers, so this method must ensure that only members that | ||
// are sent in the document payload are present in the structure when it is | ||
// converted to OpenAPI. This ensures that any path parameters are removed | ||
// before converting the structure to a synthesized JSON schema object. | ||
// Doing this sanitation after converting the shape to JSON schema might | ||
// result in things like "required" properties pointing to members that | ||
// don't exist. | ||
Set<String> documentMemberNames = bindings.stream() | ||
.map(HttpBinding::getMemberName) | ||
.collect(Collectors.toSet()); | ||
|
||
// Remove non-document members. | ||
StructureShape.Builder containerShapeBuilder = containerShape.toBuilder(); | ||
for (String memberName : containerShape.getAllMembers().keySet()) { | ||
if (!documentMemberNames.contains(memberName)) { | ||
containerShapeBuilder.removeMember(memberName); | ||
} | ||
} | ||
|
||
StructureShape cleanedShape = containerShapeBuilder.build(); | ||
return context.getJsonSchemaConverter().convertShape(cleanedShape).getRootSchema(); | ||
} | ||
|
||
@Override | ||
protected Node transformSmithyValueToProtocolValue(Node value) { | ||
return value; | ||
} | ||
} |
Oops, something went wrong.