-
Hi, everyone! 😄 Thanks in advance for any tips and suggestions! I'm trying to reuse some of the
I understand that the example below represents incorrect usage of definitions:
MyObjectType:
type: object
x-nullable: false
properties:
number:
$ref: "#/definitions/Number"
x-nullable: false
x-omitempty: true
x-go-custom-tag: "bson:\"number,omitempty\""
MyOtherObjectType:
type: object
x-nullable: false
properties:
number:
$ref: "#/definitions/Number"
x-nullable: true
x-omitempty: false
x-go-custom-tag: "bson:\"Number\""
Number:
type: string
enum:
- one
- two
- three With Anchors (
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Was able to make it work with a workaround. Really wish we could use it with // MyObjectType my object type
//
// swagger:model MyObjectType
type MyObjectType struct {
// ID
ID *pkg.ID `json:"id,omitempty" bson:"f,omitempty"`
// num
Num Number `json:"number" bson:"number"`
} This is what makes it work 👇 x-go-type:
type: "Number"
# equivalent to
x-go-type:
type: "Number"
import:
package:
alias:
hints:
kind: <whatever default is>
noValidation: false
nullable: <whatever default is>
embedded: false swagger.yml swagger: "2.0"
info:
version: version
title: title
paths: {}
x-types:
id: &ID
type: "ID"
import:
package: "github.com/redacted/redacted/pkg"
alias: pkg
hints:
kind: string
noValidation: false
nullable: false
embedded: false
definitions:
MyObjectType:
type: object
x-nullable: false
properties:
id:
type: string
x-go-type: *ID
x-go-name: ID
x-go-custom-tag: "bson:\"f,omitempty\""
x-nullable: true
x-omitempty: true
number:
type: string
x-go-type:
type: "Number"
x-go-name: Num
x-go-custom-tag: "bson:\"number\""
x-nullable: false
x-omitempty: false
Number:
type: string
enum:
- one
- two
- three On a separate note, one could set default values values for definitions:
MyObjectType:
type: object
x-nullable: false
properties:
default:
type: string
x-go-type:
type: "Number"
custom:
x-go-type:
type: "Number"
x-go-custom-tag: "bson:\"custom\""
x-nullable: false
x-omitempty: false
Number:
type: string
x-go-name: Number
x-go-custom-tag: "bson:\"default\""
enum:
- one
- two
- three |
Beta Was this translation helpful? Give feedback.
Was able to make it work with a workaround. Really wish we could use it with
$ref
tho 😢This is what makes it work 👇
swagger.yml