Skip to content

OpenAPI Extensions

As well as the core OpenAPI support, we also support the following OpenAPI extensions, as denoted by the OpenAPI Specification Extensions.

Available Extensions

Extension Description Example
x-go-type / x-go-type-import Override the generated type definition (and optionally, add an import from another package) View Example
x-go-type-skip-optional-pointer Do not add a pointer type for optional fields in structs View Example
x-go-name Override the generated name of a field or a type View Example
x-go-type-name Override the generated name of a type View Example
x-oapi-codegen-only-honour-go-name Prevent automatic capitalization of field names (for unexported fields) View Example
x-omitempty Force the presence of the JSON tag omitempty on a field View Example
x-go-json-ignore When (un)marshaling JSON, ignore field(s) View Example
x-oapi-codegen-extra-tags Generate arbitrary struct tags to fields View Example
x-sensitive-data Automatically mask sensitive data in JSON output View Example
x-enum-names Override generated variable names for enum constants View Example
x-deprecated-reason Add a GoDoc deprecation warning to a type View Example

Quick Examples

Type Override with Import

properties:
  id:
    type: string
    x-go-type: uuid.UUID
    x-go-type-import:
      path: github.com/google/uuid

Custom Struct Tags

properties:
  email:
    type: string
    x-oapi-codegen-extra-tags:
      validate: "required,email"
      safe-to-log: "false"

Sensitive Data Masking

properties:
  password:
    type: string
    x-sensitive-data:
      mask: full

For detailed documentation on each extension, click on the extension name in the table above.