Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shapes under alloy.openapi not being generated #1571

Open
arainko opened this issue Jul 30, 2024 · 3 comments
Open

Shapes under alloy.openapi not being generated #1571

arainko opened this issue Jul 30, 2024 · 3 comments

Comments

@arainko
Copy link

arainko commented Jul 30, 2024

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") 
@yisraelU
Copy link
Contributor

yisraelU commented Oct 7, 2024

@Baccata Should the resolution be to add the openapi namespace to the core module .

@Baccata
Copy link
Contributor

Baccata commented Oct 8, 2024

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

@arainko
Copy link
Author

arainko commented Oct 8, 2024

No worries - the workaround is doing its heavylifting just fine 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants