StefH/SwaggerToJavaScriptObject

โ˜… 0Forks 0C#GitHub โ†—Compare

README

SwaggerToJavaScriptObject

A Blazor WebAssembly app that converts Swagger / OpenAPI definitions to JavaScript object declarations.

๐Ÿš€ Live Demo

https://stefh.github.io/SwaggerToJavaScriptObject/

Features

  1. Input โ€” Paste your Swagger 2.0 or OpenAPI 3.0 JSON document into the text area.
  2. Analyze โ€” Click Analyze to extract all type definitions (definitions in Swagger 2.0 or components.schemas in OpenAPI 3.0).
  3. Select types โ€” A list of checkboxes lets you select or deselect the types you want to generate. Use Select All / Deselect All for convenience.
  4. Generate โ€” Click Generate to bundle and dereference the selected types and produce JavaScript const declarations, e.g.:
const petSchema = {
  "type": "object",
  "required": [
    "name",
    "photoUrls"
  ],
  "properties": {
    "id": {
      "type": "integer",
      "format": "int64"
    },
    "category": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        }
      },
      "xml": {
        "name": "Category"
      }
    },
    "name": {
      "type": "string",
      "example": "doggie"
    },
    "photoUrls": {
      "type": "array",
      "xml": {
        "wrapped": true
      },
      "items": {
        "type": "string",
        "xml": {
          "name": "photoUrl"
        }
      }
    },
    "tags": {
      "type": "array",
      "xml": {
        "wrapped": true
      },
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string"
          }
        },
        "xml": {
          "name": "Tag"
        }
      }
    },
    "status": {
      "type": "string",
      "description": "pet status in the store",
      "enum": [
        "available",
        "pending",
        "sold"
      ]
    }
  },
  "xml": {
    "name": "Pet"
  }
};
  1. Copy to clipboard โ€” Copy the generated JavaScript with one click.

Tech stack

Local development

dotnet run --project src/SwaggerToJavaScriptObject/SwaggerToJavaScriptObject.csproj

Then open http://localhost:5000.

Contributors

StefHCopilot

Issues