swagger-api / swagger-api/swagger-ui

Feature: Example generation for component schemas with anyOf types

Open
#5,804 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

specification: 3.x type: feature
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Content & configuration

Swagger/OpenAPI definition:

openapi: 3.0.2
info:
 title: Fast API
 version: 0.1.0
paths:
 /demo:
   post:
     summary: Demo
     operationId: demo_demo_post
     requestBody:
       content:
         application/json:
           schema:
             $ref: '#/components/schemas/SomeModel'
       required: true
     responses:
       '200':
         description: Successful Response
         content:
           application/json:
             schema: {}
       '422':
         description: Validation Error
         content:
           application/json:
             schema:
               $ref: '#/components/schemas/HTTPValidationError'
components:
 schemas:
   HTTPValidationError:
     title: HTTPValidationError
     type: object
     properties:
       detail:
         title: Detail
         type: array
         items:
           $ref: '#/components/schemas/ValidationError'
   SomeModel:
     title: SomeModel
     type: object
     properties:
       a:
         title: A
         anyOf:
         - type: array
           items:
             type: string
         - type: string
         default: []
       b:
         title: B
         type: array
         items:
           type: string
         default: []
   ValidationError:
     title: ValidationError
     required: [loc, msg, type]
     type: object
     properties:
       loc:
         title: Location
         type: array
         items:
           type: string
       msg:
         title: Message
         type: string
       type:
         title: Error Type
         type: string

Swagger-UI configuration options:

    const ui = SwaggerUIBundle({
       url: '/openapi.json',
   oauth2RedirectUrl: window.location.origin + '/docs/oauth2-redirect',
       dom_id: '#swagger-ui',
       presets: [
       SwaggerUIBundle.presets.apis,
       SwaggerUIBundle.SwaggerUIStandalonePreset
       ],
       layout: "BaseLayout",
       deepLinking: true
   })
Is your feature request related to a problem?

Example is not generated for component schema with anyOf types.

Describe the solution you'd like

Generate the example with the first type in the anyOf list.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in Swagger UI using the supplied OpenAPI definition and configuration, focusing on the SomeModel schema's a property. Trace the example-generation entry point to see why an anyOf schema produces no example; done means the generated example uses the first type in the anyOf list.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
documentation, frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.