Skip to content
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

issue-503: added type map in example value #683

Merged
merged 15 commits into from
Nov 20, 2020
Merged

Conversation

Arrim
Copy link
Contributor

@Arrim Arrim commented Apr 22, 2020

Describe the PR
Add example tag for maps

Relation issue
#503

Additional context
Example:

type MyStruct struct {
   MyMap map[string]string 'json:"my_map" swaggertype:"map,string" example:"key1:value1,key2:value2"'
 }

@sdghchj
Copy link
Member

sdghchj commented Apr 23, 2020

  1. Swagger have no real map or dictionary type, so it use object type with additionalProperties alternatively. And also, schemaType have no chance to be "map" in your PR. You can test it.
  2. I found swagger editor doesn't support example for object type. You can confirm it.

@Arrim
Copy link
Contributor Author

Arrim commented Apr 28, 2020

@sdghchj This type is needed to form an example json request with an arbitrary data set. For instance:
{
"data": {
"myKey1": "myData1",
"myKey2": "myData2",
"myKey3": "myData3",
}
}
I know that maybe this is a design error, but sometimes it is necessary. At the moment, swag is not able to generate such data.
And yes, I checked with my example - it works.

@sdghchj
Copy link
Member

sdghchj commented Apr 29, 2020

@Arrim Can you show your exmaple result?

@codecov-commenter
Copy link

codecov-commenter commented Jun 4, 2020

Codecov Report

Merging #683 (30b0f37) into master (09f9621) will increase coverage by 1.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #683      +/-   ##
==========================================
+ Coverage   82.64%   83.70%   +1.06%     
==========================================
  Files           8        8              
  Lines        1642     1663      +21     
==========================================
+ Hits         1357     1392      +35     
+ Misses        168      160       -8     
+ Partials      117      111       -6     
Impacted Files Coverage Δ
parser.go 79.60% <100.00%> (+0.86%) ⬆️
schema.go 98.71% <100.00%> (+14.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09f9621...30b0f37. Read the comment docs.

@sdghchj sdghchj mentioned this pull request Sep 1, 2020
@rogaha
Copy link

rogaha commented Sep 16, 2020

any updates here?

@Arrim
Copy link
Contributor Author

Arrim commented Oct 17, 2020

Hi. Sorry for the delay. I updated my code.
Swagger really not support map type. But map type in go is an object in swagger(JSON).
I use object type for a map and check child type in the "defineTypeOfExample" method. If child type not set returned error. And if the child typeset and correct, I add an example in documentation.

I add an example code in the repository, where you may check the correct result.

@Arrim
Copy link
Contributor Author

Arrim commented Nov 20, 2020

@sdghchj @easonlin404 Hi. You can merge pr?

Copy link
Member

@sdghchj sdghchj left a comment

Choose a reason for hiding this comment

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

LGTM

@sdghchj sdghchj merged commit c9056f0 into swaggo:master Nov 20, 2020
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.

5 participants