-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[Go] Fix an issue causing int array reference translated to an invalid type []Integer
#18785
[Go] Fix an issue causing int array reference translated to an invalid type []Integer
#18785
Conversation
faa506a
to
c76cccf
Compare
thanks for the PR. can you please add a test in |
c76cccf
to
e2e6707
Compare
Hi @wing328, sure! Would it be fine to add a new path in that sample? I feel this fix is hard to be tested in the existing endpoint specifications in that doc. |
yes, you can add another fake (tag) endpoint |
which version of openapi generator are you using? I remember adding better support for referencing properties in recent versions (maybe starting in v7.5.0). |
Hi @wing328, I was using the master branch, so it should include the changes made in |
e2e6707
to
95c90fc
Compare
Hi @wing328, I just added the sample. Does it look good? |
Any thought, guys? |
@@ -425,17 +424,19 @@ public String getSchemaType(Schema p) { | |||
String ref = p.get$ref(); | |||
String type; | |||
|
|||
if (ref != null && !ref.isEmpty()) { | |||
if (ref != null && !ref.isEmpty() && ref.endsWith(openAPIType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from what i understand, this fix only works if the schema name happens to be openAPIType
(e.g. string), right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been a while. If I recall correctly (I will double check tomorrow), openAPIType
would be a primitive type name, (e.g., "integer"
), for a reference to an integer, like this example below.
And openAPIType
would be s schema name (e.g., "SomeSchema"
) for a reference to a schema object.
So, checking whether the ref
is ended with the openAPIType
can determine whether it's a Schema object, which needs toModelName()
to capitalize its first letter, rather than a primitive type, which will be handled elsewhere.
3ac0f2b
to
2c984db
Compare
@ChihweiLHBird i've filed #19013 based on this PR. It fixes the issue differently by checking if the ref is a ref to another schema in a property. can you please test it to ensure it works for your use cases? thanks |
CC: @antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5
Fix an issue causing
integer
array withitems
referenced by$ref
being generated to an invalid type[]Integer
.Sample problematic spce:
This PR reorder of theif... else if... else...
expression to prioritize existing primitive types defined intypeMapping
to try to address the issue.This PR double checks to ensure the
openAPIType
is in theref
before proceeding to generating a type with the referenced model name to avoid integer type with a reference being converted toInteger
, rather thanint32
.Further investigation might be needed to look into how
ref
andget$ref()
work because them seems to benull
when$ref
is'#/components/schemas/SomeID'
in the spec, but contains a non-null string value"#/components/schemas/ExampleObject/properties/id"
when$ref
is the corresponding value. This might be root cause of this issue and may have a larger impact.Let me know any thoughts, feedback, or idea.
Still working on finalizing things with the check list below.Done now.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)