swagger-api / swagger-api/swagger-ui
Object with @Pattern is misinterpreted into 'Try it out' view
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: Ubuntu 20.04 and Windows 10
- Browser: Chrome
- Version: 100.0.4896.127 (64 bit)
- Method of installation: Maven/WebJar via springdoc-openapi
- Swagger-UI version: v4.10.3
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Bug is reproducible using an api object with bean-validation @Pattern annotation. If none example attribute is specified into @Schema annotation, Swagger-UI will render a huge value into that api object param (inside 'Parameters' tab of Try it out view).
This unexpected behaviour may exist from v4.6.2. PR: #7829
It's not being taking into account that example field can be null and Swagger-ui is trying to conform "string" type to the regex pattern.
Example Swagger/OpenAPI definition:
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: http://localhost:8080
description: Generated server url
paths:
/api/demo:
get:
tags:
- demo-controller
operationId: retrieveDemo
parameters:
- name: input
in: query
required: true
schema:
$ref: '#/components/schemas/DemoBean'
responses:
'200':
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/DemoBean'
components:
schemas:
DemoBean:
type: object
properties:
Demo Name:
type: string
description: Demo Name field example
Demo Email:
pattern: ^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
type: string
description: Demo Email with bean-validation and example value
example: valid@email.com
Demo email confirm:
pattern: ^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
type: string
description: Demo email confirm with bean-validation and non example value
To reproduce...
Steps to reproduce the behavior:
Check it out this demo project https://github.com/GandalfTheBlack16/demo-swagger
Expected behavior
Field 'demo email confirm' value to be "string"
Screenshots

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
Reproduce the issue with the supplied OpenAPI definition, comparing the Try it out Parameters view for fields with and without an example. Start at the rendering path for object query parameters and pattern-constrained strings, using the linked demo project and PR #7829 as context. Done means the field without an example displays "string" while the field with an example remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100