Skip to content

How to change the case style (pascal, camel) of a struct tag  #2600

@qubaldo

Description

@qubaldo

Problem statement

I'm trying to use swagger models with my db calls is an sql server seems like is case sensitive. I'm using golang btw.

Swagger specification

AccountsModel:

type: object
required:
  - id
  - account-no
  - description
  - customer-no
  - customer-name
properties:
  id:
    type: integer
  account-no:
    type: string
  description:
    type: string
  customer-no:
    type: string
  customer-name:
      type: string`

I use the --struct-tags db to add the db tag to the struct
this generates the following:

type AccountsModel struct {

// id
// Required: true
ID *int64 `json:"id" db:"id"`

// account no
// Required: true
AccountNo *string `json:"account-no" db:"account-no"`

// description
// Required: true
Description *string `json:"description" db:"description"`

// customer no
// Required: true
CustomerNo *string `json:"customer-no" db:"customer-no"`

// customer name
// Required: true
CustomerName *string `json:"customer-name" db:"customer-name"`

}

I need to be able to have db:"Id" (pascal case) instead of db:"id" but the json needs to stay the same is there a way to customize the format for each struct tag ?

swagger version: 0.27.0
go version: 1.15.6
OS:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions