-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[Golang][client] fix for schema definition name file
#433
[Golang][client] fix for schema definition name file
#433
Conversation
file
Build errors so far:
|
Thanks for looking into this. Is this a common problem that could affect other languages? |
I've restarted the shippable job and it's fine now. For CircleCI, seems like there're some changes and I could no longer restart it: https://circleci.com/gh/grokify/openapi-generator/28?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link The failure has nothing to do with the change and the Go test passed:
|
If the general approach is the same, I think so. If every generator that called
It seems like a more generic and less error-prone solution for all generators would be to abstract the second step so it's implemented once. We could have a method like I thought about implementing this approach as well but since this is a deeper change, it's worth a discussion. If we think this is a better way to go, I can look into this as well. There are some nuances like the |
All tests are passing with no conflicts. PR includes additional tests:
Regarding a more generic approach across all clients, I'd want to look into a few more generators to compare approaches so my preference is to have them as separate activities. |
@@ -67,7 +67,6 @@ paths: | |||
description: Status values that need to be considered for filter | |||
required: true | |||
style: form | |||
explode: false |
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.
FYI. Opened Mermade/oas-kit#76 to track it.
The shippable error does not seem to be related to the change. |
* master: (116 commits) 3.1.0 release (OpenAPITools#486) Fix broken link to openapi generator plugin README (OpenAPITools#484) show warning message for nodejs server only (OpenAPITools#481) Add grokify to Go technical committee (OpenAPITools#479) [Slim] Improve codebase decouple (OpenAPITools#438) Ensure typescript samples are up to date (OpenAPITools#444) Update README.md [Golang][client] delete sample output dir before rebuild (OpenAPITools#477) update petstore samples (OpenAPITools#478) Revert "Improve Docker Tags (OpenAPITools#390)" update go client test dependencies (OpenAPITools#468) [Golang][client] fix for schema definition name `file` (OpenAPITools#433) Fix '.travis' file (syntax) make LICENSE GitHub display compatible (OpenAPITools#467) Improve Docker Tags (OpenAPITools#390) [Golang][client] fix file suffix for _test.go (OpenAPITools#449) Remove copy section (OpenAPITools#463) Add link to presentation (OpenAPITools#465) Use postProcessOperationsWithModels(Map, List) (OpenAPITools#431) [C] Adding petstore sample written in C (OpenAPITools#306) ...
) * fix schema/definition name as 'file' * update samples * Trigger CI due to previous Shippable race condition * add fix with toModelName(openAPIType) * update tests for file schema/definition name * Update 3.0 test spec * update samples * update samples for jaxrs-cxf * Trigger CI due to previous Shippable race condition * add back explode
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,3.1.x
,4.0.x
. Default:master
.@antihax
@bvwells
There are some open items listed at the end of this post so it is not yet ready for merging. Please review the general approach.
Description of the PR
When generating a client with a v3.0 spec Schema or v2.0 spec Definition named
File
, the generator will convert the type to*os.File
instead of the model namedFile
. This is a generic issue where a model schema/definition name may collide with atypeMapping
key.An example spec excerpt looks like:
In the above,
PoolResponseResource
will have a propertySourceFiles
with type[]*os.File
instead of the desired[]File
.This occurs because abstract class
AbstractGoCodegen
convertsFile
to*os.File
usingtypeMapping
:getSchemaType
andgetTypeDeclaration
both check againsttypeMapping
, e.g.:getSchemaType
gets a baseline type to process fromsuper.getSchemaType
which returns a single string that appears to represent 3 things: (a) definition/schema names, (b) types, and (c) formats.typeMapping
covers the following:integer
int32
type
only:"type": "integer"
long
int64
type
andformat
:"type": "integer", "format": "int64"
File
*os.File
$ref
only:"$ref": "#/definitions/File"
Proposed Fix
This PR includes a minimal fix and test case to consider the value of
$ref
when determining the type. If$ref
is present and matches the Spec 2.0/3.0 definition/schema path,typeMapping
is not used.Notes
The added test,
filePropertyTest
inGoModelTest.java
uses the spec 2.0 model reference:#/definitions/File
, however, when building a client, it appears a 2.0 spec using#/definitions/File
is converted to a 3.0 spec#/components/schemas/File
bysuper.getSchemaType
References
Open Items / Next StepsThis update generates client code conditionally if a spec definition with nameFile
(or other schema name with typeMapping collision) is present, so an additional fake PetStore test endpoint will be provided to test the results.filePropertyTest
added toGoModelTest.java
.This currently generates a regression issue that needs to be resolved. A struct will be created with nameFixed in e51623b . Covered inProfileImageInfoUri
but be referenced asProfileImageInfoURI
. This is not covered in the Petstore tests, but appears using the RingCentral spec. Will resolve and look to add a test case for this.filePropertyTest
added toGoModelTest.java
.