Skip to content

Commit

Permalink
(fix): Fix Go snippets for optional primitive aliases (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Feb 24, 2024
1 parent fb0814d commit fdd7a6a
Show file tree
Hide file tree
Showing 62 changed files with 5,826 additions and 2,008 deletions.
2 changes: 1 addition & 1 deletion generators/go/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.0-rc0
0.17.0-rc1
20 changes: 19 additions & 1 deletion generators/go/internal/generator/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (s *SnippetWriter) getSnippetForContainer(
if exampleContainer.Optional == nil {
return nil
}
if primitive := exampleContainer.Optional.Shape.Primitive; primitive != nil {
if primitive := maybePrimitiveExampleTypeReferenceShape(exampleContainer.Optional.Shape); primitive != nil {
return s.getSnippetForOptionalPrimitive(primitive)
}
return s.GetSnippetForExampleTypeReference(exampleContainer.Optional)
Expand Down Expand Up @@ -510,6 +510,24 @@ func (s *SnippetWriter) declaredTypeNameToImportedReference(
}
}

func maybePrimitiveExampleTypeReferenceShape(
exampleTypeReferenceShape *ir.ExampleTypeReferenceShape,
) *ir.ExamplePrimitive {
switch exampleTypeReferenceShape.Type {
case "primitive":
return exampleTypeReferenceShape.Primitive
case "container":
if exampleTypeReferenceShape.Container.Optional != nil {
return maybePrimitiveExampleTypeReferenceShape(exampleTypeReferenceShape.Container.Optional.Shape)
}
case "named":
if exampleTypeReferenceShape.Named.Shape.Alias != nil {
return maybePrimitiveExampleTypeReferenceShape(exampleTypeReferenceShape.Named.Shape.Alias.Value.Shape)
}
}
return nil
}

func examplePrimitiveToPointerConstructorName(
examplePrimitive *ir.ExamplePrimitive,
) string {
Expand Down
5 changes: 5 additions & 0 deletions generators/go/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- ## Unreleased -->

## [0.17.0-rc1] - 2024-02-23

- Fix: Snippets for aliases to optional primitive values. With this, the generated snippet
will include the top-level pointer helpers (e.g. `acme.String(...)`).

## [0.17.0-rc0] - 2024-02-21

- Fix: Package documentation is now generated into the correct package's `doc.go`.
Expand Down
Loading

0 comments on commit fdd7a6a

Please sign in to comment.