Shapes under `alloy.openapi` not being generated
Just to provide a reproduction of the issue, let's say we're starting with a JSON Schema definition:
{
"$schema":"http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"exampleField": {
"type": "integer",
"x-format": "int64"
}
}
}
...we then invoke smithytranslate json-schema-to-smithy --input example.json ../smithy which generates this smithy file:
$version: "2.0"
namespace example
use alloy.openapi#openapiExtensions
structure Input {
@openapiExtensions(
"x-format": "int64"
)
exampleField: Integer
}
along with a couple of other files i.e. alloy/openapi.smithy and alloy/common.smithy, the openapi file contains the definition of @openapiExtensions but when trying to compile this code we get:
ul 30, 2024 10:36:16 AM software.amazon.smithy.openapi.fromsmithy.mappers.RemoveUnusedComponents removalRound
INFO: Removing unused OpenAPI components: [#/components/schemas/ConferenceNotFound, #/components/schemas/CreateConferenceOutput, #/components/schemas/CreateConferenceInput, #/components/schemas/DeleteConferenceInput, #/components/schemas/UpdateTalkInput, #/components/schemas/CreateTalkInput, #/components/schemas/ConferenceOrTalkNotFound, #/components/schemas/ValidationErrors, #/components/schemas/FetchConferencesOutput, #/components/schemas/CreateTalkOutput, #/components/schemas/UpdateConferenceInput, #/components/schemas/UpdateTalkOutput, #/components/schemas/DeleteTalkInput]
[info] compiling 4 Scala sources to /home/aleksander/repos/ducktape-talk/http/smithy/target/scala-3.3.3/classes ...
[error] -- [E008] Not Found Error: /home/aleksander/repos/ducktape-talk/http/smithy/target/scala-3.3.3/src_managed/main/smithy4s/example/Input.scala:21:71
[error] 21 | int.optional[Input]("exampleField", _.exampleField).addHints(alloy.openapi.OpenapiExtensions(Map("x-format" -> smithy4s.Document.fromString("int64")))),
[error] | ^^^^^^^^^^^^^
[error] | value openapi is not a member of alloy
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 9 s, completed Jul 30, 2024, 10:36:24 AM
sbt:httpSmithy>
This was discussed on Discord here. I'll also copy over the context and a workaround that was provided by one of the maintainers:
right okay ... so it's a bug, that's caused because :
we've not generated the openapi namespace in smithy4s-core (see https://github.com/disneystreaming/smithy4s/blob/8d943ab5db5f0d72656d85928202955bc4e8d056/build.sbt#L181-L187)
we're preventing the automatic generation of anything under some namespace list, unless specified otherwise (https://github.com/disneystreaming/smithy4s/blob/8d943ab5db5f0d72656d85928202955bc4e8d056/modules/codegen/src/smithy4s/codegen/internals/CodegenImpl.scala#L140)
Could you kindly open an issue ? In the meantime, you can mitigate by having a dedicated module that would have the smithy4s codegen plugin enabled, and set the smithy4sAllowedNamespaces setting to Set("alloy.openapi")
@Baccata Should the resolution be to add the openapi namespace to the core module .
Yeah, I think it's probably okay for us to add that namespace to the core module.
@arainko apologies, looks like I had missed this issue when you created it
No worries - the workaround is doing its heavylifting just fine 😄
https://github.com/disneystreaming/smithy4s/blob/4bfa08b0306a75cae85d03bfb6e245462824a2f7/build.sbt#L209
probably just need to add that namespace here