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

implement new field: x-go-type-import #633

Merged
merged 15 commits into from Jun 29, 2022
Merged

implement new field: x-go-type-import #633

merged 15 commits into from Jun 29, 2022

Conversation

VladimirStepanov
Copy link
Contributor

@VladimirStepanov VladimirStepanov commented Jun 18, 2022

Close #498

@Viltonhoy
Copy link

Tried to use your x-go-type with an imported type but as a result it produces a pointer to this type. Do you have nullable in your code?

@VladimirStepanov
Copy link
Contributor Author

VladimirStepanov commented Jun 20, 2022

@Viltonhoy oapi-codegen generates pointer type when a field is not in required list

schemas:
    Pet:
      properties:
        age:
          x-go-type: uuid.UUID
          x-go-type-import:
            path: github.com/google/uuid
      required:
        - age

Result:

type Pet struct {
    Age uuid.UUID `json:"age"`
}

@VladimirStepanov
Copy link
Contributor Author

@deepmap-marcinr Hello, could you check this changes plz, if you have free time?:)

@othalla
Copy link

othalla commented Jun 23, 2022

Wht not testing the codegen.go file ?

@VladimirStepanov
Copy link
Contributor Author

@othalla thanks for your comment, I fixed it

@stsem
Copy link

stsem commented Jun 29, 2022

I'm really looking forward to this PR in the master

@deepmap-marcinr
Copy link
Contributor

We can already add any arbitrary imports via the configuration file for oapi-codegen, so I was wondering why we want to do this via the spec? I've been trying to avoid having multiple ways of doing the same thing where it can be helped.

@VladimirStepanov
Copy link
Contributor Author

VladimirStepanov commented Jun 29, 2022

@deepmap-marcinr Hi! Thanks for your reply! :)
I noticed, some people are waiting for this support (15 votes in the issue and several votes here). I thought it will be convenient and intuitively to keep close declarations and imports together :)

@deepmap-marcinr deepmap-marcinr merged commit 2cf7fcf into deepmap:master Jun 29, 2022
adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
* implement new field: x-go-type-import

* implement getting of request bodies imports

* implement getting of responses imports

* refactoring: rename GetImportsFromSchema to GetImports

* refactoring: add error wrapping

* update README

* fix: generate import only if define x-go-type and x-go-type-import

* fix: bug of import generation

* fix: remove useless checking

* docs: add description for 'name' field

* test: add tests for x-go-type-import into codegen_test

* docs: fix README.md

* refactor: fix error msg

* refactor: use existing importMap type

* refactor: fix error msg

Co-authored-by: Vladimir Stepanov <v.stepanov@redmadrobot.com>
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.

Support types that need to be imported in the x-go-type property
6 participants