DoubleK
DoubleK

Reputation: 562

Swagger UI marking parameters as group

Is it possible to somehow mark properties so that it's understandable which field should be set in SwaggerUI when sending request.

For example we have a route for payments, which has payment_type property that can hold values like paypal, credit_card, crypto, etc. and based on that field we need to fill different properties like below.

{
  "payment": 0,
  "paypal": "[email protected]",
  "cryptocurrency": "test",
  "wallet_address": "test",
  "swift": "test",
  "iban": "test",
  "account_name": "test",
  "bank_name": "test"
}

Is it possible to mark them somehow so that they are grouped, like for crypto cryptocurrency and wallet_address should be set, while for bank transfer swift, iban, account_name and bank_name should be set.

Upvotes: 1

Views: 1328

Answers (1)

Helder Sepulveda
Helder Sepulveda

Reputation: 17584

No, there is no such an option. We are limited by the OpenAPI-Specification, read the Parameter Object section to see a list of available fields.

Now knowing that limitation not everything is lost, here are a few options:

  • You do have description that is a good place to add your details.

  • You also can go with a Specification Extension but that will not be something that the swagger-ui will support by default, if you need the UI to take action on your extension(s) you will need to code it.

  • Another option pointed out in the comments by @Helen is using discriminator but that is not currently supported by the swagger-ui:
    https://github.com/swagger-api/swagger-ui/issues/2438

Upvotes: 1

Related Questions