Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/codegen/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ type OutputOptions struct {
// Whether to generate nullable type for nullable fields
NullableType bool `yaml:"nullable-type,omitempty"`

// DisableTypeAliasesForType allows defining which OpenAPI `type`s will explicitly not use type aliases
// Currently supports:
// "array"
// DisableTypeAliasesForType allows defining which OpenAPI `type`s will explicitly not use type aliases. Use Go type names
// and not the OpenAPI type names. Use "[]type" to disable arrays, a shortcut for all arrays can be used by specifying
// `array` value.
DisableTypeAliasesForType []string `yaml:"disable-type-aliases-for-type"`

// NameNormalizer is the method used to normalize Go names and types, for instance converting the text `MyApi` to `MyAPI`. Corresponds with the constants defined for `codegen.NameNormalizerFunction`
Expand Down
5 changes: 5 additions & 0 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem
outSchema.AdditionalTypes = arrayType.AdditionalTypes
outSchema.Properties = arrayType.Properties
outSchema.DefineViaAlias = true
// kept for backward compatibility, array can be disabled via either "array" or "[]type"
if sliceContains(globalState.options.OutputOptions.DisableTypeAliasesForType, "array") {
outSchema.DefineViaAlias = false
}
Expand Down Expand Up @@ -656,6 +657,10 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem
} else {
return fmt.Errorf("unhandled Schema type: %v", t)
}

if outSchema.GoType != "" && sliceContains(globalState.options.OutputOptions.DisableTypeAliasesForType, outSchema.GoType) {
outSchema.DefineViaAlias = false
}
return nil
}

Expand Down