Skip to content

optional nullable field does not get omitempty json tag as mention in Readme #2091

@damnOblivious

Description

@damnOblivious

Readme states that by default nullable fields get omitempty tag. See https://github.com/oapi-codegen/oapi-codegen?tab=readme-ov-file#generating-nullable-types. But that doesn't seem to be the case.

#[0]$ cat config.yaml2
package: preferskipoptionalpointerwithomitzero
output: gen.go
generate:
  models: true
output-options:
  skip-prune: true
#[0]$ cat spec.yaml2
openapi: "3.0.0"
info:
  version: 1.0.0
  title: testing
components:
  schemas:
    ClientWithExtension:
      type: object
      properties:
        newfield:
          type: string
          nullable: true
#[0]$ oapi-codegen --config config.yaml2 spec.yaml2

#[0]$ cat gen.go
// Package preferskipoptionalpointerwithomitzero provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.0 DO NOT EDIT.
package preferskipoptionalpointerwithomitzero

// ClientWithExtension defines model for ClientWithExtension.
type ClientWithExtension struct {
        Newfield *string `json:"newfield"`
}
#[0]$ oapi-codegen --version
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
v2.5.0

#[0]$ go version
go version go1.24.4 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions