oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Types can be placed separately from the server side logic

Open sparshev opened this issue 4 years ago • 4 comments

Additional option to specify which module contains the generated types

sparshev avatar Jun 24 '21 21:06 sparshev

Hi @deepmap-marcinr, could you please suggest who can check the PR? If it's good - I can work on the tests and other required improvements to make sure it will fit perfectly.

sparshev avatar Jul 13 '21 17:07 sparshev

Hi @deepmap-marcinr could you please check this? Not sure if it's still actual though...

sparshev avatar Oct 12 '21 21:10 sparshev

Rebased and adapted this patch in #558 . I think we can close it now.

tuxofil avatar Apr 24 '22 10:04 tuxofil

Thank you @tuxofil , I've got no review, so I switched to in-place patching and almost forgot about this change - for sure when yours will be merged I will close this one.

sparshev avatar Apr 24 '22 20:04 sparshev

Ok, now types could be separated the next way:

  • For types package:
    ---
    package: types
    output: types/types.gen.go
    generate:
      models: true
    
  • For the server package:
    ---
    package: api
    output: api/server_v1.gen.go
    generate:
      echo-server: true
    additional-imports:
      - alias: .  # means will be used without namespace prefix
        package: github.com/exampleorg/exampleproj/pkg/types  # full path to the types package
    

So the types will be available to use in server generated code.

sparshev avatar Sep 12 '22 00:09 sparshev