Swagger UI - Update form button text

Viewed 373

I have a YAML file with the following in it:

    - name: parameters
      in: query
      required: true
      description: ""
      style: form
      explode: true
      schema:
        type: array
        items:
          type: string

In the Swagger UI, it allows the user to click a button to add individual parameters. example:

However, I would like that button to say something else.. like Add a Parameter and the text box to say something like single parameter so that the user doesn't get confused and add multiple parameters in a single text box.

I'm using the standalone swagger ui bundle and I cannot see where this button is even being generated. Looks like it is react that is generating the button (i have inspected it in chrome), but I cannot see how to edit it.

It this possible?

1 Answers

To change the text in the input box, add an example to the parameter schema:

      schema:
        type: array
        items:
          type: string
          example: single parameter  # <--------

You can also add an array-level example:

      schema:
        type: array
        items:
          type: string
          example: single parameter
        example:     # <--------
          - param 1
          - param 2

This will display multiple input boxes initially, so that it's a bit more clear that each input takes a single value:


The "Add ... item" button text, hovever, is hard-coded in the Swagger UI source code:
https://github.com/swagger-api/swagger-ui/blob/master/src/core/json-schema-components.jsx#L269

To change it you'll have to fork and rebuild Swagger UI and use your forked version instead of the standard version.

Related