swagger-api / swagger-api/swagger-ui
Gibberish shown in example when pattern is used on a field and no defaultValue is provided
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: 119
- Method of installation: WebJar (*)
- Swagger-UI version: 5.10.3
- Swagger/OpenAPI version: OpenAPI 3
(*) WebJar downloads a distribution from github and copies over your dist folder, see https://github.com/webjars/swagger-ui/blob/master/pom.xml#L22 and https://github.com/webjars/swagger-ui/blob/master/pom.xml#L110
Content & configuration
Example Swagger/OpenAPI definition:
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: http://localhost:8080
description: Generated server url
tags:
- name: user-v1
description: User v1 API
paths:
/users/v1:
get:
tags:
- user-v1
summary: Find Users based on filter criteria
operationId: get
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
required:
- email
- username
type: object
properties:
username:
pattern: "^(?=.{4,256}$)(?:[a-zA-Z\\d]+(?:[.\\-_@][a-zA-Z\\d])*)+$"
type: string
description: User name of a given user
email:
pattern: "^[\\w-.]+@([\\w-]+\\.)+[\\w-]{2,4}$"
type: string
description: E-mail of a given user
description: Properties for creation of a user
Swagger-UI configuration options:
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout" ,
"configUrl" : "/v3/api-docs/swagger-config",
"validatorUrl" : ""
});
//</editor-fold>
};
Not sure what this is, but I have:
http://localhost:8080/swagger-ui/index.html#/user-v1/get
Describe the bug you're encountering
When a pattern is added to a schema property, and no default value is provided, the example shown in swagger ui is literal gibberish.
To reproduce...
Steps to reproduce the behavior:
The schema is provided as-is. I have first encountered this using a spring-boot application that I put at
https://github.com/ZIRAKrezovic/openapi-report
Requires Java 17
Build and run with:
./mvnw clean install spring-boot:run
Navigate to http://localhost:8080/swagger-ui/index.html#/user-v1/get
Expected behavior
I would expect a sane example value is shown on the UI
Screenshots
Additional context or thoughts
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
Run the supplied Spring Boot reproduction with ./mvnw clean install spring-boot:run, then open the User operation at /swagger-ui/index.html#/user-v1/get using the provided OpenAPI schema. Inspect how examples are rendered for the username and email patterns; done means the UI shows sane example values when no defaultValue is supplied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100