Skip to content

Improve rendering oneOf: [string, string] #10737

@HenryGessau

Description

@HenryGessau

Content & configuration

Swagger/OpenAPI definition:

swagger: "2.0"
host: localhost
basePath: /v1
tags:
- name: subnets

paths:
 /subnets:
   post:
     tags:
     - subnets
     summary: Create a subnet
     parameters:
     - in: body
       name: body
       required: true
       schema:
         $ref: '#/definitions/Subnet'

definitions:
 CIDRv4:
   type: string
   description: An IPv4 address range in CIDR notation.
   pattern: '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))$'
   example: 10.9.8.0/24
 CIDRv6:
   type: string
   description: An IPv6 address range in CIDR notation.
   pattern: '^(?:(?:(?:[a-f0-9]{1,4}:){6}|(?=(?:[a-f0-9]{0,4}:){0,6}(?:[0-9]{1,3}\.){3}[0-9]{1,3}(?![:.\w]))(([0-9a-f]{1,4}:){0,5}|:)((:[0-9a-f]{1,4}){1,5}:|:)|::(?:[a-f0-9]{1,4}:){5})(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}|(?=(?:[a-f0-9]{0,4}:){0,7}[a-f0-9]{0,4}(?![:.\w]))(([0-9a-f]{1,4}:){1,7}|:)((:[0-9a-f]{1,4}){1,7}|:)|(?:[a-f0-9]{1,4}:){7}:|:(:[a-f0-9]{1,4}){7})(?![:.\w])\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$'
   example: 2001:DB8:8700:2010::/64
 SubnetCIDR:
   type: string
   oneOf:
   - $ref: '#/definitions/CIDRv4'
   - $ref: '#/definitions/CIDRv6'
 Subnet:
   type: object
   required:
   - cidr
   properties:
     cidr:
       $ref: '#/definitions/SubnetCIDR'

Swagger-UI configuration options:

 window.ui = SwaggerUIBundle({
   url: "subnet.yaml",
   dom_id: '#swagger-ui',
   defaultModelRendering: 'model',
   deepLinking: true,
   presets: [
     SwaggerUIBundle.presets.apis,
     SwaggerUIStandalonePreset
   ],
   plugins: [
     SwaggerUIBundle.plugins.DownloadUrl
   ],
   layout: "StandaloneLayout"
 });

Is your feature request related to a problem?

Displays as follows:

Image

Describe the solution you'd like

Display something more like this:

Image

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions