swagger-api / swagger-api/swagger-ui

Add option to generate CURL in summary if OpenApi definition has examples

Open
#8,050 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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.1",
 "info": {
   "title": "Test",
   "description": "Test.",
   "contact": {
     "name": "Test",
     "url": "https://test.com",
     "email": "test@test.te"
   },
   "version": "v1.0"
 },
 "paths": {
   "/api/v1.0/{entityId}/someaction": {
     "get": {
       "tags": [
         "Bucket",
       ],
       "summary": "Some summary.",
       "description": "Sample descript",
       "operationId": "SampleOpId",
       "parameters": [
         {
           "name": "entityId",
           "in": "path",
           "description": "The identifier of the entity.",
           "required": true,
           "schema": {
             "type": "string",
             "format": "uuid"
           },
           "example": "ca87606e-c758-46ad-af1e-60c84ffcacef"
         }
       ],
       "responses": {
         "200": {
           "description": "Returns the information about bucket existing in file storage.",
           "content": {
             "application/json": {
               "schema": {
               }
             }
           }
         }
       }
     }
   }
 },
 "components": {
   "schemas": {}
 }
}
Is your feature request related to a problem?

No

Describe the solution you'd like

If we hit TryItOut and Execute there is sample curl displayed.
If example is present for all required parameters curl can be generated before clicking Execute and be shown, eg below Summary

Describe alternatives you've considered

Plugin, but from initial testing, whole Operation component needs to be overriden, and it later on would be hard to mantain.

Additional context

I can prepare PR if You're interested

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

Start with the Operation component and trace the TryItOut and Execute flow to see how the existing sample curl is produced. Check how examples for all required parameters are exposed before execution. Done means the Summary can display a generated curl when those examples are available, without requiring Execute.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.