Skip to content

Conversation

@shindonghwi
Copy link
Contributor

Summary

  • Adds support for parsing {} as an empty object in example values
  • Fixes the error object is unsupported type in example value {} when using map[string]struct{} with examples

Problem

When using a map[string]struct{} field with swaggertype and example tags:

type Response struct {
    MyField map[string]struct{} `json:"my_field" swaggertype:"object,object" example:"key1:{},key2:{}"`
}

The parser would fail with:

object is unsupported type in example value `{}`

Solution

Added a special case in defineTypeOfExample to handle empty object {} as a valid example value, returning an empty map[string]any{}.

Test plan

  • Added unit tests for empty object parsing
  • Added unit tests for map[string]struct{} with empty object values
  • All existing tests pass

Fixes #2018

This adds support for parsing `{}` as an empty object in example values.

Before this fix, using `swaggertype:"object,object" example:"key1:{},key2:{}"`
for a `map[string]struct{}` field would fail with:
  "object is unsupported type in example value `{}`"

Now the empty object `{}` is correctly parsed as an empty map.

Fixes swaggo#2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support map[string]struct{} struct-tag examples

1 participant