-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from benoitlouy/jsonunknown-additionalprop
update openapi/jsonschema conversion to translate jsonUnknown to additionalProperties
- Loading branch information
Showing
4 changed files
with
61 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright 2022 Disney Streaming | ||
* | ||
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://disneystreaming.github.io/TOST-1.0.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package alloy.openapi | ||
|
||
import software.amazon.smithy.jsonschema.JsonSchemaMapper | ||
import software.amazon.smithy.jsonschema.JsonSchemaConfig | ||
import software.amazon.smithy.jsonschema.Schema.Builder | ||
import software.amazon.smithy.model.node.Node | ||
import software.amazon.smithy.model.shapes.Shape | ||
import alloy.JsonUnknownTrait | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
class JsonUnknownMapper() extends JsonSchemaMapper { | ||
private final val ADDITIONAL_PROPERTIES = "additionalProperties" | ||
|
||
override def updateSchema( | ||
shape: Shape, | ||
schemaBuilder: Builder, | ||
config: JsonSchemaConfig | ||
): Builder = { | ||
val jsonUnknownMemberName = shape | ||
.getAllMembers() | ||
.asScala | ||
.collect { | ||
case (name, member) if member.hasTrait(classOf[JsonUnknownTrait]) => | ||
name | ||
} | ||
.headOption | ||
|
||
jsonUnknownMemberName.fold(schemaBuilder) { name => | ||
schemaBuilder | ||
.removeProperty(name) | ||
.putExtension(ADDITIONAL_PROPERTIES, Node.from(true)) | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -305,6 +305,7 @@ | |
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": true, | ||
"example": { | ||
"name": "Woof" | ||
} | ||
|
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