diff --git a/.env b/.env index a7517dd86df..ae7c41ed892 100644 --- a/.env +++ b/.env @@ -1 +1,11 @@ +# Swagger 2.0 to OpenAPI 3.0.x Converter URL +# Set this to use a custom converter service instead of the default +# Set to 'null' (without quotes) to disable the converter feature +# VITE_SWAGGER2_CONVERTER_URL=https://converter.swagger.io/api/convert + +# Generator base URLs (optional) +# Set these to use custom generator instances for OpenAPI 3.0 and 2.0 code generation +# VITE_OPENAPI3_GENERATOR_BASE_URL=https://custom-generator3.example.com/api +# VITE_OPENAPI2_GENERATOR_BASE_URL=https://custom-generator2.example.com/api/gen + VITE_VERSION=$npm_package_version diff --git a/README.md b/README.md index f3535e35134..5bbce3b4efa 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,39 @@ ## Table of Contents -- [Anonymized analytics](#anonymized-analytics) -- [Getting started](#getting-started) - - [Prerequisites](#prerequisites) - - [Installation](#installation) - - [Usage](#usage) -- [Development](#development) - - [Prerequisites](#prerequisites) - - [Setting up](#setting-up) - - [npm scripts](#npm-scripts) - - [Build artifacts](#build-artifacts) - - [Package mapping](#package-mapping) -- [Documentation](#documentation) -- [Docker](#docker) -- [License](#license) -- [Software Bill Of Materials (SBOM)](#software-bill-of-materials-sbom) +- [SwaggerEditor](#swaggereditor) + - [Table of Contents](#table-of-contents) + - [Anonymized analytics](#anonymized-analytics) + - [Getting started](#getting-started) + - [Prerequisites](#prerequisites) + - [Installation](#installation) + - [Usage](#usage) + - [Development](#development) + - [Prerequisites](#prerequisites-1) + - [Setting up](#setting-up) + - [npm scripts](#npm-scripts) + - [Build artifacts](#build-artifacts) + - [Package mapping](#package-mapping) + - [Documentation](#documentation) + - [Using older version of React](#using-older-version-of-react) + - [npm](#npm) + - [yarn](#yarn) + - [Customization](#customization) + - [Syntax Highlighting Modes](#syntax-highlighting-modes) + - [Environment Variables](#environment-variables) + - [Using preview plugins in SwaggerUI](#using-preview-plugins-in-swaggerui) + - [Standalone mode](#standalone-mode) + - [Utilizing preview plugins via unpkg.com](#utilizing-preview-plugins-via-unpkgcom) + - [Composing customized SwaggerEditor version](#composing-customized-swaggereditor-version) + - [Plugins](#plugins) + - [Presets](#presets) + - [Composing with swagger-ui](#composing-with-swagger-ui) + - [Composing with swagger-ui-react](#composing-with-swagger-ui-react) + - [Docker](#docker) + - [Pre-built DockerHub image](#pre-built-dockerhub-image) + - [Building locally](#building-locally) + - [License](#license) + - [Software Bill Of Materials (SBOM)](#software-bill-of-materials-sbom) ## Anonymized analytics @@ -583,9 +601,12 @@ Both modes support: Environment variables are baked in at build time via Vite's `define` mechanism. The only currently active variable is: -| Variable name | Description | -|-----------------|-----------------------------------------------------------------------------| -| `VITE_VERSION` | Version displayed in the splash screen. Defaults to `$npm_package_version`. | +| Variable name | Description | +| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `VITE_VERSION` | Version displayed in the splash screen. Defaults to `$npm_package_version`. | +| `VITE_SWAGGER2_CONVERTER_URL` | Specifies the URL for the OpenAPI 2.0 to OpenAPI 3.0 converter service. Defaults to `https://converter.swagger.io/api/convert`. Set to `null` to disable conversion. | +| `VITE_OPENAPI3_GENERATOR_BASE_URL` | Specifies the base URL for the OpenAPI 3.0 code generator service. Defaults to `https://generator3.swagger.io/api`. Set to `null` to disable the generator. | +| `VITE_OPENAPI2_GENERATOR_BASE_URL` | Specifies the base URL for the OpenAPI 2.0 code generator service. Defaults to `https://generator.swagger.io/api/gen`. Set to `null` to disable the generator. | Sample values can be found in the `.env` file at the root of the repository. diff --git a/src/plugins/top-bar/components/EditMenu/items/ConvertToOpenAPI30xMenuItem.jsx b/src/plugins/top-bar/components/EditMenu/items/ConvertToOpenAPI30xMenuItem.jsx index af67931b6ca..3c2c239cc60 100644 --- a/src/plugins/top-bar/components/EditMenu/items/ConvertToOpenAPI30xMenuItem.jsx +++ b/src/plugins/top-bar/components/EditMenu/items/ConvertToOpenAPI30xMenuItem.jsx @@ -8,8 +8,9 @@ const ConvertToOpenAPI30xMenuItem = ({ }) => { const DropdownMenuItem = getComponent('DropdownMenuItem'); const isContentTypeOpenAPI20 = editorSelectors.selectIsContentTypeOpenAPI20(); + const converterURL = editorSelectors.selectOpenAPI20ConverterURL(); - return isContentTypeOpenAPI20 ? ( + return isContentTypeOpenAPI20 && converterURL ? ( {children || 'Convert to OpenAPI 3.0.x'} ) : null; }; @@ -18,6 +19,7 @@ ConvertToOpenAPI30xMenuItem.propTypes = { getComponent: PropTypes.func.isRequired, editorSelectors: PropTypes.shape({ selectIsContentTypeOpenAPI20: PropTypes.func.isRequired, + selectOpenAPI20ConverterURL: PropTypes.func.isRequired, }).isRequired, children: PropTypes.node, onClick: PropTypes.func.isRequired, diff --git a/src/plugins/top-bar/selectors.js b/src/plugins/top-bar/selectors.js index 168055b0ccb..59646313766 100644 --- a/src/plugins/top-bar/selectors.js +++ b/src/plugins/top-bar/selectors.js @@ -6,7 +6,13 @@ import { SUCCESS_STATUS, IDLE_STATUS } from './reducers.js'; * editor state plugin selectors. */ -export const selectOpenAPI20ConverterURL = () => 'https://converter.swagger.io/api/convert'; +export const selectOpenAPI20ConverterURL = () => { + const converterUrl = import.meta.env.VITE_SWAGGER2_CONVERTER_URL; + if (converterUrl === 'null') { + return null; + } + return converterUrl || 'https://converter.swagger.io/api/convert'; +}; /** * editorTopBar state plugin selectors. @@ -14,10 +20,23 @@ export const selectOpenAPI20ConverterURL = () => 'https://converter.swagger.io/a export const selectEditorTopBarState = (state) => state; -export const selectOpenAPI3GeneratorServerListURL = () => - 'https://generator3.swagger.io/api/servers'; +export const selectOpenAPI3GeneratorBaseURL = () => { + return import.meta.env.VITE_OPENAPI3_GENERATOR_BASE_URL || 'https://generator3.swagger.io/api'; +}; + +export const selectOpenAPI2GeneratorBaseURL = () => { + return import.meta.env.VITE_OPENAPI2_GENERATOR_BASE_URL || 'https://generator.swagger.io/api/gen'; +}; + +export const selectOpenAPI3GeneratorServerListURL = () => { + const baseUrl = selectOpenAPI3GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/servers` : 'https://generator3.swagger.io/api/servers'; +}; -export const selectOpenAPI3GenerateServerURL = () => 'https://generator3.swagger.io/api/generate'; +export const selectOpenAPI3GenerateServerURL = () => { + const baseUrl = selectOpenAPI3GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/generate` : 'https://generator3.swagger.io/api/generate'; +}; export const selectOpenAPI3GeneratorServerListStatus = (state) => state.get('openAPI3GeneratorServerListStatus') || IDLE_STATUS; @@ -34,10 +53,15 @@ export const selectOpenAPI3GeneratorServerList = createSelector( } ); -export const selectOpenAPI3GeneratorClientListURL = () => - 'https://generator3.swagger.io/api/clients'; +export const selectOpenAPI3GeneratorClientListURL = () => { + const baseUrl = selectOpenAPI3GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/clients` : 'https://generator3.swagger.io/api/clients'; +}; -export const selectOpenAPI3GenerateClientURL = () => 'https://generator3.swagger.io/api/generate'; +export const selectOpenAPI3GenerateClientURL = () => { + const baseUrl = selectOpenAPI3GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/generate` : 'https://generator3.swagger.io/api/generate'; +}; export const selectOpenAPI3GeneratorClientListStatus = (state) => state.get('openAPI3GeneratorClientListStatus') || IDLE_STATUS; @@ -54,10 +78,15 @@ export const selectOpenAPI3GeneratorClientList = createSelector( } ); -export const selectOpenAPI2GeneratorServerListURL = () => - 'https://generator.swagger.io/api/gen/servers'; +export const selectOpenAPI2GeneratorServerListURL = () => { + const baseUrl = selectOpenAPI2GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/servers` : 'https://generator.swagger.io/api/gen/servers'; +}; -export const selectOpenAPI2GenerateServerURL = () => 'https://generator.swagger.io/api/gen/servers'; +export const selectOpenAPI2GenerateServerURL = () => { + const baseUrl = selectOpenAPI2GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/servers` : 'https://generator.swagger.io/api/gen/servers'; +}; export const selectOpenAPI2GeneratorServerListStatus = (state) => state.get('openAPI2GeneratorServerListStatus') || IDLE_STATUS; @@ -74,10 +103,15 @@ export const selectOpenAPI2GeneratorServerList = createSelector( } ); -export const selectOpenAPI2GeneratorClientListURL = () => - 'https://generator.swagger.io/api/gen/clients'; +export const selectOpenAPI2GeneratorClientListURL = () => { + const baseUrl = selectOpenAPI2GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/clients` : 'https://generator.swagger.io/api/gen/clients'; +}; -export const selectOpenAPI2GenerateClientURL = () => 'https://generator.swagger.io/api/gen/clients'; +export const selectOpenAPI2GenerateClientURL = () => { + const baseUrl = selectOpenAPI2GeneratorBaseURL(); + return baseUrl ? `${baseUrl}/clients` : 'https://generator.swagger.io/api/gen/clients'; +}; export const selectOpenAPI2GeneratorClientListStatus = (state) => state.get('openAPI2GeneratorClientListStatus') || IDLE_STATUS;