Created by: mariotoffia
This allows to override json key name from open api using x-codegen-name. This makes it possible to have a field name that renders a different json key. When not x-codegen-name exists it defaults back to the original baseName naming (as earlier).
This applies to the go client generator.
Below open API spec defines two fields, one overridden and the other is normal.
openapi: "3.0.1"
info:
title: Building
version: 1.0.0
description: >
Building model
termsOfService: "http://www.crossbreed.se/terms/"
contact:
name: mario.toffia@crossbreed.se
license:
name: Apache 2.0
paths:
/info:
get:
operationId: getInfo
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Building'
components:
schemas:
Building:
type: object
properties:
BuildingID:
type: string
x-go-custom-tag: 'dynamodbav:"PK"'
x-codegen-name: lid
SK:
type: string
maxLength: 255
This generates the following
/*
Building
Building model
API version: 1.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package locationmodel
import (
"encoding/json"
)
// Building struct for Building
type Building struct {
BuildingID string `json:"lid" dynamodbav:"PK"`
SK string `json:"SK"`
}
// NewBuilding instantiates a new Building object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBuilding(buildingID string, sK string, name string, location map[string]string, params map[string]string, version int64, sign string) *Building {
this := Building{}
this.BuildingID = buildingID
this.SK = sK
this.Name = name
this.Location = location
this.Params = params
this.Version = version
this.Sign = sign
return &this
}
// NewBuildingWithDefaults instantiates a new Building object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBuildingWithDefaults() *Building {
this := Building{}
return &this
}
// GetBuildingID returns the BuildingID field value
func (o *Building) GetBuildingID() string {
if o == nil {
var ret string
return ret
}
return o.BuildingID
}
// GetBuildingIDOk returns a tuple with the BuildingID field value
// and a boolean to check if the value has been set.
func (o *Building) GetBuildingIDOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.BuildingID, true
}
// SetBuildingID sets field value
func (o *Building) SetBuildingID(v string) {
o.BuildingID = v
}
// GetSK returns the SK field value
func (o *Building) GetSK() string {
if o == nil {
var ret string
return ret
}
return o.SK
}
// GetSKOk returns a tuple with the SK field value
// and a boolean to check if the value has been set.
func (o *Building) GetSKOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.SK, true
}
// SetSK sets field value
func (o *Building) SetSK(v string) {
o.SK = v
}
func (o Building) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["lid"] = o.BuildingID
}
if true {
toSerialize["SK"] = o.SK
}
return json.Marshal(toSerialize)
}
type NullableBuilding struct {
value *Building
isSet bool
}
func (v NullableBuilding) Get() *Building {
return v.value
}
func (v *NullableBuilding) Set(val *Building) {
v.value = val
v.isSet = true
}
func (v NullableBuilding) IsSet() bool {
return v.isSet
}
func (v *NullableBuilding) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBuilding(val *Building) *NullableBuilding {
return &NullableBuilding{value: val, isSet: true}
}
func (v NullableBuilding) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBuilding) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}