OAS3.1.0 const naming is long and different than other types
I have a simple oas3 file v3.1.0 with both const and regular objects. Here is my config cfg-schemas.yaml:
package: api
generate:
models: true
output: go/api/schemas.go
output-options:
skip-prune: true
name-normalizer: ToCamelCaseWithInitialisms
yaml-tags: trueAnd my schemas input file (simplified) schemas.yaml:
openapi: "3.1.0"
components:
schemas:
SomeConst:
type: string
const: "someconststringinput/fields/aes256"
OtherConst:
type: string
const: "otherconststringinput/subdata/ed25519"
Metadata:
type: object
properties:
name:
type: string
description: name of the input
description:
type: string
description: description of the input
digest:
type: string
description: SHA256 digest of the inputAnd then I run:
oapi-codegen -config ./cfg-schemas.yaml ./schemas.yamlThe output I get is the following:
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.8.0 DO NOT EDIT.
package api
// Defines values for OtherConst.
const (
OtherconststringinputSubdataEd25519 OtherConst = "otherconststringinput/subdata/ed25519"
)
// Valid indicates whether the value is a known member of the OtherConst enum.
func (e OtherConst) Valid() bool {
switch e {
case OtherconststringinputSubdataEd25519:
return true
default:
return false
}
}
// Defines values for SomeConst.
const (
SomeconststringinputFieldsAes256 SomeConst = "someconststringinput/fields/aes256"
)
// Valid indicates whether the value is a known member of the SomeConst enum.
func (e SomeConst) Valid() bool {
switch e {
case SomeconststringinputFieldsAes256:
return true
default:
return false
}
}
// Metadata defines model for Metadata.
type Metadata struct {
// Description description of the input
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
// Digest SHA256 digest of the input
Digest *string `json:"digest,omitempty" yaml:"digest,omitempty"`
// Name name of the input
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
}
// OtherConst defines model for OtherConst.
type OtherConst string
// SomeConst defines model for SomeConst.
type SomeConst stringNotice that my Metadata component becomes type Metadata struct, while my peer SomeConst constant become type SomeConst string which can be access via the painfully named SomeconststringinputFieldsAes256 SomeConst = "someconststringinput/fields/aes256".
Since this is a constant, I don't care much to create a type SomeConst which is just a string, and then have a single object with a long name SomeconststringinputFieldsAes256 (looks like derived from the const value?) for it. I really am just looking for the simple:
const SomeConst = "someconststringinput/fields/aes256"I hope this describes the issue well?
Source: oapi-codegen/oapi-codegen