Skip to content

Conversation

@bit0rez
Copy link

@bit0rez bit0rez commented Jul 4, 2025

Problem code example

// Some schema type
type SomeType struct {
  SomeField string
}

func (s *SomeType) GetSomeField() string {
  return s.SomeField
}

// Aliases

type Foo SomeType
type Bar SomeType
x := &Foo{}
y := &Bar{}

x.GetSomeField() // <- Compile Error: x.GetSomeField undefined (type *Foo has no field or method GetSomeField)
y.GetSomeField() // <- Compile Error: y.GetSomeField undefined (type *Bar has no field or method GetSomeField)

So, client can't use interface for this types and access SomeField in some cases.

Just generate real go type alias and embed structures to fixing this problem.

@abemedia
Copy link
Contributor

abemedia commented Jul 7, 2025

What if the alias has different validation or defaults? Making it an actual go type alias would break this.

@bit0rez
Copy link
Author

bit0rez commented Jul 8, 2025

What if the alias has different validation or defaults? Making it an actual go type alias would break this.

I'll rollback this for non struct types. For structs with embedding it works fine.

@bit0rez bit0rez force-pushed the fix-type-alias-template branch from 928a6ca to 18d14ea Compare August 20, 2025 11:47
@bit0rez
Copy link
Author

bit0rez commented Aug 20, 2025

UP!

@ernado ernado force-pushed the fix-type-alias-template branch from 816dcb3 to 7abcb48 Compare September 18, 2025 00:31
@ernado
Copy link
Member

ernado commented Sep 18, 2025

This breaks tests:

ernado@nexus:/src/ogen/ogen$ make test
# github.com/ogen-go/ogen/internal/integration/test_http_requests
internal/integration/test_http_requests/oas_request_decoders_gen.go:165:60: cannot convert unwrapped (variable of struct type SimpleObject) to type AllRequestBodiesApplicationXWwwFormUrlencoded
internal/integration/test_http_requests/oas_request_decoders_gen.go:401:68: cannot convert unwrapped (variable of struct type SimpleObject) to type AllRequestBodiesOptionalApplicationXWwwFormUrlencoded

Please iterate with make generat examples to fix it, so I can merge this.

Copy link
Member

@ernado ernado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix make test result

@bit0rez bit0rez force-pushed the fix-type-alias-template branch from 7abcb48 to d125e78 Compare September 26, 2025 12:05
@bit0rez bit0rez force-pushed the fix-type-alias-template branch from 3b2ce3a to afa85d2 Compare September 26, 2025 15:15
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

Successfully merging this pull request may close these issues.

3 participants