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
10 changes: 10 additions & 0 deletions configuration-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@
"type": "string"
}
},
"content-types": {
"type": "object",
"description": "Maps a short name (used as the tag in generated type names, e.g. the `JSON` in `FindPetsJSONRequestBody`) to a list of regex patterns matched against request/response media types. Matching media types get models generated and named with the short name. Note that typed fields on client response structs are only generated for media types the client knows how to deserialize (JSON-like, YAML and XML); mapping any other media type (e.g. `CSV: ['^text/csv$']`) generates models and named request bodies, but client responses for it expose only the raw body. Entries are merged on top of the built-in defaults by key replacement (`JSON: ['^application/json$']`, `Formdata: ['^application/x-www-form-urlencoded$']`, `Multipart: ['^multipart/']`, `Text: ['^text/plain$']`); an empty list disables a key. A media type matching patterns under two different short names is a generation-time error; unmatched media types keep the remaining built-in behavior.",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
},
"nullable-type": {
"type": "boolean",
"description": "Whether to generate nullable type for nullable fields"
Expand Down
12 changes: 12 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ output-options:
skip-client-response-content-type: false
skip-response-body-getters: false
streaming-content-types: []
# Short names for media types, used in generated type names. Keys are the
# tag spliced into type names (e.g. the JSON in FindPetsJSONRequestBody),
# values are regex patterns matched against request/response media types.
# Matching media types get models generated and named with the short name.
# User entries are merged on top of these defaults by key replacement
# (an empty list disables a key); unmatched media types keep the
# remaining built-in behavior.
content-types:
JSON: ['^application/json$']
Formdata: ['^application/x-www-form-urlencoded$']
Multipart: ['^multipart/']
Text: ['^text/plain$']
user-templates: {}
# OpenAPI Overlay applied to the spec before generation
overlay:
Expand Down
16 changes: 16 additions & 0 deletions internal/test/options/content_types/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# yaml-language-server: $schema=../../../../configuration-schema.json
package: optionscontenttypes
output: content_types.gen.go
generate:
models: true
client: true
std-http-server: true
strict-server: true
output-options:
skip-prune: true
# content-types: short names mapped to media-type regex patterns. V1 renames
# a vendored JSON type in generated identifiers; CSV opts an otherwise
# unsupported media type into model generation.
content-types:
V1: ['^application/vnd\.mycompany\.v1\+json$']
CSV: ['^text/csv$']
Loading