Skip to content

fixbug: interface{} in a map as value should be generated/typed to any #2776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

emilgpa
Copy link
Contributor

@emilgpa emilgpa commented May 21, 2022

package main

// swagger:model Example
type Example struct {
	MyField map[string]interface{} `json:"my_field,omitempty"`
}

should to generate:

{
  "swagger": "2.0",
  "paths": {},
  "definitions": {
    "Example": {
      "type": "object",
      "properties": {
        "my_field": {
          "type": "object",
          "additionalProperties": {},
          "x-go-name": "MyField"
        }
      }
    }
  }
}

but currently generates:

{
  "swagger": "2.0",
  "paths": {},
  "definitions": {
    "Example": {
      "type": "object",
      "properties": {
        "my_field": {
          "type": "object",
          "additionalProperties": {
            "type": "object"
          }
          "x-go-name": "MyField"
        }
      }
    }
  }
}

interface{} as value in a map should be mapped to any. This PR fixes this!

this issue is more described in: #2758

@emilgpa emilgpa changed the title fixbug: interface{} should be generated/typed to 'any' fixbug: interface{} in a map as value should be generated/typed to any May 21, 2022
@casualjim
Copy link
Member

I don't think this PR fixes #2758

As far as I can tell this PR just removes the default of type: object to be any type of json value. But it doesn't address the real issue that is mentioned which is respecting swagger:type

Copy link
Member

@casualjim casualjim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to work on supporting swagger:type

@emilgpa
Copy link
Contributor Author

emilgpa commented May 22, 2022

@casualjim Yes, you're right. It is also related to swagger:type. Although I understand from the code that swagger:type object doesn't exist. Could that be the reason the guy was trying to use it to avoid the additionalProperties generated by interface{}? Anyway, i included in the PR support swagger:type object (it did not exists). If you want this support in another PR, tell me, I can do it without problem.

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.

2 participants