Comments (9)
@ilk thanks for creating the issue. May I know if you can also share a spec to more easily reproduce the issue?
When using type: object
, are you referring to an arbitrary JSON payload?
from openapi-generator.
For example:
...
"Provider" : {
"type" : "object",
"properties" : {
"Foobar" : {
"type" : "object",
"description" : "Foobar-specific configuration object"
},
...
Results to:
type Provider struct {
Foobar *interface{}
...
}
Better would be:
type Provider struct {
Foobar map[string]interface{}
...
}
from openapi-generator.
@ilk @wing328 I agree with ilk's assessment and would appreciate this change too. It'll make the go client more Go-like:
- JSON Object type maps properly to Go's
map[string]interface{}
. This way there is no need to type cast. - Since map/slice/channel values are already pointer wrapper struct values, there is no need in this case to add an additional pointer to them. Handling an
*interface{}
variable is extremely complex, non Go idiomatic and involves usage of thereflect
package - which is not easy to grasp.
from openapi-generator.
@louis77 thanks for the feedback.
from openapi-generator.
from openapi-generator.
@antihax Which works properly if definitions are used in the OpenAPI Spec.
However, arbitrary inline objects are currently represented as *interface{}'s. To use @ilk 's example, Foobar
is an arbitrary inline object, most likely there will be no corresponding struct definition in the Go code that will use the go-client.
from openapi-generator.
This looks OK in this instance. However it would end up as map[string]string as we cannot determine types on an arbitrary structure?
from openapi-generator.
The AbstractGoCodegen.java
implementations plainly maps these objects always to an interface{}:
typeMapping.put("object", "interface{}");
This is now changed to:
typeMapping.put("object", "map[string]interface{}");
So it'll always end up as a map[string]interface{}, there is no further logic involved. In a next release we could think about generating an InlineObject
Go type to further abstract the user from low-level accessing of the values inside the map.
from openapi-generator.
Is it correct to say that the proposed change will also work with XML payload (since Go client supports the "withXML" option) ?
withXml
whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML) (Default: false)
from openapi-generator.
Related Issues (20)
- [BUG] Description
- [BUG] Description HOT 3
- enum
- [BUG][JAVA] Client generation: required gson versions in generated pom.xml (2.10.1) and build.* are different HOT 1
- [BUG][C#][CSHARP] Client.Trace/AsynchronousClient.TraceAsync are missed in ISynchronousClient/IAsynchronousClient but invoked from WebSocketApi
- Please upgrade jmustache to 1.16 HOT 3
- [BUG] Description
- [BUG] [kotlin-spring] Escaped backticks in parameters using reserved words
- [BUG][C#][CSharp] Newline character at the example field of the property leads to incorrect CSharp generation
- [BUG][PYTHON] Int Enum serialization is the enum name instead of value
- [BUG] [SWIFT]: URLSession warns about deprecated Classes with iOS 15 HOT 1
- [BUG][DART2] ApiClient deserialize result to type Map<String,Map<String,String>> throws exception
- Code read help request - where are the language specific classes injected? HOT 1
- [BUG][JAVA] Incorrect Jackson @JsonProperty for microprofile client
- Enhance useSpringBoot3 feature HOT 1
- Declared path parameter functionId needs to be defined as a path parameter in path or operation level HOT 3
- [BUG] invalid allVars for allOf and properties at the same level HOT 4
- [REQ] [C#] [Csharp] Support `Nullable``enable` for RestSharp client when `nullableReferenceTypes` enabled HOT 1
- [REQ] Decouple java-camel generator from Spring Boot dependencies HOT 1
- org.springframework.core.io.Resource cannot be converted to org.springframework.web.multipart.MultipartFile
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-generator.