swagger-api / swagger-api/swagger-ui
When Attribute is called EmailAddress it presents weird example instead of string
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: Windows
- Browser: Chrome
- Version: all
- Method of installation: [e.g. npm, dist assets]
- Swagger-UI version: [e.g. 3.X]
- Swagger/OpenAPI version: [OpenAPI 3.0]
- I'm using .net Swashbuckle.AspNetCore but the problem is on the UI
Describe the bug you're encountering
When the attribute is named emailAddress in the CreateUserCommand Class the example that appears for this field is a long string of random characters instead of "string", as it does for other attributes. I believe the reason for this lies in the pattern attribute we can find for this component in the schema session.
"components": {
"schemas": {
"CreateUserCommand": {
"type": "object",
"additionalProperties": false,
"required": [
"emailAddress"
],
"properties": {
"emailAddress": {
"type": "string",
"minLength": 1,
"pattern": "^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?$",
"nullable": false
This pattern doesn't appear for other attributes. I tried with both email_address and emailaddress and both failed to have string as an example. below you have an example in which I updated the object with additional fields like test, email, address and email_adress. and both email_address and emailAddress fail to display string in swagger ui.
SWAGGER UI Output for CreateUserCommand Class with some extra fields for testing purposes
{
"test": "string",
"email": "string",
"address": "string",
"email_address": "?/30lj4i*.#4i09/y1h5+r#07h3wv|*{o1uf2*n93&zh75}1|'^3`&~.4uyy2y?|4aai15`v?7!1'o=m56`i+y9foi=?oq6ixtiw.5-r+}.3709`6$%q90$`3'?lrk7{$3er^6/~.747^^j/14^h^?56si2h9kd}%6o}1-5x9z!s1!{6b/78}z1b6mh+w}68|^w2#j9339}?6wm2_8#a*5.u?3081nze~94.`e|$z6w-$&hi`#0k&!}jv6&z3s2={{`~35ch-9_n33!$9667.21?%%dvz^a_v{1%84-~5k0w05.^ew^6f2l1is9w2=#3a}p?5r'uu_105e293{28-04e+%+eq5.70*47923h!1+r5l'8y+%7`'q28g6rp7{.$|9x^9z&7~y+uh!0#++1lf1h5uv}883h2u3#a55{|$6x94`3s_o7ogh2/^i'0.f21~k16ryhz{1ix/~9#ak/4wuvz99y'_2758i69|!|#27_i-#95rlxr*w3ib{5vbfz07.3497$z~89-xfi0^wm1#632rh`^=h&701b6/-+6m!?%!%2=6?}9y*r0zo&%4{azvgbi9btc4#4*+.`0s8c_${+k`&362k_5n+s4jgl%~3/y60?+3{pjwrm`${147%u|d2?v&$?_@9~.~_3~-7~~9..74_~7_~~~.o~-~~56.ros~-~__--~_.-xf.~-2.26.h~g2.--9.1.1.b.k.s.45.~-0_~7-~_._9r60~.3h2_~._~87v~6m_-y3__-x.~-0-___in-.--~.~-jazh~i~t2__~2..ah1_c~8hj6-..89._~~f..n.f.c~.--9_4_~-_5_~-h~~q-..~._z...56~~-n2_07u~1os~3_..9j.q-_pj82n~-~p.f.i.qc_~.kuems_.85~~__~_hcr29_.6k-~-kxc_3-~.j-f~w~-q.w.~-_-_k_.18c_-0--~9~p~fx_-s~.d8--~2-g12_.-~g6_3~~.69j__~~6d.t.a.2...xll_.z-..5_~~7-m_t_~5-k~.z~g6~__~~_~6~f~__e6~-.~_ss-i--.5~1b~~8k0~._-.-9_x_w2._-ne__-7q.dc8..q.i.5.h.",
"addressEmail": "string",
"emailAddress": "\"\\e\\rOH\\n \t \t\t\t \t\t\t\t\t \ts\\\t \t \t\t\t\t \t\t\t\t\t \t\t \t \t\t \t \t\t\t \t \t \t\t\t\t \t\t \t \t\t \t\t \t \t \t \t\t\t\t\t\t \t \t\t\t \t \t\t\t\t \t\t\t \t\t \t \t \t \t \t\t\t\t\t\t \t\t\t \t\t\t\t \t\t \t \t\t \t \t\t\t \t\t\t\t \t\t\t \t\t \\0\\n \t \t \t \t \t \t \t\t\t \t\t\t\t\t\t \t \t\t\t \t \t \t \t \t\t\t\t \t\t \tx0dx0a\t\t \t\t \t \t\t \t \t\t \t \t\t \t \t \t \t \t \t \\w!\\ex \t\t\t\t \t\t x0dx0a \t\t \t \t \t\t \t \t\t \t\t \t \t \t\t \t\t\t\t\t\t \t\t \t\t \t \t \t\t\t \t \t\t \t \\w \t\t \t \t\t\t\t \t \t\t\t \t\t \t \t \t\t\t \t\t\t \t \t\t\t \t\t \t \t\t\t\t \t \t \t \t \t \\\t \t \t \t \t \t\t\t\t \t\t \t \t\t \t\t \t\t \t\t \t\t \t\t\t\t \t\t \t \t\t \t \t\t\t\t\t\t \t\t\t \t\t\t\t\t\t \t \t \t\t\t x0dx0a\t \t \t \t\t \t \t\t \t \t \t \t\t\t\t\t \t \t\t \t\t\t \t \t \t \t\t\t \t\t \t\t\t\t\t \t\t \t\t \t\t \t \t\t \t \t \t \t\t\t \t \t \t \t \t \t \t\t\t \t \t \t \t\t\t \t\t\t \t \t\t \t\t \t \t \t\t\t \t \\\t \t \t\\;\\kl!d\\Nvo\t \t\t\t \\e%o\t \t\t \t \t\t\t \t\t\t\t\t\t \t\t\t \t \t\t\t\t \t\t\t\t\t\t \t\t\t \t \t\t\t\t \t\t \t \t\t\t \t\t\t\t \t\t \t\t \t\t\t \t\t \t \t\t \\l \t\t \t \t\t \t\t \t \t \t\t \t\t\t \t\t\t\t \t\t\t\t\t\\!\t\t\t \t \t\t\t\t\t\t\t \t\t \t \t\t \t\t\t \t \tx0dx0a \t \t \t\t\t\t \t\t \t \t\t\t \t \t \t\t\t \t \t\t\t \t\t \t \t\t\t\t \t \t\t\t\t \t\t \t\t\t \t\t1 \t\t\t\t\t\t \t \t \t\t \t\t\t\t \t \t \t\t \t \t\t\t\t \t\t x0dx0a\t\t\t \t \t\t \t \t\t \t\t\t \t \t\t \t\t \t \t\t \t\t \t \t \t\t e\\g! \t x0dx0a\t \t \t \t\t \t \t\t \t \t\t \t \t\t\t \t \t \t ! \t \t\t \t\t\t\t\t\t\t \t\t \t \t\t \t \t\t\t\t \t \t\t\t\t \t \t \t\t \t \t\t\t\t \t\t\t \t\t \t\t\t \t \t\t \t\t\\rt\t\t\t \t\t\t \t\t\t \t\tx0dx0a\t \t \t\t\t\t \t \t\t \t\t\t \t \t \t\t\t \t \t\t \t \t\t\t \t \t \t \t\t \t \t \t \t\t\t \t\t\t\t\t\t\t \t\t\t\t \t \t \\\t\t \tx0dx0a\t\t\t\t \t \t\t\t\t\t \t\t \t \t \t \t\t\t \t \t\t \t \t\t\t\t\t\t\t \t\t\t\t\t\t \t \t\t \t \t\t\t\t \t \t\t\t\t \t\t\t \t \t\t \t \t\t\\e \t \t \t \t \t\t\t \t \t\t\t \t \t\t \t \t\t \t\t x0dx0a\t \t\t\t\t \t\t \t\t \\\\nv!\t \t\t\t \t\t \t\t \t\t \t\t\t\t\t\t \t \t\t \t \t\t\t\t \\\\7\t \t \t \t \t\t\t\t\t\t \t \t \t \t\t \t \t \t \t\t\t \t \t \t \t\t\t \t \t \t \t \t \t\\o\t \t \t \t \t \t \t\t \t\t\t\t \t \t\t\t \t \t\t \t \t\t \t\t \t\t \t \t\tv!<j\\\t\t ! \t \t \t\t\t \t \t \t\t \t \t\t\t \t \t\t \t\t \t \t\t \t\t\t\t\t\t\t\t \twq\t \t\t\t\t \t \t\t \t\t\t\t\t \t \t \t\t \t\t\t\t\t \\\\7\t :\t \t\t \t\t \t\t \t\t \t \t \t \t \t\t \t \t\t \t\t\t\t \t \t\t\t \t\t \t\t \t \t\t\t\t\t \t \t\t\tx0dx0a\t \t \t\t \t \t\t\t\t\t \t \t \t\t\t \t\t\ts\\\\xk \t \t\t\t\t\t \t\t \t\t \t\t\t\t\t\t\t\t \t\t \t \t\t\t \t\t\t\t \t\t \t\t x0dx0a \t \t\t\t\t\t\t \t\t\t\t \t \t\t\t \t\t \t\t \t\t\t \t\t \t\t\t\t\t\t\t\t\t \t\t \t\\r\t \t\t\t \t\t\t\t\t \t \t\t \t\t\t \t\t \t\t\t\t \t\t\t \t \t\t\t\t \t \t\t \t\t\t\t\t \t \t \t \t\t\t\t x0dx0a \t \t\t \t\t \t\t \t \t \t \t\t \t\t\t \t \t\t\t \t \t\t\t\t\t\t\t \t \t\t\t \t\t\t \t\t \t \t\t \t \t\t \td \t\t \t \t\t \t \t\t\t\t \t \t\t \t \t \t\t\t \t \t\t\t \t\t\t \t\t\t \t\t\t\t \t\t\t\t \t\t\t \t \t\t\t \t\t\t\t \t\tw \t\t \t \t \t \t\t \t\t \t\t \t\t \t \t \t\t\t \t \t\t \t\t\t \t\t \t \t\t\t\t\t \t\t\t \t \t\t \t\t\\h\t \t \t \t\t \t\t \t\t\t \t \t \t\t \t\t \t\t\t \t\t\t \t \t \t\t \t\t \t \t \t\t \t\t\t\t\t \t \t\t \t \t\t\t\t\t \t\t\t \t \t\t \t\t \t \t\t\t \t\t\t\t\t\t \t\t\t\t\t\t\t\t \t\t \t\t\t x0dx0a\t\t \t \t \t\t\t \t \t\t \t \t \t\t\\7\t \t\t\t\t \t\t\t \t \t \t \t \t \t \t \t \t \\\t \t \t\t\t\t \t\t \t\t \t\tx0dx0a \t \t\t \t \t\t\t \t\t \t\t\t\t \t \t \t\t \t \t\t\t \t\t \t\t\t \t\t \t %jg\t\t\t \t \t \t\t \t\\\\c \t \t \t\t\t\t! \t\t \t \t \t \t\t\t\t\t\t \t \t\t \t \t \t \t\t \t\t \t\t \t\t \t \t \t \t \t \t\t \t\t \t\t\t\t\t\t \t\"@9.-~1ski-_~~-4c.._f~_4j_.r.1.~9~.~.-_0_07..v.q.6-~-0j.l_5_8.___kt-f8.~-_-9~.--____-_t~._qi~~~1~.~_.1.ym~t..~~..3.~-.-p-6-8r3_v__-~.5._y~~a~~-~.p--h.s._5_---_a..-x--~_-_~~.8~5_--__--~x8~~3~0._.9~0~.14_~d_~.-8~..-8-4~-..~~-~_-z3.e_.5_-_9-5-_7.~w_s-5_e.5_9~~w8~3_.--~..~--b5.i~-20-~-~e~i9_....~-~.~_e.4_--__~-6_._i_~9_~_~9-_~~z~~37..w..wk_v--_u.~k-_~_.~dy_~~g.h.0.~~~_x__~.~6_.~t~_..4~2~.~9p7.7~k~1~n-9-h.1.9.~__.__f.b9__s6r---~.n~d-~~~_-2vv~~_~_.-~--xc__~qh..-u~~_-~.~~z~j3-e.~_.-p~..v54z-n3r.~~gq-_.~s9.hs_.--_~.~~..o5~~-93~_~62~~-.~_~._.q_5-~7--.~_--j_._-.-~.9.0.h.6v-.k."
}
To reproduce...
I don't know how to reproduce has it only happens with one class so far. but it seems a pattern attribute is being added inadvertently to the schema of the CreateUserCommand for unknown reasons.
Open Api definition
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached openapi.json and inspect the CreateUserCommand schema, especially the emailAddress and email_address properties and their pattern values. Compare the Swagger UI examples for these fields with the other string fields; done means the affected fields display an appropriate string example rather than the generated random values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100