importing struct with x-go-type generates invalid client code
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
importing struct with x-go-type generates invalid client code
i'm trying to extract a model from our swagger document & consume it from an external source, bcz we want the the type to be generated by DB access layer.
when doing so i've hit 2 issues:
1. the API's which use the imported types changed the so they take a value rather than a pointer. this implies most of the called API's which forces a huge change to the code base.
2. some API's which take a type T imported using the x-go-type now generate invalid code for the client.
these consume the imported type within the API body
consider importing a type like this:
```
Hotspot:
x-go-type:
import:
package: fbc/xwf/swagger/gen/ents
type: Hotspot
x-nullable: true
```
and then declare an API like this
```
post:
tags:
- hotspot
summary: Create a Hotspot
operationId: "CreateHotspot"
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: Hotspot
required: false
schema:
$ref: '#/definitions/Hotspot'
responses:
201:
description: Hotspot created.
schema:
$ref: '#/definitions/Hotspot'
400:
description: Bad request.
schema:
$ref: '#/definitions/Error'
422:
description: Unprocessable entity
schema:
$ref: '#/definitions/Error'
500:
description: Unexpected error.
schema:
$ref: '#/definitions/Error'
```
the faulty generated code looks like this:
```
func (o *CreateHotspotParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Hotspot != nil {<<<<<<<<<<<<<<<This fails to compile bcz its NOT a pointer !!!
if err := r.SetBodyParam(o.Hotspot); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
```
any idea how to fix this ?
Thanks
Eitan
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Eitan,
It looks like you are using go-swagger. It's not a SmartBear project, and we don't know it well enough to provide support for it. I'd suggest asking this question in the go-swagger repository:
https://github.com/go-swagger/go-swagger/issues
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
