-
-
Notifications
You must be signed in to change notification settings - Fork 953
fix(codegen): allow using x-go-type and x-go-type-skip-optional-pointer together #1957
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
fix(codegen): allow using x-go-type and x-go-type-skip-optional-pointer together #1957
Conversation
Thanks! Will take a look hopefully today, and see if I can get some tests added to cover this |
Do you have an example (minimal spec) that this change improves the codegen for? In my limited testing, I can't seem to get much meaningfully different when applying this PR I can see that looking a this with an |
With this
I expect something like that:
instead of
Currently, If I remove all the
Which is correct.
Which is also correct.
I get
Which is still correct.
I get:
Which is incorrect. This PR should be fixing that, and makes sure we're not using a pointer when |
Thanks! From my testing: openapi: "3.0.0"
info:
version: 1.0.0
title: Generate models # TODO
paths:
/root:
get:
operationId: getRoot
parameters:
- in: query
name: at
schema:
type: string
format: date-time
x-go-type-skip-optional-pointer: true
x-go-type: googleuuid.UUID
x-go-type-import:
path: github.com/google/uuid
name: googleuuid
responses:
"200":
description: Some data
components:
schemas:
SomeType:
type: object
properties:
at:
type: string
format: date-time
x-go-type-skip-optional-pointer: true
x-go-type: googleuuid.UUID
x-go-type-import:
path: github.com/google/uuid
name: googleuuid It looks like I'll add a bit more of a test to show the before/after for this, thanks! |
606f819
to
136c334
Compare
136c334
to
a720a1f
Compare
As part of future changes, we'll be modifying the way this works, so we should capture the current behaviour.
…er together When using `x-go-type`, `GenerateGoSchema` returns early, meaning that any extensions that are checked after this one are no-op. This PR moves the code for `x-go-type-skip-optional-pointer` higher up, so it can be used alongside `x-go-type`. This corrects this piece of behaviour, and amends our generated code examples to correctly apply `x-go-type-skip-optional-pointer` when using an optional field, or inside an `AllOf`.
a720a1f
to
cf79d5e
Compare
When using
x-go-type
,GenerateGoSchema
returns early, meaning that any extensions that are checked after this one are no-op.This PR moves the code for
x-go-type-skip-optional-pointer
higher up, so it can be used alongsidex-go-type
.This PR only fixes a bug, not the root issue. There may be more similar issues, and the code makes it easy to introduce new similar bugs. Ultimately we'd need to refactor
GenerateGoSchema
to:This isn't the goal of that PR though, so maybe in another one.