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

Generated code doesn't compile when there's a smithy shape using a reserved name #1051

Closed
miguel-vila opened this issue Jun 22, 2023 · 9 comments
Labels
0.17 affects the 0.17 series bug Something isn't working

Comments

@miguel-vila
Copy link
Contributor

for example this smithy code:

$version: "2.0"

namespace smithy4s.example.reservedNameOverride

use smithy4s.api#simpleRestJson

@simpleRestJson
service ReservedNameOverrideService {
    version: "1.0.0",
    operations: [SetOp]
}

@http(method: "POST", uri: "/api/set/", code: 204)
operation SetOp {
    input := {
       @required
       set: Set
    }
}

structure Set {
    @required
    someField: String,
    @required
    otherField: Integer
}

generates this code which doesn't compile:

package smithy4s.example.reservedNameOverride

import smithy4s.Schema
import smithy4s.Hints
import smithy4s.ShapeId
import smithy4s.schema.Schema.struct
import smithy4s.ShapeTag

case class SetOpInput(set: _Set)
object SetOpInput extends ShapeTag.Companion[SetOpInput] {
  val id: ShapeId = ShapeId("smithy4s.example.reservedNameOverride", "SetOpInput")

  val hints : Hints = Hints(
    smithy.api.Input(),
  )

  implicit val schema: Schema[SetOpInput] = struct(
    _Set.schema.required[SetOpInput]("set", _.set).addHints(smithy.api.Required()),
  ){
    SetOpInput.apply
  }.withId(id).addHints(hints)
}

because it's referring to _Set instead of Set in the same package

reproduced at #1050

@kubukoz kubukoz added bug Something isn't working 0.17 affects the 0.17 series labels Jun 22, 2023
@kubukoz
Copy link
Member

kubukoz commented Jun 22, 2023

related: #389

@Baccata
Copy link
Contributor

Baccata commented Jun 22, 2023

Wanna have a go at fixing ?

@miguel-vila
Copy link
Contributor Author

@Baccata yeah, will give it a go, any hint on the related code parts?

@Baccata
Copy link
Contributor

Baccata commented Jun 22, 2023

not off the top of my head

@kubukoz
Copy link
Member

kubukoz commented Jun 22, 2023

CollisionAvoidance.scala is probably your man.

@miguel-vila
Copy link
Contributor Author

btw, what is the preferred solution here? to override the name (e.g. make it case class SetOpInput(set: Set) in the code above and Set refers to the type in the same package)? or to use the new name (make it case class SetOpInput(set: _Set))? My thinking is that it's better to avoid name overriding

@Baccata
Copy link
Contributor

Baccata commented Jun 26, 2023

@miguel-vila, actually, I'll fix it.

The "reservedNames" was there in the first iterations of smithy4s. In the last year, a much more robust mechanism was introduced by @yisraelU, so dropping the reserved "types" altogether is a better solution.

@Baccata
Copy link
Contributor

Baccata commented Jun 26, 2023

@Baccata
Copy link
Contributor

Baccata commented Jul 24, 2023

Closing as the PRs fixing this have been merged.

@Baccata Baccata closed this as completed Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.17 affects the 0.17 series bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants