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

Gibberish shown in example when pattern is used on a field and no defaultValue is provided #9415

Open
ZIRAKrezovic opened this issue Dec 4, 2023 · 1 comment

Comments

@ZIRAKrezovic
Copy link

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

image

Additional context or thoughts

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

No branches or pull requests

2 participants