forked from admin/services_core
Update Database dan ALL yang di butuhkan
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
dist/
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
[node-production]
|
||||
maintained node versions
|
||||
|
||||
[node-development]
|
||||
node 24
|
||||
|
||||
[browser-production]
|
||||
> 1%
|
||||
last 2 versions
|
||||
Firefox ESR
|
||||
not dead
|
||||
|
||||
[browser-development]
|
||||
last 1 chrome version
|
||||
last 1 firefox version
|
||||
last 1 safari version
|
||||
|
||||
[isomorphic-production]
|
||||
> 1%
|
||||
last 2 versions
|
||||
Firefox ESR
|
||||
not dead
|
||||
maintained node versions
|
||||
|
||||
[isomorphic-development]
|
||||
last 1 chrome version
|
||||
last 1 firefox version
|
||||
last 1 safari version
|
||||
node 24
|
||||
@@ -0,0 +1,565 @@
|
||||
# Skill Usage Example: Adding OAS 4.0 Support
|
||||
|
||||
This document demonstrates how to use the `/add-oas-support` skill to add OpenAPI 4.0 support to Swagger UI.
|
||||
|
||||
## Scenario
|
||||
|
||||
You want to add support for OpenAPI Specification 4.0 (a hypothetical major version) to Swagger UI. OAS 4.0 includes:
|
||||
- New `workflows` top-level field
|
||||
- New `asyncAPI` authentication type
|
||||
- Updated JSON Schema to Draft 2024
|
||||
- Enhanced callback syntax
|
||||
- New `info.license.attribution` field
|
||||
|
||||
## Step-by-Step Usage
|
||||
|
||||
### 1. Start the Skill
|
||||
|
||||
```bash
|
||||
/add-oas-support --version 4.0 --type major
|
||||
```
|
||||
|
||||
### 2. Answer Questions
|
||||
|
||||
Claude will ask you questions about the new version:
|
||||
|
||||
**Q: What is the exact version number?**
|
||||
A: 4.0
|
||||
|
||||
**Q: Is it a major or minor version?**
|
||||
A: Major (breaking changes from OAS 3.x)
|
||||
|
||||
**Q: Does it use a new JSON Schema version?**
|
||||
A: Yes, JSON Schema Draft 2024
|
||||
|
||||
**Q: What are the new top-level fields?**
|
||||
A: `workflows` - defines reusable workflow definitions
|
||||
|
||||
**Q: What features are added/removed/changed?**
|
||||
A:
|
||||
- Added: `workflows` object for workflow automation
|
||||
- Added: `asyncAPI` authentication type
|
||||
- Added: `info.license.attribution` field
|
||||
- Changed: Callback syntax enhanced with workflow references
|
||||
- Removed: Deprecated `x-` extension fields from OAS 3.0
|
||||
|
||||
**Q: Are there new authentication types?**
|
||||
A: Yes, `asyncAPI` type for asynchronous authentication flows
|
||||
|
||||
### 3. Claude Creates Plugin Structure
|
||||
|
||||
Claude will execute:
|
||||
|
||||
```bash
|
||||
mkdir -p src/core/plugins/oas40/{auth-extensions,oas31-extensions,spec-extensions,components/auth,wrap-components}
|
||||
```
|
||||
|
||||
### 4. Claude Generates Files
|
||||
|
||||
#### 4a. Version Detection (src/core/plugins/oas40/fn.js)
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
export const isOAS40 = (jsSpec) => {
|
||||
const oasVersion = jsSpec.get("openapi")
|
||||
return (
|
||||
typeof oasVersion === "string" &&
|
||||
/^4\.0\.(?:[1-9]\d*|0)$/.test(oasVersion)
|
||||
)
|
||||
}
|
||||
|
||||
export const createOnlyOAS40Selector =
|
||||
(selector) =>
|
||||
(state, ...args) =>
|
||||
(system) => {
|
||||
if (system.getSystem().specSelectors.isOAS40()) {
|
||||
const selectedValue = selector(state, ...args)
|
||||
return typeof selectedValue === "function"
|
||||
? selectedValue(system)
|
||||
: selectedValue
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// ... other factory functions
|
||||
```
|
||||
|
||||
#### 4b. Main Plugin Export (src/core/plugins/oas40/index.js)
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import afterLoad from "./after-load.js"
|
||||
import {
|
||||
isOAS40,
|
||||
createSystemSelector,
|
||||
createOnlyOAS40Selector,
|
||||
createOnlyOAS40SelectorWrapper,
|
||||
createOnlyOAS40ComponentWrapper,
|
||||
} from "./fn.js"
|
||||
|
||||
import Workflows from "./components/workflows.jsx"
|
||||
import AsyncAPIAuth from "./components/auth/async-api-auth.jsx"
|
||||
import OAS40License from "./components/license.jsx"
|
||||
// ... other imports
|
||||
|
||||
const OpenAPI40Plugin = ({ fn }) => {
|
||||
return {
|
||||
fn: {
|
||||
oas40: {
|
||||
isOAS40,
|
||||
createSystemSelector,
|
||||
createOnlyOAS40Selector,
|
||||
createOnlyOAS40SelectorWrapper,
|
||||
createOnlyOAS40ComponentWrapper,
|
||||
},
|
||||
},
|
||||
components: {
|
||||
Workflows,
|
||||
AsyncAPIAuth,
|
||||
OAS40License,
|
||||
},
|
||||
wrapComponents: {
|
||||
// Wrap existing components
|
||||
},
|
||||
statePlugins: {
|
||||
spec: {
|
||||
selectors: {
|
||||
isOAS40: createSystemSelector(selectIsOAS40),
|
||||
workflows: createOnlyOAS40Selector(selectWorkflows),
|
||||
},
|
||||
wrapSelectors: {
|
||||
isOAS31: isOAS31SelectorWrapper,
|
||||
isOAS3: isOAS3SelectorWrapper,
|
||||
},
|
||||
},
|
||||
auth: {
|
||||
wrapSelectors: {
|
||||
definitionsToAuthorize: definitionsToAuthorizeWrapper,
|
||||
},
|
||||
},
|
||||
oas40: {
|
||||
selectors: {},
|
||||
},
|
||||
},
|
||||
afterLoad,
|
||||
}
|
||||
}
|
||||
|
||||
export default OpenAPI40Plugin
|
||||
```
|
||||
|
||||
#### 4c. Workflows Component (src/core/plugins/oas40/components/workflows.jsx)
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
const Workflows = ({ specSelectors, getComponent }) => {
|
||||
const workflows = specSelectors.workflows()
|
||||
|
||||
if (!workflows || !workflows.size) {
|
||||
return null
|
||||
}
|
||||
|
||||
const Operations = getComponent("operations", true)
|
||||
|
||||
return (
|
||||
<div className="opblock-tag-section">
|
||||
<h2 className="opblock-tag">Workflows</h2>
|
||||
<div className="opblock-description-wrapper">
|
||||
<p>
|
||||
Reusable workflow definitions that can be referenced from operations.
|
||||
</p>
|
||||
</div>
|
||||
{workflows.entrySeq().map(([workflowName, workflow]) => (
|
||||
<div key={workflowName} className="opblock-workflow">
|
||||
<h3>{workflowName}</h3>
|
||||
<p>{workflow.get("description")}</p>
|
||||
{/* Render workflow steps */}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Workflows.propTypes = {
|
||||
specSelectors: PropTypes.object.isRequired,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
export default Workflows
|
||||
```
|
||||
|
||||
#### 4d. AsyncAPI Auth Component (src/core/plugins/oas40/components/auth/async-api-auth.jsx)
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
const AsyncAPIAuth = ({ schema, name, getComponent, onChange, authorized }) => {
|
||||
const authValue = authorized && authorized.getIn([name])
|
||||
const Input = getComponent("Input")
|
||||
const Button = getComponent("Button")
|
||||
|
||||
return (
|
||||
<div className="auth-container">
|
||||
<h4>AsyncAPI Authentication</h4>
|
||||
<p>{schema.get("description")}</p>
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Enter async API key"
|
||||
value={authValue?.get("key") || ""}
|
||||
onChange={(e) => onChange({ key: e.target.value })}
|
||||
/>
|
||||
<Button className="btn modal-btn auth authorize">Authorize</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
AsyncAPIAuth.propTypes = {
|
||||
schema: PropTypes.object.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
authorized: PropTypes.object,
|
||||
}
|
||||
|
||||
export default AsyncAPIAuth
|
||||
```
|
||||
|
||||
### 5. Claude Registers Plugin
|
||||
|
||||
Updates `src/core/presets/apis/index.js`:
|
||||
|
||||
```javascript
|
||||
import OpenAPI40Plugin from "../../plugins/oas40/index.js"
|
||||
|
||||
export default function PresetApis() {
|
||||
return [
|
||||
BasePreset,
|
||||
OpenAPI30Plugin,
|
||||
JSONSchema202012Plugin,
|
||||
JSONSchema202012SamplesPlugin,
|
||||
OpenAPI31Plugin,
|
||||
JSONSchema2024Plugin, // New JSON Schema version
|
||||
JSONSchema2024SamplesPlugin,
|
||||
OpenAPI40Plugin, // LAST - overrides all previous
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 6. Claude Adds Tests
|
||||
|
||||
#### Unit Test (test/unit/core/plugins/oas40/fn.js)
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import { fromJS } from "immutable"
|
||||
import { isOAS40 } from "src/core/plugins/oas40/fn.js"
|
||||
|
||||
describe("oas40 plugin - fn - isOAS40", () => {
|
||||
it("should match OpenAPI 4.0.0", () => {
|
||||
const spec = fromJS({ openapi: "4.0.0" })
|
||||
expect(isOAS40(spec)).toBe(true)
|
||||
})
|
||||
|
||||
it("should match OpenAPI 4.0.15", () => {
|
||||
const spec = fromJS({ openapi: "4.0.15" })
|
||||
expect(isOAS40(spec)).toBe(true)
|
||||
})
|
||||
|
||||
it("should NOT match OpenAPI 4.0", () => {
|
||||
const spec = fromJS({ openapi: "4.0" })
|
||||
expect(isOAS40(spec)).toBe(false)
|
||||
})
|
||||
|
||||
it("should NOT match OpenAPI 3.1.0", () => {
|
||||
const spec = fromJS({ openapi: "3.1.0" })
|
||||
expect(isOAS40(spec)).toBe(false)
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
#### E2E Test (test/e2e-cypress/e2e/features/oas40/workflows.cy.js)
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
describe("OpenAPI 4.0 - Workflows", () => {
|
||||
it("should render workflows section", () => {
|
||||
cy.visit("/e2e-cypress/static/documents/oas40/petstore-workflows.yaml")
|
||||
cy.get(".opblock-tag").contains("Workflows").should("exist")
|
||||
})
|
||||
|
||||
it("should display workflow definitions", () => {
|
||||
cy.visit("/e2e-cypress/static/documents/oas40/petstore-workflows.yaml")
|
||||
cy.get(".opblock-workflow").should("have.length.greaterThan", 0)
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### 7. Claude Updates Documentation
|
||||
|
||||
Updates to `README.md`:
|
||||
|
||||
```markdown
|
||||
## Compatibility
|
||||
|
||||
Swagger UI supports the following OpenAPI Specification versions:
|
||||
|
||||
- OpenAPI 2.0 (Swagger)
|
||||
- OpenAPI 3.0.x
|
||||
- OpenAPI 3.1.x
|
||||
- OpenAPI 4.0.x ⭐ NEW
|
||||
```
|
||||
|
||||
Updates to `CLAUDE.md`:
|
||||
|
||||
```markdown
|
||||
### 26 Core Plugins
|
||||
|
||||
- `oas3` - OpenAPI 3.0.x support
|
||||
- `oas31` - OpenAPI 3.1.x support
|
||||
- `oas40` - OpenAPI 4.0.x support (NEW)
|
||||
```
|
||||
|
||||
### 8. Claude Runs Tests
|
||||
|
||||
```bash
|
||||
# Lint
|
||||
npm run lint-errors
|
||||
|
||||
# Unit tests
|
||||
npm run test:unit
|
||||
|
||||
# Build
|
||||
npm run build
|
||||
|
||||
# Artifact tests
|
||||
npm run test:artifact
|
||||
|
||||
# E2E tests
|
||||
npm run cy:ci
|
||||
```
|
||||
|
||||
### 9. Claude Creates Commit
|
||||
|
||||
```bash
|
||||
git add src/core/plugins/oas40/
|
||||
git add src/core/presets/apis/index.js
|
||||
git add test/unit/core/plugins/oas40/
|
||||
git add test/e2e-cypress/e2e/features/oas40/
|
||||
git add README.md CLAUDE.md
|
||||
|
||||
git commit -m "$(cat <<'EOF'
|
||||
feat(oas40): add support for OpenAPI 4.0
|
||||
|
||||
Implement OpenAPI 4.0.x specification support with:
|
||||
- Version detection and plugin architecture
|
||||
- Workflows rendering for reusable workflow definitions
|
||||
- AsyncAPI authentication type support
|
||||
- JSON Schema Draft 2024 integration
|
||||
- Enhanced callback syntax with workflow references
|
||||
- License attribution field support
|
||||
|
||||
Breaking changes from OAS 3.1:
|
||||
- Removed deprecated x- extension fields
|
||||
- Updated JSON Schema to Draft 2024
|
||||
|
||||
Includes comprehensive unit and E2E tests.
|
||||
|
||||
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
### 10. Result
|
||||
|
||||
You now have complete OpenAPI 4.0 support in Swagger UI:
|
||||
|
||||
```
|
||||
src/core/plugins/oas40/
|
||||
├── index.js (367 lines)
|
||||
├── fn.js (124 lines)
|
||||
├── selectors.js (45 lines)
|
||||
├── after-load.js (78 lines)
|
||||
├── auth-extensions/
|
||||
│ └── wrap-selectors.js (32 lines)
|
||||
├── oas31-extensions/
|
||||
│ └── fn.js (56 lines)
|
||||
├── spec-extensions/
|
||||
│ ├── selectors.js (89 lines)
|
||||
│ └── wrap-selectors.js (23 lines)
|
||||
├── components/
|
||||
│ ├── workflows.jsx (156 lines)
|
||||
│ ├── license.jsx (67 lines)
|
||||
│ ├── version-pragma-filter.jsx (78 lines)
|
||||
│ └── auth/
|
||||
│ └── async-api-auth.jsx (54 lines)
|
||||
└── wrap-components/
|
||||
├── info.jsx (12 lines)
|
||||
└── license.jsx (12 lines)
|
||||
|
||||
test/unit/core/plugins/oas40/
|
||||
├── fn.js (67 lines)
|
||||
└── components/
|
||||
└── version-pragma-filter.jsx (45 lines)
|
||||
|
||||
test/e2e-cypress/e2e/features/oas40/
|
||||
├── workflows.cy.js (34 lines)
|
||||
└── async-api-auth.cy.js (28 lines)
|
||||
```
|
||||
|
||||
**Total:** ~1,367 lines of code, fully tested and documented.
|
||||
|
||||
## Benefits of Using the Skill
|
||||
|
||||
### Without the Skill (Manual Implementation)
|
||||
|
||||
**Estimated Time:** 40-60 hours
|
||||
|
||||
**Challenges:**
|
||||
- Understanding plugin architecture (4-6 hours)
|
||||
- Studying OAS 3.1 patterns (3-4 hours)
|
||||
- Creating file structure (1 hour)
|
||||
- Implementing version detection (2 hours)
|
||||
- Creating selector factories (4-6 hours)
|
||||
- Implementing components (12-16 hours)
|
||||
- Writing tests (8-12 hours)
|
||||
- Debugging integration issues (6-8 hours)
|
||||
- Documentation (2-3 hours)
|
||||
|
||||
**Error-prone areas:**
|
||||
- Plugin loading order
|
||||
- Selector wrapping logic
|
||||
- Component lifecycle
|
||||
- Redux state management
|
||||
- afterLoad hook timing
|
||||
|
||||
### With the Skill (Guided Implementation)
|
||||
|
||||
**Estimated Time:** 8-12 hours
|
||||
|
||||
**Benefits:**
|
||||
- Automated boilerplate generation
|
||||
- Follows established patterns
|
||||
- Guided step-by-step process
|
||||
- Built-in error checking
|
||||
- Comprehensive test coverage
|
||||
- Documentation templates
|
||||
- Best practices enforced
|
||||
|
||||
**What the skill handles:**
|
||||
- ✅ File structure creation
|
||||
- ✅ Boilerplate code generation
|
||||
- ✅ Pattern adherence
|
||||
- ✅ Test scaffolding
|
||||
- ✅ Documentation updates
|
||||
- ✅ Build verification
|
||||
- ✅ Commit message formatting
|
||||
|
||||
## Customization Options
|
||||
|
||||
The skill is flexible and can be customized per version:
|
||||
|
||||
### For Minor Versions (e.g., 3.2)
|
||||
|
||||
```bash
|
||||
/add-oas-support --version 3.2 --type minor
|
||||
```
|
||||
|
||||
Claude will:
|
||||
- Create lighter plugin structure
|
||||
- Reuse more from previous version
|
||||
- Focus on incremental additions
|
||||
- Skip breaking change handling
|
||||
- Minimize component wrapping
|
||||
|
||||
### For Major Versions (e.g., 5.0)
|
||||
|
||||
```bash
|
||||
/add-oas-support --version 5.0 --type major
|
||||
```
|
||||
|
||||
Claude will:
|
||||
- Create comprehensive plugin structure
|
||||
- Implement extensive component wrapping
|
||||
- Handle breaking changes
|
||||
- Create new base components if needed
|
||||
- Add deprecation warnings
|
||||
- Update preset configurations
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Skill Not Found
|
||||
|
||||
```
|
||||
Error: Skill 'add-oas-support' not found
|
||||
```
|
||||
|
||||
**Solution:** Ensure the skill file exists in `.claude/skills/add-oas-support.md`
|
||||
|
||||
### Version Already Exists
|
||||
|
||||
```
|
||||
Error: Plugin for OAS 4.0 already exists
|
||||
```
|
||||
|
||||
**Solution:** Remove existing plugin or choose a different version
|
||||
|
||||
### Build Failures
|
||||
|
||||
```
|
||||
Error: Module not found
|
||||
```
|
||||
|
||||
**Solution:** Check plugin registration in presets and import paths
|
||||
|
||||
### Test Failures
|
||||
|
||||
```
|
||||
Error: isOAS40 is not a function
|
||||
```
|
||||
|
||||
**Solution:** Verify selector is properly exported and registered
|
||||
|
||||
## Next Steps
|
||||
|
||||
After the skill completes:
|
||||
|
||||
1. **Test with real specs** - Use actual OAS 4.0 examples
|
||||
2. **Review generated code** - Ensure it matches your requirements
|
||||
3. **Add custom features** - Extend beyond the boilerplate
|
||||
4. **Optimize performance** - Profile and optimize hot paths
|
||||
5. **Submit PR** - Follow the PR template and guidelines
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- **OAS 4.0 Spec:** https://spec.openapis.org/oas/v4.0.0 (hypothetical)
|
||||
- **Plugin API:** `docs/customization/plugin-api.md`
|
||||
- **CLAUDE.md:** Complete codebase guide
|
||||
- **Skill Source:** `.claude/skills/add-oas-support.md`
|
||||
|
||||
---
|
||||
|
||||
**Note:** This example uses hypothetical OAS 4.0 features for demonstration purposes. Adapt the skill usage to match the actual specification features of the version you're implementing.
|
||||
@@ -0,0 +1,151 @@
|
||||
# Swagger UI Claude Skills
|
||||
|
||||
This directory contains custom skills for working with the Swagger UI codebase in Claude Code.
|
||||
|
||||
## Available Skills
|
||||
|
||||
### `/add-oas-support` - Add OpenAPI Specification Version Support
|
||||
|
||||
Comprehensive skill for adding support for a new OpenAPI Specification version to Swagger UI.
|
||||
|
||||
**Usage:**
|
||||
```
|
||||
/add-oas-support --version 4.0 --type major
|
||||
/add-oas-support --version 3.2 --type minor
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `--version` (required): The OpenAPI version to add support for (e.g., "3.2", "4.0")
|
||||
- `--type` (optional): Version type - "major" or "minor" (default: "minor")
|
||||
|
||||
**Structure:**
|
||||
The skill includes both a **Quick Reference** section at the top for experienced developers, and a **comprehensive guide** below for detailed implementation instructions.
|
||||
|
||||
**What it does:**
|
||||
1. **Analyzes the target OAS version specification using WebFetch**
|
||||
- Fetches official spec from https://spec.openapis.org/
|
||||
- Systematically identifies new/modified/removed fields
|
||||
- Maps specification changes to Swagger UI components
|
||||
- Creates specification change document
|
||||
2. Creates the plugin directory structure
|
||||
3. Implements version detection logic
|
||||
4. Creates selector factories and component wrappers
|
||||
5. Implements new feature components based on spec analysis
|
||||
6. Handles authentication changes
|
||||
7. Registers plugin in presets
|
||||
8. Adds unit and E2E tests
|
||||
9. Updates documentation
|
||||
10. Runs full test suite
|
||||
|
||||
**Key Features:**
|
||||
- ✅ **Quick Reference** section for rapid development
|
||||
- ✅ Comprehensive specification analysis workflow using WebFetch
|
||||
- ✅ Detailed mapping table from spec changes → components (15+ change types)
|
||||
- ✅ Real examples from OAS 3.1 implementation (6 detailed examples)
|
||||
- ✅ Iterative spec-driven development approach
|
||||
- ✅ Component-by-component verification checklist
|
||||
- ✅ Best practices for continuous spec reference
|
||||
- ✅ WebFetch query templates for spec analysis
|
||||
- ✅ Common pitfalls and solutions
|
||||
- ✅ Pre-submit checklist
|
||||
|
||||
**Based on:**
|
||||
This skill follows the patterns established by the OAS 3.1 implementation (commit history analyzed from `src/core/plugins/oas31/`).
|
||||
|
||||
**Key patterns:**
|
||||
- Plugin-based architecture with Redux state management
|
||||
- Selector factories for version-specific logic
|
||||
- Component wrapping for conditional rendering
|
||||
- afterLoad lifecycle hooks for function overrides
|
||||
- Plugin loading order (new version loaded LAST)
|
||||
|
||||
**Prerequisites:**
|
||||
- Understanding of Swagger UI plugin architecture
|
||||
- Access to the new OAS specification document
|
||||
- All existing tests passing
|
||||
|
||||
**Example workflow:**
|
||||
|
||||
Adding OAS 4.0 support:
|
||||
```
|
||||
# Start the skill
|
||||
/add-oas-support --version 4.0 --type major
|
||||
|
||||
# Claude will:
|
||||
# 1. Ask about new features in OAS 4.0
|
||||
# 2. Create plugin directory structure
|
||||
# 3. Generate boilerplate code
|
||||
# 4. Guide through implementation
|
||||
# 5. Add tests
|
||||
# 6. Update documentation
|
||||
# 7. Verify build
|
||||
```
|
||||
|
||||
## Creating New Skills
|
||||
|
||||
To create a new skill for Swagger UI:
|
||||
|
||||
1. Create a markdown file in `.claude/skills/`
|
||||
2. Add frontmatter with skill metadata:
|
||||
```yaml
|
||||
---
|
||||
name: skill-name
|
||||
description: Brief description
|
||||
args:
|
||||
param1:
|
||||
description: "Parameter description"
|
||||
required: true
|
||||
type: string
|
||||
---
|
||||
```
|
||||
3. Write comprehensive instructions following the patterns in existing skills
|
||||
4. Document common pitfalls and best practices
|
||||
5. Include code templates with placeholders
|
||||
6. Add to this README
|
||||
|
||||
## Skill Development Guidelines
|
||||
|
||||
When creating skills for Swagger UI:
|
||||
|
||||
1. **Follow project conventions:**
|
||||
- No semicolons
|
||||
- Double quotes
|
||||
- @prettier pragma in all new files
|
||||
- .jsx extension for React components
|
||||
|
||||
2. **Use the plugin architecture:**
|
||||
- Don't modify core unnecessarily
|
||||
- Follow established patterns
|
||||
- Load new plugins at the end of presets
|
||||
|
||||
3. **Include comprehensive tests:**
|
||||
- Unit tests for logic
|
||||
- Component tests for UI
|
||||
- E2E tests for integration
|
||||
|
||||
4. **Document thoroughly:**
|
||||
- Update CLAUDE.md
|
||||
- Update relevant docs
|
||||
- Add inline JSDoc comments
|
||||
|
||||
5. **Security first:**
|
||||
- Use DOMPurify for HTML
|
||||
- Validate all input
|
||||
- Follow OWASP guidelines
|
||||
|
||||
## Contributing
|
||||
|
||||
To contribute new skills:
|
||||
|
||||
1. Fork the repository
|
||||
2. Create skill in `.claude/skills/`
|
||||
3. Test thoroughly
|
||||
4. Update this README
|
||||
5. Submit pull request
|
||||
|
||||
## Resources
|
||||
|
||||
- **CLAUDE.md** - Comprehensive codebase guide
|
||||
- **Plugin API** - `docs/customization/plugin-api.md`
|
||||
- **Development Setup** - `docs/development/setting-up.md`
|
||||
- **Contributing Guide** - https://github.com/swagger-api/.github/blob/HEAD/CONTRIBUTING.md
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
],
|
||||
"rules": {
|
||||
"header-max-length": [
|
||||
2,
|
||||
"always",
|
||||
69
|
||||
],
|
||||
"scope-case": [
|
||||
2,
|
||||
"always",
|
||||
[
|
||||
"camel-case",
|
||||
"kebab-case",
|
||||
"upper-case"
|
||||
]
|
||||
],
|
||||
"subject-case": [
|
||||
0,
|
||||
"always"
|
||||
]
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/.git
|
||||
/.github
|
||||
/dev-helpers
|
||||
/docs
|
||||
/src
|
||||
/swagger-ui-dist-package
|
||||
/test
|
||||
/node_modules
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
dist/
|
||||
node_modules/
|
||||
test/e2e-selenium/
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
const path = require("node:path")
|
||||
|
||||
module.exports = {
|
||||
parser: "@babel/eslint-parser",
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
es6: true,
|
||||
jest: true,
|
||||
"jest/globals": true,
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaFeatures: { jsx: true },
|
||||
babelOptions: { configFile: path.join(__dirname, "babel.config.js") },
|
||||
},
|
||||
extends: [
|
||||
"eslint:recommended",
|
||||
"plugin:react/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
],
|
||||
plugins: ["react", "import", "jest", "prettier"],
|
||||
settings: {
|
||||
react: {
|
||||
pragma: "React",
|
||||
version: "15.0",
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
semi: [2, "never"],
|
||||
strict: 0,
|
||||
quotes: [
|
||||
2,
|
||||
"double",
|
||||
{
|
||||
avoidEscape: true,
|
||||
allowTemplateLiterals: true,
|
||||
},
|
||||
],
|
||||
"no-unused-vars": 2,
|
||||
"no-multi-spaces": 1,
|
||||
camelcase: [
|
||||
"error",
|
||||
{
|
||||
allow: [
|
||||
"^UNSAFE_",
|
||||
"^requestSnippetGenerator_",
|
||||
"^JsonSchema_",
|
||||
"^curl_",
|
||||
"^dom_",
|
||||
"^api_",
|
||||
"^client_",
|
||||
"^grant_",
|
||||
"^code_",
|
||||
"^redirect_",
|
||||
"^spec",
|
||||
],
|
||||
},
|
||||
],
|
||||
"no-use-before-define": [2, "nofunc"],
|
||||
"no-underscore-dangle": 0,
|
||||
"no-unused-expressions": 1,
|
||||
"comma-dangle": 0,
|
||||
"no-console": [
|
||||
2,
|
||||
{
|
||||
allow: ["warn", "error"],
|
||||
},
|
||||
],
|
||||
"react/jsx-no-bind": 1,
|
||||
"react/jsx-no-target-blank": 2,
|
||||
"react/display-name": 0,
|
||||
"import/no-extraneous-dependencies": 2,
|
||||
"react/jsx-filename-extension": 2,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
docker-run.sh text eol=lf
|
||||
/dist/*.map export-ignore
|
||||
/test export-ignore
|
||||
/docs export-ignore
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report an issue you're experiencing
|
||||
|
||||
---
|
||||
|
||||
<!---
|
||||
Thanks for filing a bug report! 😄
|
||||
|
||||
Before you submit, please read the following:
|
||||
|
||||
If you're here to report a security issue, please STOP writing an issue and
|
||||
contact us at security@swagger.io instead!
|
||||
|
||||
Search open/closed issues before submitting!
|
||||
|
||||
Issues on GitHub are only related to problems of Swagger-UI itself. We'll try
|
||||
to offer support here for your use case, but we can't offer help with projects
|
||||
that use Swagger-UI indirectly, like Springfox or swagger-node.
|
||||
|
||||
Likewise, we can't accept bugs in the Swagger/OpenAPI specifications
|
||||
themselves, or anything that violates the specifications.
|
||||
-->
|
||||
|
||||
### Q&A (please complete the following information)
|
||||
- OS: [e.g. macOS]
|
||||
- Browser: [e.g. chrome, safari]
|
||||
- Version: [e.g. 22]
|
||||
- Method of installation: [e.g. npm, dist assets]
|
||||
- Swagger-UI version: [e.g. 3.10.0]
|
||||
- Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]
|
||||
|
||||
### Content & configuration
|
||||
<!--
|
||||
Provide us with a way to see what you're seeing,
|
||||
so that we can fix your issue.
|
||||
-->
|
||||
|
||||
Example Swagger/OpenAPI definition:
|
||||
```yaml
|
||||
# your YAML here
|
||||
```
|
||||
|
||||
Swagger-UI configuration options:
|
||||
```js
|
||||
SwaggerUI({
|
||||
// your config options here
|
||||
})
|
||||
```
|
||||
|
||||
```
|
||||
?yourQueryStringConfig
|
||||
```
|
||||
|
||||
### Describe the bug you're encountering
|
||||
<!-- A clear and concise description of what the bug is. -->
|
||||
|
||||
### To reproduce...
|
||||
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
### Expected behavior
|
||||
<!-- A clear and concise description of what you expected to happen. -->
|
||||
|
||||
### Screenshots
|
||||
<!-- If applicable, add screenshots to help explain your problem. -->
|
||||
|
||||
### Additional context or thoughts
|
||||
<!-- Add any other context about the problem here. -->
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest a new feature or enhancement for this project
|
||||
|
||||
---
|
||||
|
||||
### Content & configuration
|
||||
|
||||
Swagger/OpenAPI definition:
|
||||
```yaml
|
||||
# your YAML here
|
||||
```
|
||||
|
||||
Swagger-UI configuration options:
|
||||
```js
|
||||
SwaggerUI({
|
||||
// your config options here
|
||||
})
|
||||
```
|
||||
|
||||
```
|
||||
?yourQueryStringConfig
|
||||
```
|
||||
|
||||
|
||||
### Is your feature request related to a problem?
|
||||
<!--
|
||||
Please provide a clear and concise description of what the problem is.
|
||||
"I'm always frustrated when..."
|
||||
-->
|
||||
|
||||
### Describe the solution you'd like
|
||||
<!-- A clear and concise description of what you want to happen. -->
|
||||
|
||||
### Describe alternatives you've considered
|
||||
<!--
|
||||
A clear and concise description of any alternative solutions or features
|
||||
you've considered.
|
||||
-->
|
||||
|
||||
### Additional context
|
||||
<!-- Add any other context or screenshots about the feature request here. -->
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: Support
|
||||
about: Ask a question or request help with your implementation.
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
We can only offer support for Swagger-UI itself.
|
||||
|
||||
If you're having a problem with a library that uses Swagger-UI
|
||||
(for example, Springfox or swagger-node), please open an issue
|
||||
in that project's repository instead.
|
||||
-->
|
||||
|
||||
### Q&A (please complete the following information)
|
||||
- OS: [e.g. macOS]
|
||||
- Browser: [e.g. chrome, safari]
|
||||
- Version: [e.g. 22]
|
||||
- Method of installation: [e.g. npm, dist assets]
|
||||
- Swagger-UI version: [e.g. 3.10.0]
|
||||
- Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]
|
||||
|
||||
### Content & configuration
|
||||
<!-- Provide us with a way to see what you're seeing, so that we can help. -->
|
||||
|
||||
Swagger/OpenAPI definition:
|
||||
```yaml
|
||||
# your YAML here
|
||||
```
|
||||
|
||||
Swagger-UI configuration options:
|
||||
```js
|
||||
SwaggerUI({
|
||||
// your config options here
|
||||
})
|
||||
```
|
||||
|
||||
```
|
||||
?yourQueryStringConfig
|
||||
```
|
||||
|
||||
### Screenshots
|
||||
<!-- If applicable, add screenshots to help give context to your problem. -->
|
||||
|
||||
### How can we help?
|
||||
<!-- Your question or problem goes here! -->
|
||||
@@ -0,0 +1,35 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "23:00"
|
||||
commit-message:
|
||||
prefix: "chore"
|
||||
include: "scope"
|
||||
open-pull-requests-limit: 3
|
||||
ignore:
|
||||
# node-fetch must be synced manually
|
||||
- dependency-name: "node-fetch"
|
||||
|
||||
- package-ecosystem: "docker"
|
||||
# Look for a `Dockerfile` in the `root` directory
|
||||
directory: "/"
|
||||
# Check for updates once a week
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
time: "23:00"
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
target-branch: "master"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
time: "23:00"
|
||||
commit-message:
|
||||
prefix: "chore"
|
||||
include: "scope"
|
||||
open-pull-requests-limit: 3
|
||||
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
daysUntilLock: 365
|
||||
skipCreatedBefore: 2017-03-29 # initial release of Swagger UI 3.0.0
|
||||
exemptLabels: []
|
||||
lockLabel: "locked-by: lock-bot"
|
||||
setLockReason: false
|
||||
only: issues
|
||||
lockComment: false
|
||||
# lockComment: |
|
||||
# Locking due to inactivity.
|
||||
|
||||
# This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.
|
||||
|
||||
# If you think you're experiencing something similar to what you've found here: please [open a new issue](https://github.com/swagger-api/swagger-ui/issues/new/choose), follow the template, and reference this issue in your report.
|
||||
|
||||
# Thanks!
|
||||
@@ -0,0 +1,55 @@
|
||||
<!--- Provide a general summary of your changes in the Title above -->
|
||||
|
||||
### Description
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
|
||||
|
||||
### Motivation and Context
|
||||
<!--- Why is this change required? What problem does it solve? -->
|
||||
<!--- If it fixes an open issue, please link to the issue here. -->
|
||||
<!--- Use the magic "Fixes #1234" format, so the issues are -->
|
||||
<!--- automatically closed when this PR is merged. -->
|
||||
|
||||
|
||||
|
||||
### How Has This Been Tested?
|
||||
<!--- Please describe in detail how you manually tested your changes. -->
|
||||
<!--- Include details of your testing environment, and the tests you ran to -->
|
||||
<!--- see how your change affects other areas of the code, etc. -->
|
||||
|
||||
|
||||
|
||||
### Screenshots (if appropriate):
|
||||
|
||||
|
||||
|
||||
## Checklist
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
|
||||
### My PR contains...
|
||||
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
||||
- [ ] No code changes (`src/` is unmodified: changes to documentation, CI, metadata, etc.)
|
||||
- [ ] Dependency changes (any modification to dependencies in `package.json`)
|
||||
- [ ] Bug fixes (non-breaking change which fixes an issue)
|
||||
- [ ] Improvements (misc. changes to existing features)
|
||||
- [ ] Features (non-breaking change which adds functionality)
|
||||
|
||||
### My changes...
|
||||
- [ ] are breaking changes to a public API (config options, System API, major UI change, etc).
|
||||
- [ ] are breaking changes to a private API (Redux, component props, utility functions, etc.).
|
||||
- [ ] are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
|
||||
- [ ] are not breaking changes.
|
||||
|
||||
### Documentation
|
||||
- [ ] My changes do not require a change to the project documentation.
|
||||
- [ ] My changes require a change to the project documentation.
|
||||
- [ ] If yes to above: I have updated the documentation accordingly.
|
||||
|
||||
### Automated tests
|
||||
- [ ] My changes can not or do not need to be tested.
|
||||
- [ ] My changes can and should be tested by unit and/or integration tests.
|
||||
- [ ] If yes to above: I have added tests to cover my changes.
|
||||
- [ ] If yes to above: I have taken care to cover edge cases in my tests.
|
||||
- [ ] All new and existing tests passed.
|
||||
@@ -0,0 +1,63 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ "master" ]
|
||||
schedule:
|
||||
- cron: '16 04 * * 2'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'javascript' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Use only 'java' to analyze code written in Java, Kotlin or both
|
||||
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
config: |
|
||||
paths-ignore:
|
||||
- 'dist/'
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v4
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
||||
@@ -0,0 +1,40 @@
|
||||
name: Merge me!
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
branches: [ master, next ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
merge-me:
|
||||
name: Merge me!
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# This first step will fail if there's no metadata and so the approval
|
||||
# will not occur.
|
||||
- name: Dependabot metadata
|
||||
id: dependabot-metadata
|
||||
uses: dependabot/fetch-metadata@v3.0.0
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
# Here the PR gets approved.
|
||||
- name: Approve a PR
|
||||
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
|
||||
run: gh pr review --approve "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{ github.event.pull_request.html_url }}
|
||||
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
|
||||
# Finally, tell dependabot to merge the PR if all checks are successful
|
||||
- name: Instruct dependabot to squash & merge
|
||||
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
|
||||
uses: mshick/add-pr-comment@v3
|
||||
with:
|
||||
repo-token: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
|
||||
allow-repeats: true
|
||||
message: |
|
||||
@dependabot squash and merge
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
name: Build & Push SwaggerUI unstable Docker image
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Node.js CI"]
|
||||
types:
|
||||
- completed
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
|
||||
build-push-unstable:
|
||||
if: github.event.workflow_run.conclusion == 'success'
|
||||
name: Build & Push SwaggerUI unstable Docker image
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
cache-dependency-path: package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build SwaggerUI
|
||||
run: npm run build
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Log in to DockerHub
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_SB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_SB_PASSWORD }}
|
||||
|
||||
- name: Build docker image and push
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm/v6,linux/arm64,linux/386,linux/ppc64le
|
||||
provenance: false
|
||||
tags: swaggerapi/swagger-ui:unstable
|
||||
@@ -0,0 +1,77 @@
|
||||
name: Build & Push SwaggerUI Docker image
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Release SwaggerUI"]
|
||||
types:
|
||||
- completed
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
|
||||
build-push:
|
||||
if: github.event.workflow_run.conclusion == 'success'
|
||||
name: Build & Push SwaggerUI Docker image
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
cache-dependency-path: package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build SwaggerUI
|
||||
run: npm run build
|
||||
|
||||
- name: Determine released version
|
||||
uses: actions/github-script@v9
|
||||
with:
|
||||
script: |
|
||||
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: context.payload.workflow_run.id,
|
||||
});
|
||||
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "released-version"
|
||||
})[0];
|
||||
const download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('${{github.workspace}}/released-version.zip', Buffer.from(download.data));
|
||||
- run: |
|
||||
unzip released-version.zip
|
||||
RELEASED_VERSION=$(cat released-version.txt)
|
||||
echo "RELEASED_VERSION=$RELEASED_VERSION" >> $GITHUB_ENV
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Log in to DockerHub
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_SB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_SB_PASSWORD }}
|
||||
|
||||
- name: Build docker image and push
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm/v6,linux/arm64,linux/386,linux/ppc64le
|
||||
provenance: false
|
||||
tags: swaggerapi/swagger-ui:latest,swaggerapi/swagger-ui:v${{ env.RELEASED_VERSION }}
|
||||
@@ -0,0 +1,23 @@
|
||||
name: Security scan for docker image
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '30 4 * * *'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Run Trivy vulnerability scanner
|
||||
uses: aquasecurity/trivy-action@master
|
||||
with:
|
||||
image-ref: 'docker.swagger.io/swaggerapi/swagger-ui:unstable'
|
||||
format: 'table'
|
||||
exit-code: '1'
|
||||
ignore-unfixed: true
|
||||
vuln-type: 'os,library'
|
||||
severity: 'CRITICAL,HIGH'
|
||||
@@ -0,0 +1,86 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Node.js CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, next ]
|
||||
pull_request:
|
||||
branches: [ master, next ]
|
||||
|
||||
env:
|
||||
CYPRESS_CACHE_FOLDER: cypress/cache
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
|
||||
- name: Cache Node Modules and Cypress binary
|
||||
uses: actions/cache@v5
|
||||
id: cache-primes
|
||||
with:
|
||||
path: |
|
||||
node_modules
|
||||
${{ env.CYPRESS_CACHE_FOLDER }}
|
||||
key: ${{ runner.os }}-node-and-cypress-${{ hashFiles('package-lock.json') }}
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.cache-primes.outputs.cache-hit != 'true'
|
||||
run: npm ci
|
||||
|
||||
- name: Lint code for errors only
|
||||
run: npm run lint-errors
|
||||
|
||||
- name: Run all tests
|
||||
run: npm run test:unit
|
||||
env:
|
||||
CI: true
|
||||
|
||||
- name: Build SwaggerUI
|
||||
run: npm run build
|
||||
|
||||
- name: Test build artifacts
|
||||
run: npm run test:artifact
|
||||
|
||||
e2e-tests:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
containers: ['+(a11y|security|bugs)/**/*cy.js', 'features/**/+(o|d)*.cy.js', 'features/**/m*.cy.js', 'features/**/!(o|d|m)*.cy.js']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
|
||||
- name: Cache Node Modules and Cypress binary
|
||||
uses: actions/cache@v5
|
||||
id: cache-primes
|
||||
with:
|
||||
path: |
|
||||
node_modules
|
||||
${{ env.CYPRESS_CACHE_FOLDER }}
|
||||
key: ${{ runner.os }}-node-and-cypress-${{ hashFiles('package-lock.json') }}
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.cache-primes.outputs.cache-hit != 'true'
|
||||
run: npm ci
|
||||
|
||||
- name: Cypress Test
|
||||
run: npx start-server-and-test cy:start http://localhost:3204 'npm run cy:run -- --spec "test/e2e-cypress/e2e/${{ matrix.containers }}"'
|
||||
@@ -0,0 +1,61 @@
|
||||
name: Release SwaggerUI Dist
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Release SwaggerUI"]
|
||||
types:
|
||||
- completed
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
release-swagger-ui-dist:
|
||||
if: github.event.workflow_run.conclusion == 'success'
|
||||
name: Release swagger-ui-dist npm package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
ref: master
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
cache-dependency-path: package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Download build artifact
|
||||
uses: actions/github-script@v9
|
||||
with:
|
||||
script: |
|
||||
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: context.payload.workflow_run.id,
|
||||
});
|
||||
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "dist"
|
||||
})[0];
|
||||
const download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('${{github.workspace}}/dist.zip', Buffer.from(download.data));
|
||||
- run: |
|
||||
unzip -o dist.zip -d dist
|
||||
|
||||
- name: Publish to npmjs.com
|
||||
run: ./deploy.sh
|
||||
working-directory: ./swagger-ui-dist-package
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
PUBLISH_DIST: true
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
name: Release SwaggerUI to Packagist
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Release SwaggerUI"]
|
||||
types:
|
||||
- completed
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
release-swagger-ui-packagist:
|
||||
if: github.event.workflow_run.conclusion == 'success'
|
||||
name: Release swagger-ui to packagist
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Update SwaggerUI packagist package
|
||||
run: |
|
||||
curl --fail -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
"https://packagist.org/api/update-package?username=${{ secrets.PACKAGIST_USER }}&apiToken=${{ secrets.PACKAGIST_API_TOKEN }}" \
|
||||
-d "{\"repository\":{\"url\":\"https://packagist.org/packages/swagger-api/swagger-ui\"}}"
|
||||
@@ -0,0 +1,61 @@
|
||||
name: Release SwaggerUI React
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Release SwaggerUI"]
|
||||
types:
|
||||
- completed
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
release-swagger-ui-react:
|
||||
if: github.event.workflow_run.conclusion == 'success'
|
||||
name: Release swagger-ui-react npm package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
ref: master
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
cache-dependency-path: package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Download build artifact
|
||||
uses: actions/github-script@v9
|
||||
with:
|
||||
script: |
|
||||
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: context.payload.workflow_run.id,
|
||||
});
|
||||
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "dist"
|
||||
})[0];
|
||||
const download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('${{github.workspace}}/dist.zip', Buffer.from(download.data));
|
||||
- run: |
|
||||
unzip -o dist.zip -d dist
|
||||
|
||||
- name: Publish to npmjs.com
|
||||
run: ./run.sh
|
||||
working-directory: ./flavors/swagger-ui-react/release
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
PUBLISH_FLAVOR_REACT: true
|
||||
@@ -0,0 +1,95 @@
|
||||
name: Release SwaggerUI
|
||||
on:
|
||||
workflow_dispatch:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Release swagger-ui npm package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
ref: master
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
cache-dependency-path: package-lock.json
|
||||
|
||||
- name: Determine the next release version
|
||||
uses: cycjimmy/semantic-release-action@v6
|
||||
with:
|
||||
dry_run: true
|
||||
extra_plugins: |
|
||||
@semantic-release/git
|
||||
@semantic-release/exec
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Nothing to release
|
||||
if: ${{ env.NEXT_RELEASE_VERSION == '' }}
|
||||
uses: actions/github-script@v9
|
||||
with:
|
||||
script: |
|
||||
core.setFailed('Nothing to release')
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Prepare for the Release
|
||||
env:
|
||||
REACT_APP_VERSION: ${{ env.NEXT_RELEASE_VERSION }}
|
||||
run: |
|
||||
npm run test
|
||||
npm run build
|
||||
|
||||
- name: Semantic Release
|
||||
id: semantic
|
||||
uses: cycjimmy/semantic-release-action@v6
|
||||
with:
|
||||
dry_run: false
|
||||
extra_plugins: |
|
||||
@semantic-release/git
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Release failed
|
||||
if: steps.semantic.outputs.new_release_published == 'false'
|
||||
uses: actions/github-script@v9
|
||||
with:
|
||||
script: |
|
||||
core.setFailed('Release failed')
|
||||
|
||||
- name: Release published
|
||||
run: |
|
||||
echo ${{ steps.semantic.outputs.new_release_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_major_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_minor_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_patch_version }}
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: dist
|
||||
path: ./dist
|
||||
|
||||
|
||||
- name: Prepare released version for uploading
|
||||
shell: bash
|
||||
run: |
|
||||
echo ${{ steps.semantic.outputs.new_release_version }} > released-version.txt
|
||||
- name: Upload released version
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: released-version
|
||||
path: ./released-version.txt
|
||||
retention-days: 1
|
||||
@@ -0,0 +1,29 @@
|
||||
node_modules
|
||||
.idea
|
||||
.vscode
|
||||
.deps_check
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.nyc_output
|
||||
npm-debug.log*
|
||||
.eslintcache
|
||||
*.iml
|
||||
selenium-debug.log
|
||||
chromedriver.log
|
||||
test/e2e/db.json
|
||||
docs/_book
|
||||
dev-helpers/examples
|
||||
|
||||
# dist
|
||||
flavors/**/dist/*
|
||||
/lib
|
||||
/es
|
||||
dist/log*
|
||||
/swagger-ui-*.tgz
|
||||
|
||||
# Cypress
|
||||
test/e2e-cypress/screenshots
|
||||
test/e2e-cypress/videos
|
||||
@@ -0,0 +1 @@
|
||||
npx commitlint -e
|
||||
@@ -0,0 +1 @@
|
||||
npx lint-staged
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"*.{js,jsx}": ["eslint --max-warnings 0"],
|
||||
"*.scss": ["stylelint '**/*.scss'"]
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
*
|
||||
*/
|
||||
!README.md
|
||||
!NOTICE
|
||||
!package.json
|
||||
!dist/swagger-ui.js
|
||||
!dist/swagger-ui.js.map
|
||||
!dist/swagger-ui-bundle.js
|
||||
!dist/swagger-ui-standalone-preset.js
|
||||
!dist/swagger-ui-es-bundle.js
|
||||
!dist/swagger-ui-es-bundle-core.js
|
||||
!dist/swagger-ui-es-bundle-core.js.map
|
||||
!dist/swagger-ui.css
|
||||
!dist/swagger-ui.css.map
|
||||
!dist/oauth2-redirect.html
|
||||
!dist/oauth2-redirect.js
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
save-prefix="="
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
24.14.0
|
||||
@@ -0,0 +1,5 @@
|
||||
semi: false
|
||||
trailingComma: es5
|
||||
endOfLine: lf
|
||||
requirePragma: true
|
||||
insertPragma: true
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"branches": [
|
||||
{"name": "master"}
|
||||
],
|
||||
"tagFormat": "v${version}",
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
[
|
||||
"@semantic-release/exec",
|
||||
{
|
||||
"verifyReleaseCmd": "echo \"NEXT_RELEASE_VERSION=${nextRelease.version}\" >> $GITHUB_ENV"
|
||||
}
|
||||
],
|
||||
"@semantic-release/release-notes-generator",
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/github",
|
||||
["@semantic-release/git", {
|
||||
"assets": [
|
||||
"dist/*.{js,html,css}",
|
||||
"package.json",
|
||||
"package-lock.json"
|
||||
],
|
||||
"message": "chore(release): cut the ${nextRelease.version} release\n\n${nextRelease.notes}"
|
||||
}]
|
||||
]
|
||||
}
|
||||
+1072
File diff suppressed because it is too large
Load Diff
+52
@@ -0,0 +1,52 @@
|
||||
# Looking for information on environment variables?
|
||||
# We don't declare them here — take a look at our docs.
|
||||
# https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
|
||||
|
||||
FROM nginx:1.30.0-alpine
|
||||
|
||||
LABEL maintainer="vladimir.gorej@gmail.com" \
|
||||
org.opencontainers.image.authors="vladimir.gorej@gmail.com" \
|
||||
org.opencontainers.image.url="docker.swagger.io/swaggerapi/swagger-ui" \
|
||||
org.opencontainers.image.source="https://github.com/swagger-api/swagger-ui" \
|
||||
org.opencontainers.image.description="SwaggerUI Docker image" \
|
||||
org.opencontainers.image.licenses="Apache-2.0"
|
||||
|
||||
RUN apk add --update-cache --no-cache \
|
||||
"nodejs" \
|
||||
"libxml2>=2.13.9-r0" \
|
||||
"libexpat>=2.7.2-r0" \
|
||||
"libxslt>=1.1.42-r2" \
|
||||
"xz-libs>=5.6.3-r1" \
|
||||
"c-ares>=1.34.5-r0" \
|
||||
"libpng>=1.6.56-r0" \
|
||||
"zlib>=1.3.2-r0" \
|
||||
"libcrypto3>=3.5.6-r0" \
|
||||
"libssl3>=3.5.6-r0" \
|
||||
"musl>=1.2.5-r23" \
|
||||
"musl-utils>=1.2.5-r23" \
|
||||
"nghttp2-libs>=1.68.1-r0"
|
||||
|
||||
LABEL maintainer="char0n"
|
||||
|
||||
ENV API_KEY="**None**" \
|
||||
SWAGGER_JSON="/app/swagger.json" \
|
||||
PORT="8080" \
|
||||
PORT_IPV6="" \
|
||||
BASE_URL="/" \
|
||||
SWAGGER_JSON_URL="" \
|
||||
CORS="true" \
|
||||
EMBEDDING="false"
|
||||
|
||||
COPY --chmod=0644 ./docker/default.conf.template ./docker/cors.conf ./docker/embedding.conf /etc/nginx/templates/
|
||||
|
||||
COPY --chmod=0644 ./dist/* /usr/share/nginx/html/
|
||||
COPY --chmod=0755 ./docker/docker-entrypoint.d/ /docker-entrypoint.d/
|
||||
COPY --chmod=0644 ./docker/configurator /usr/share/nginx/configurator
|
||||
|
||||
# Simulates running NGINX as a non root; in future we want to use nginxinc/nginx-unprivileged.
|
||||
# In future we will have separate unpriviledged images tagged as v5.1.2-unprivileged.
|
||||
RUN chmod 777 /etc/nginx/conf.d/ /usr/share/nginx/html/ /var/cache/nginx/ /var/run/ && \
|
||||
chmod 666 /etc/nginx/conf.d/default.conf /usr/share/nginx/html/swagger-initializer.js && \
|
||||
chmod 755 /etc/nginx/templates /usr/share/nginx/configurator
|
||||
|
||||
EXPOSE 8080
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
swagger-ui
|
||||
Copyright 2020-2021 SmartBear Software Inc.
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
# <img src="https://raw.githubusercontent.com/swagger-api/swagger.io/wordpress/images/assets/SWU-logo-clr.png" width="300">
|
||||
|
||||
[](http://badge.fury.io/js/swagger-ui)
|
||||
[](https://jenkins.swagger.io/view/OSS%20-%20JavaScript/job/oss-swagger-ui-master/)
|
||||
[](https://jenkins.swagger.io/job/oss-swagger-ui-security-audit/lastBuild/console)
|
||||
[](https://github.com/swagger-api/swagger-ui/graphs/contributors)
|
||||
|
||||
[](https://www.npmjs.com/package/swagger-ui)
|
||||

|
||||

|
||||
[](https://bundlephobia.com/package/swagger-ui)
|
||||
|
||||
## Introduction
|
||||
[Swagger UI](https://swagger.io/tools/swagger-ui/) allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation and client side consumption.
|
||||
|
||||
## General
|
||||
**👉🏼 Want to score an easy open-source contribution?** Check out our [Good first issue](https://github.com/swagger-api/swagger-ui/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%22) label.
|
||||
|
||||
**🕰️ Looking for the older version of Swagger UI?** Refer to the [*2.x* branch](https://github.com/swagger-api/swagger-ui/tree/2.x).
|
||||
|
||||
|
||||
This repository publishes three different NPM modules:
|
||||
|
||||
* [swagger-ui](https://www.npmjs.com/package/swagger-ui) is a traditional npm module intended for use in single-page applications that are capable of resolving dependencies (via Webpack, Browserify, etc.).
|
||||
* [swagger-ui-dist](https://www.npmjs.com/package/swagger-ui-dist) is a dependency-free module that includes everything you need to serve Swagger UI in a server-side project, or a single-page application that can't resolve npm module dependencies.
|
||||
* [swagger-ui-react](https://www.npmjs.com/package/swagger-ui-react) is Swagger UI packaged as a React component for use in React applications.
|
||||
|
||||
We strongly suggest that you use `swagger-ui` instead of `swagger-ui-dist` if you're building a single-page application, since `swagger-ui-dist` is significantly larger.
|
||||
|
||||
If you are looking for plain ol' HTML/JS/CSS, [download the latest release](https://github.com/swagger-api/swagger-ui/releases/latest) and copy the contents of the `/dist` folder to your server.
|
||||
|
||||
|
||||
## Compatibility
|
||||
The OpenAPI Specification has undergone 5 revisions since initial creation in 2010. Compatibility between Swagger UI and the OpenAPI Specification is as follows:
|
||||
|
||||
| Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes |
|
||||
|--------------------|--------------|-------------------------------------------------------------|-----------------------------------------------------------------------|
|
||||
| 5.32.0 | 2026-02-27 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.1.0, 3.1.1, 3.1.2, 3.2.0 | [tag v5.32.0](https://github.com/swagger-api/swagger-ui/tree/v5.32.0) |
|
||||
| 5.19.0 | 2025-02-17 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.1.0, 3.1.1, 3.1.2 | [tag v5.19.0](https://github.com/swagger-api/swagger-ui/tree/v5.19.0) |
|
||||
| 5.0.0 | 2023-06-12 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0 | [tag v5.0.0](https://github.com/swagger-api/swagger-ui/tree/v5.0.0) |
|
||||
| 4.0.0 | 2021-11-03 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3 | [tag v4.0.0](https://github.com/swagger-api/swagger-ui/tree/v4.0.0) |
|
||||
| 3.18.3 | 2018-08-03 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3 | [tag v3.18.3](https://github.com/swagger-api/swagger-ui/tree/v3.18.3) |
|
||||
| 3.0.21 | 2017-07-26 | 2.0 | [tag v3.0.21](https://github.com/swagger-api/swagger-ui/tree/v3.0.21) |
|
||||
| 2.2.10 | 2017-01-04 | 1.1, 1.2, 2.0 | [tag v2.2.10](https://github.com/swagger-api/swagger-ui/tree/v2.2.10) |
|
||||
| 2.1.5 | 2016-07-20 | 1.1, 1.2, 2.0 | [tag v2.1.5](https://github.com/swagger-api/swagger-ui/tree/v2.1.5) |
|
||||
| 2.0.24 | 2014-09-12 | 1.1, 1.2 | [tag v2.0.24](https://github.com/swagger-api/swagger-ui/tree/v2.0.24) |
|
||||
| 1.0.13 | 2013-03-08 | 1.1, 1.2 | [tag v1.0.13](https://github.com/swagger-api/swagger-ui/tree/v1.0.13) |
|
||||
| 1.0.1 | 2011-10-11 | 1.0, 1.1 | [tag v1.0.1](https://github.com/swagger-api/swagger-ui/tree/v1.0.1) |
|
||||
|
||||
## Anonymized analytics
|
||||
|
||||
SwaggerUI uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:
|
||||
|
||||
```
|
||||
// package.json
|
||||
{
|
||||
// ...
|
||||
"scarfSettings": {
|
||||
"enabled": false
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.
|
||||
|
||||
## Documentation
|
||||
|
||||
#### Usage
|
||||
- [Installation](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/installation.md)
|
||||
- [Configuration](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md)
|
||||
- [CORS](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/cors.md)
|
||||
- [OAuth2](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/oauth2.md)
|
||||
- [Deep Linking](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/deep-linking.md)
|
||||
- [Limitations](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/limitations.md)
|
||||
- [Version detection](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/version-detection.md)
|
||||
|
||||
#### Customization
|
||||
- [Overview](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/customization/overview.md)
|
||||
- [Plugin API](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/customization/plugin-api.md)
|
||||
- [Custom layout](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/customization/custom-layout.md)
|
||||
|
||||
#### Development
|
||||
- [Setting up](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/development/setting-up.md)
|
||||
- [Scripts](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/development/scripts.md)
|
||||
|
||||
#### Contributing
|
||||
- [Contributing](https://github.com/swagger-api/.github/blob/HEAD/CONTRIBUTING.md)
|
||||
|
||||
##### Integration Tests
|
||||
|
||||
You will need JDK of version 7 or higher as instructed here
|
||||
https://nightwatchjs.org/guide/getting-started/installation.html#install-selenium-server
|
||||
|
||||
Integration tests can be run locally with `npm run e2e` - be sure you aren't running a dev server when testing!
|
||||
|
||||
### Browser support
|
||||
Swagger UI works in the latest versions of Chrome, Safari, Firefox, and Edge.
|
||||
|
||||
### Known Issues
|
||||
|
||||
To help with the migration, here are the currently known issues with 3.X. This list will update regularly, and will not include features that were not implemented in previous versions.
|
||||
|
||||
- Only part of the parameters previously supported are available.
|
||||
- The JSON Form Editor is not implemented.
|
||||
- Support for `collectionFormat` is partial.
|
||||
- l10n (translations) is not implemented.
|
||||
- Relative path support for external files is not implemented.
|
||||
|
||||
## Security contact
|
||||
|
||||
Please disclose any security-related issues or vulnerabilities by emailing [security@swagger.io](mailto:security@swagger.io), instead of using the public issue tracker.
|
||||
|
||||
## License
|
||||
|
||||
SwaggerUI is licensed under [Apache 2.0 license](https://github.com/swagger-api/swagger-ui/blob/master/LICENSE).
|
||||
SwaggerUI comes with an explicit [NOTICE](https://github.com/swagger-api/swagger-ui/blob/master/NOTICE) file
|
||||
containing additional legal notices and information.
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
# Security Policy
|
||||
|
||||
If you believe you've found an exploitable security issue in Swagger UI,
|
||||
**please don't create a public issue**.
|
||||
|
||||
|
||||
## Supported versions
|
||||
|
||||
This is the list of versions of `swagger-ui` which are
|
||||
currently being supported with security updates.
|
||||
|
||||
| Version | Supported | Notes |
|
||||
|---------|--------------------|---------------------------------|
|
||||
| 5.x | :white_check_mark: | Active LTS |
|
||||
| 4.x | :x: | End-of-life as of August 2023 |
|
||||
| 3.x | :x: | End-of-life as of November 2021 |
|
||||
| 2.x | :x: | End-of-life as of 2017 |
|
||||
|
||||
## Reporting a vulnerability
|
||||
|
||||
To report a vulnerability please send an email with the details to [security@swagger.io](mailto:security@swagger.io).
|
||||
|
||||
We'll acknowledge receipt of your report ASAP, and set expectations on how we plan to handle it.
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
const browser = {
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
debug: false,
|
||||
modules: "auto",
|
||||
useBuiltIns: false,
|
||||
forceAllTransforms: false,
|
||||
ignoreBrowserslistConfig: false,
|
||||
}
|
||||
],
|
||||
"@babel/preset-react",
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
"@babel/plugin-transform-runtime",
|
||||
{
|
||||
corejs: { version: 3, proposals: false },
|
||||
absoluteRuntime: false,
|
||||
helpers: true,
|
||||
regenerator: false,
|
||||
version: "^7.22.11",
|
||||
}
|
||||
],
|
||||
[
|
||||
"transform-react-remove-prop-types",
|
||||
{
|
||||
additionalLibraries: [
|
||||
"react-immutable-proptypes"
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
"babel-plugin-module-resolver",
|
||||
{
|
||||
alias: {
|
||||
root: ".",
|
||||
core: "./src/core",
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: {
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
debug: false,
|
||||
modules: "commonjs",
|
||||
loose: true,
|
||||
useBuiltIns: false,
|
||||
forceAllTransforms: false,
|
||||
ignoreBrowserslistConfig: false,
|
||||
}
|
||||
],
|
||||
"@babel/preset-react",
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
"@babel/plugin-transform-runtime",
|
||||
{
|
||||
corejs: { version: 3, proposals: false },
|
||||
absoluteRuntime: false,
|
||||
helpers: true,
|
||||
regenerator: false,
|
||||
version: "^7.22.11",
|
||||
}
|
||||
],
|
||||
[
|
||||
"transform-react-remove-prop-types",
|
||||
{
|
||||
additionalLibraries: [
|
||||
"react-immutable-proptypes"
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
"babel-plugin-module-resolver",
|
||||
{
|
||||
alias: {
|
||||
root: ".",
|
||||
core: "./src/core",
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
},
|
||||
esm: {
|
||||
presets: [
|
||||
[
|
||||
"@babel/env",
|
||||
{
|
||||
debug: false,
|
||||
modules: false,
|
||||
ignoreBrowserslistConfig: false,
|
||||
useBuiltIns: false,
|
||||
}
|
||||
],
|
||||
"@babel/preset-react"
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
"@babel/plugin-transform-runtime",
|
||||
{
|
||||
corejs: { version: 3, proposals: false },
|
||||
absoluteRuntime: false,
|
||||
helpers: true,
|
||||
regenerator: false,
|
||||
version: "^7.22.11",
|
||||
}
|
||||
],
|
||||
[
|
||||
"transform-react-remove-prop-types",
|
||||
{
|
||||
additionalLibraries: [
|
||||
"react-immutable-proptypes"
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
"babel-plugin-module-resolver",
|
||||
{
|
||||
alias: {
|
||||
root: ".",
|
||||
core: "./src/core",
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
development: browser,
|
||||
production: browser,
|
||||
},
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "swagger-api/swagger-ui",
|
||||
"description": " Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.",
|
||||
"keywords": [
|
||||
"Swagger",
|
||||
"OpenAPI",
|
||||
"specification",
|
||||
"documentation",
|
||||
"API",
|
||||
"UI"
|
||||
],
|
||||
"homepage": "http://swagger.io",
|
||||
"license": "Apache-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Anna Bodnia",
|
||||
"email": "anna.bodnia@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Buu Nguyen",
|
||||
"email": "buunguyen@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Josh Ponelat",
|
||||
"email": "jponelat@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Kyle Shockey",
|
||||
"email": "kyleshockey1@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Robert Barnwell",
|
||||
"email": "robert@robertismy.name"
|
||||
},
|
||||
{
|
||||
"name": "Sahar Jafari",
|
||||
"email": "shr.jafari@gmail.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"rules": {
|
||||
"import/no-unresolved": 0,
|
||||
"import/extensions": 0,
|
||||
"quotes": ["error", "single"],
|
||||
"semi": ["error", "always"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
rootDir: path.join(__dirname, '..', '..'),
|
||||
testEnvironment: 'jsdom',
|
||||
testMatch: ['**/test/build-artifacts/**/*.js'],
|
||||
setupFiles: ['<rootDir>/test/unit/jest-shim.js'],
|
||||
transformIgnorePatterns: ['/node_modules/(?!(swagger-client|react-syntax-highlighter)/)'],
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
rootDir: path.join(__dirname, '..', '..'),
|
||||
testEnvironment: 'jest-environment-jsdom',
|
||||
testMatch: [
|
||||
'**/test/unit/*.js?(x)',
|
||||
'**/test/unit/**/*.js?(x)',
|
||||
],
|
||||
setupFiles: ['<rootDir>/test/unit/jest-shim.js'],
|
||||
setupFilesAfterEnv: ['<rootDir>/test/unit/setup.js'],
|
||||
testPathIgnorePatterns: [
|
||||
'<rootDir>/node_modules/',
|
||||
'<rootDir>/test/build-artifacts/',
|
||||
'<rootDir>/test/unit/jest-shim.js',
|
||||
'<rootDir>/test/unit/setup.js',
|
||||
],
|
||||
moduleNameMapper: {
|
||||
'^.+\\.svg$': 'jest-transform-stub',
|
||||
'^standalone/(.*)$': '<rootDir>/src/standalone/$1',
|
||||
},
|
||||
transformIgnorePatterns: ['/node_modules/(?!(sinon|react-syntax-highlighter|@asamuzakjp/css-color)/)'],
|
||||
silent: true, // set to `false` to allow console.* calls to be printed
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
const { defineConfig } = require("cypress")
|
||||
|
||||
const startOAuthServer = require("./test/e2e-cypress/support/helpers/oauth2-server")
|
||||
|
||||
module.exports = defineConfig({
|
||||
fileServerFolder: "test/e2e-cypress/static",
|
||||
fixturesFolder: "test/e2e-cypress/fixtures",
|
||||
screenshotsFolder: "test/e2e-cypress/screenshots",
|
||||
videosFolder: "test/e2e-cypress/videos",
|
||||
video: false,
|
||||
e2e: {
|
||||
baseUrl: "http://localhost:3230/",
|
||||
supportFile: "test/e2e-cypress/support/e2e.js",
|
||||
specPattern: "test/e2e-cypress/e2e/**/*.cy.{js,jsx}",
|
||||
setupNodeEvents: () => {
|
||||
startOAuthServer()
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
/* eslint-disable no-undef */
|
||||
window.onload = function() {
|
||||
window["SwaggerUIBundle"] = window["swagger-ui-bundle"]
|
||||
window["SwaggerUIStandalonePreset"] = window["swagger-ui-standalone-preset"]
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "https://petstore.swagger.io/v2/swagger.json",
|
||||
dom_id: "#swagger-ui",
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
// requestSnippetsEnabled: true,
|
||||
layout: "StandaloneLayout"
|
||||
})
|
||||
|
||||
window.ui = ui
|
||||
|
||||
ui.initOAuth({
|
||||
clientId: "your-client-id",
|
||||
clientSecret: "your-client-secret-if-required",
|
||||
realm: "your-realms",
|
||||
appName: "your-app-name",
|
||||
scopeSeparator: " ",
|
||||
scopes: "openid profile email phone address",
|
||||
additionalQueryStringParams: {},
|
||||
useBasicAuthenticationWithAccessCodeGrant: false,
|
||||
usePkceWithAuthorizationCodeGrant: false
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<!-- HTML for dev server -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<link rel="stylesheet" type="text/css" href="/swagger-ui.css">
|
||||
<style>
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="dev-helper-initializer.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<body>
|
||||
<script src="oauth2-redirect.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,69 @@
|
||||
"use strict"
|
||||
function run () {
|
||||
var oauth2 = window.opener.swaggerUIRedirectOauth2
|
||||
var sentState = oauth2.state
|
||||
var redirectUrl = oauth2.redirectUrl
|
||||
var isValid, qp, arr
|
||||
|
||||
if (/code|token|error/.test(window.location.hash)) {
|
||||
qp = window.location.hash.substring(1).replace("?", "&")
|
||||
} else {
|
||||
qp = location.search.substring(1)
|
||||
}
|
||||
|
||||
arr = qp.split("&")
|
||||
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace("=", '":"') + '"' })
|
||||
qp = qp ? JSON.parse("{" + arr.join() + "}",
|
||||
function (key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value)
|
||||
}
|
||||
) : {}
|
||||
|
||||
isValid = qp.state === sentState
|
||||
|
||||
if ((
|
||||
oauth2.auth.schema.get("flow") === "accessCode" ||
|
||||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
|
||||
oauth2.auth.schema.get("flow") === "authorization_code"
|
||||
) && !oauth2.auth.code) {
|
||||
if (!isValid) {
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "warning",
|
||||
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
|
||||
})
|
||||
}
|
||||
|
||||
if (qp.code) {
|
||||
delete oauth2.state
|
||||
oauth2.auth.code = qp.code
|
||||
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl})
|
||||
} else {
|
||||
let oauthErrorMsg
|
||||
if (qp.error) {
|
||||
oauthErrorMsg = "["+qp.error+"]: " +
|
||||
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
||||
(qp.error_uri ? "More info: "+qp.error_uri : "")
|
||||
}
|
||||
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "error",
|
||||
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
|
||||
})
|
||||
}
|
||||
} else {
|
||||
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl})
|
||||
}
|
||||
window.close()
|
||||
}
|
||||
|
||||
if( document.readyState !== "loading" ) {
|
||||
run()
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
run()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 665 B |
Binary file not shown.
|
After Width: | Height: | Size: 628 B |
+16
@@ -0,0 +1,16 @@
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: #fafafa;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
|
||||
<link rel="stylesheet" type="text/css" href="index.css" />
|
||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
|
||||
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
|
||||
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<body>
|
||||
<script src="oauth2-redirect.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
"use strict";function run(){var e,r,t,a=window.opener.swaggerUIRedirectOauth2,o=a.state,n=a.redirectUrl;if((t=(r=/code|token|error/.test(window.location.hash)?window.location.hash.substring(1).replace("?","&"):location.search.substring(1)).split("&")).forEach((function(e,r,t){t[r]='"'+e.replace("=",'":"')+'"'})),e=(r=r?JSON.parse("{"+t.join()+"}",(function(e,r){return""===e?r:decodeURIComponent(r)})):{}).state===o,"accessCode"!==a.auth.schema.get("flow")&&"authorizationCode"!==a.auth.schema.get("flow")&&"authorization_code"!==a.auth.schema.get("flow")||a.auth.code)a.callback({auth:a.auth,token:r,isValid:e,redirectUrl:n});else if(e||a.errCb({authId:a.auth.name,source:"auth",level:"warning",message:"Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"}),r.code)delete a.state,a.auth.code=r.code,a.callback({auth:a.auth,redirectUrl:n});else{let e;r.error&&(e="["+r.error+"]: "+(r.error_description?r.error_description+". ":"no accessCode received from the server. ")+(r.error_uri?"More info: "+r.error_uri:"")),a.errCb({authId:a.auth.name,source:"auth",level:"error",message:e||"[Authorization failed]: no accessCode received from the server"})}window.close()}"loading"!==document.readyState?run():document.addEventListener("DOMContentLoaded",(function(){run()}));
|
||||
@@ -0,0 +1,20 @@
|
||||
window.onload = function() {
|
||||
//<editor-fold desc="Changeable Configuration Block">
|
||||
|
||||
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
|
||||
window.ui = SwaggerUIBundle({
|
||||
url: "https://petstore.swagger.io/v2/swagger.json",
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
});
|
||||
|
||||
//</editor-fold>
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,13 @@
|
||||
module.exports.indent = function indent(str, len, fromLine = 0) {
|
||||
|
||||
return str
|
||||
.split("\n")
|
||||
.map((line, i) => {
|
||||
if (i + 1 >= fromLine) {
|
||||
return `${Array(len + 1).join(" ")}${line}`
|
||||
} else {
|
||||
return line
|
||||
}
|
||||
})
|
||||
.join("\n")
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Replace static code with configured data based on environment-variables.
|
||||
* This code should be called BEFORE the webserver serve the api-documentation.
|
||||
*/
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
|
||||
const translator = require("./translator")
|
||||
const oauthBlockBuilder = require("./oauth")
|
||||
const indent = require("./helpers").indent
|
||||
|
||||
const START_MARKER = "//<editor-fold desc=\"Changeable Configuration Block\">"
|
||||
const END_MARKER = "//</editor-fold>"
|
||||
|
||||
const targetPath = path.normalize(process.cwd() + "/" + process.argv[2])
|
||||
|
||||
const originalHtmlContent = fs.readFileSync(targetPath, "utf8")
|
||||
|
||||
const startMarkerIndex = originalHtmlContent.indexOf(START_MARKER)
|
||||
const endMarkerIndex = originalHtmlContent.indexOf(END_MARKER)
|
||||
|
||||
const beforeStartMarkerContent = originalHtmlContent.slice(0, startMarkerIndex)
|
||||
const afterEndMarkerContent = originalHtmlContent.slice(
|
||||
endMarkerIndex + END_MARKER.length
|
||||
)
|
||||
|
||||
if (startMarkerIndex < 0 || endMarkerIndex < 0) {
|
||||
console.error("ERROR: Swagger UI was unable to inject Docker configuration data!")
|
||||
console.error("! This can happen when you provide custom HTML/JavaScript to Swagger UI.")
|
||||
console.error("! ")
|
||||
console.error(`! In order to solve this, add the "${START_MARKER}"`)
|
||||
console.error(`! and "${END_MARKER}" markers to your JavaScript.`)
|
||||
console.error("! See the repository for an example:")
|
||||
console.error("! https://github.com/swagger-api/swagger-ui/blob/8c946a02e73ef877d73b7635de27924418ba50f3/dist/swagger-initializer.js#L2-L19")
|
||||
console.error("! ")
|
||||
console.error("! If you're seeing this message and aren't using custom HTML,")
|
||||
console.error("! this message may be a bug. Please file an issue:")
|
||||
console.error("! https://github.com/swagger-api/swagger-ui/issues/new/choose")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
targetPath,
|
||||
`${beforeStartMarkerContent}
|
||||
${START_MARKER}
|
||||
window.ui = SwaggerUIBundle({
|
||||
${indent(translator(process.env, {injectBaseConfig: true}), 8, 2)}
|
||||
})
|
||||
${indent(oauthBlockBuilder(process.env), 6, 2)}
|
||||
${END_MARKER}
|
||||
${afterEndMarkerContent}`
|
||||
)
|
||||
@@ -0,0 +1,55 @@
|
||||
const translator = require("./translator")
|
||||
const indent = require("./helpers").indent
|
||||
|
||||
const oauthBlockSchema = {
|
||||
OAUTH_CLIENT_ID: {
|
||||
type: "string",
|
||||
name: "clientId"
|
||||
},
|
||||
OAUTH_CLIENT_SECRET: {
|
||||
type: "string",
|
||||
name: "clientSecret",
|
||||
onFound: () => console.warn("Swagger UI warning: don't use `OAUTH_CLIENT_SECRET` in production!")
|
||||
},
|
||||
OAUTH_REALM: {
|
||||
type: "string",
|
||||
name: "realm"
|
||||
},
|
||||
OAUTH_APP_NAME: {
|
||||
type: "string",
|
||||
name: "appName"
|
||||
},
|
||||
OAUTH_SCOPE_SEPARATOR: {
|
||||
type: "string",
|
||||
name: "scopeSeparator"
|
||||
},
|
||||
OAUTH_SCOPES: {
|
||||
type: "string",
|
||||
name: "scopes"
|
||||
},
|
||||
OAUTH_ADDITIONAL_PARAMS: {
|
||||
type: "object",
|
||||
name: "additionalQueryStringParams"
|
||||
},
|
||||
OAUTH_USE_BASIC_AUTH: {
|
||||
type: "boolean",
|
||||
name: "useBasicAuthenticationWithAccessCodeGrant"
|
||||
},
|
||||
OAUTH_USE_PKCE: {
|
||||
type: "boolean",
|
||||
name: "usePkceWithAuthorizationCodeGrant"
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function oauthBlockBuilder(env) {
|
||||
const translatorResult = translator(env, { schema: oauthBlockSchema })
|
||||
|
||||
if(translatorResult) {
|
||||
return (
|
||||
`ui.initOAuth({
|
||||
${indent(translatorResult, 2)}
|
||||
})`)
|
||||
}
|
||||
|
||||
return ``
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// Converts an object of environment variables into a Swagger UI config object
|
||||
const configSchema = require("./variables")
|
||||
|
||||
const defaultBaseConfig = {
|
||||
url: {
|
||||
value: "https://petstore.swagger.io/v2/swagger.json",
|
||||
schema: {
|
||||
type: "string",
|
||||
base: true
|
||||
}
|
||||
},
|
||||
dom_id: {
|
||||
value: "#swagger-ui",
|
||||
schema: {
|
||||
type: "string",
|
||||
base: true
|
||||
}
|
||||
},
|
||||
deepLinking: {
|
||||
value: "true",
|
||||
schema: {
|
||||
type: "boolean",
|
||||
base: true
|
||||
}
|
||||
},
|
||||
presets: {
|
||||
value: `[\n SwaggerUIBundle.presets.apis,\n SwaggerUIStandalonePreset\n]`,
|
||||
schema: {
|
||||
type: "array",
|
||||
base: true
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
value: `[\n SwaggerUIBundle.plugins.DownloadUrl\n]`,
|
||||
schema: {
|
||||
type: "array",
|
||||
base: true
|
||||
}
|
||||
},
|
||||
layout: {
|
||||
value: "StandaloneLayout",
|
||||
schema: {
|
||||
type: "string",
|
||||
base: true
|
||||
}
|
||||
},
|
||||
queryConfigEnabled: {
|
||||
value: "false",
|
||||
schema: {
|
||||
type: "boolean",
|
||||
base: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function objectToKeyValueString(env, { injectBaseConfig = false, schema = configSchema, baseConfig = defaultBaseConfig } = {}) {
|
||||
let valueStorage = injectBaseConfig ? Object.assign({}, baseConfig) : {}
|
||||
const keys = Object.keys(env)
|
||||
|
||||
// Compute an intermediate representation that holds candidate values and schemas.
|
||||
//
|
||||
// This is useful for deduping between multiple env keys that set the same
|
||||
// config variable.
|
||||
|
||||
keys.forEach(key => {
|
||||
const varSchema = schema[key]
|
||||
const value = env[key]
|
||||
|
||||
if(!varSchema) return
|
||||
|
||||
if(varSchema.onFound) {
|
||||
varSchema.onFound()
|
||||
}
|
||||
|
||||
const storageContents = valueStorage[varSchema.name]
|
||||
|
||||
if(storageContents) {
|
||||
if (varSchema.legacy === true && !storageContents.schema.base) {
|
||||
// If we're looking at a legacy var, it should lose out to any already-set value
|
||||
// except for base values
|
||||
return
|
||||
}
|
||||
delete valueStorage[varSchema.name]
|
||||
}
|
||||
|
||||
valueStorage[varSchema.name] = {
|
||||
value,
|
||||
schema: varSchema
|
||||
}
|
||||
})
|
||||
|
||||
// Compute a key:value string based on valueStorage's contents.
|
||||
|
||||
let result = ""
|
||||
|
||||
Object.keys(valueStorage).forEach(key => {
|
||||
const value = valueStorage[key]
|
||||
|
||||
const escapedName = /[^a-zA-Z0-9]/.test(key) ? `"${key}"` : key
|
||||
|
||||
if (value.schema.type === "string") {
|
||||
result += `${escapedName}: "${value.value}",\n`
|
||||
} else {
|
||||
result += `${escapedName}: ${value.value === "" ? `undefined` : value.value},\n`
|
||||
}
|
||||
})
|
||||
|
||||
return result.trim()
|
||||
}
|
||||
|
||||
module.exports = objectToKeyValueString
|
||||
@@ -0,0 +1,125 @@
|
||||
const standardVariables = {
|
||||
CONFIG_URL: {
|
||||
type: "string",
|
||||
name: "configUrl"
|
||||
},
|
||||
DOM_ID: {
|
||||
type: "string",
|
||||
name: "dom_id"
|
||||
},
|
||||
SPEC: {
|
||||
type: "object",
|
||||
name: "spec"
|
||||
},
|
||||
URL: {
|
||||
type: "string",
|
||||
name: "url"
|
||||
},
|
||||
URLS: {
|
||||
type: "array",
|
||||
name: "urls"
|
||||
},
|
||||
URLS_PRIMARY_NAME: {
|
||||
type: "string",
|
||||
name: "urls.primaryName"
|
||||
},
|
||||
QUERY_CONFIG_ENABLED: {
|
||||
type: "boolean",
|
||||
name: "queryConfigEnabled"
|
||||
},
|
||||
LAYOUT: {
|
||||
type: "string",
|
||||
name: "layout"
|
||||
},
|
||||
DEEP_LINKING: {
|
||||
type: "boolean",
|
||||
name: "deepLinking"
|
||||
},
|
||||
DISPLAY_OPERATION_ID: {
|
||||
type: "boolean",
|
||||
name: "displayOperationId"
|
||||
},
|
||||
DEFAULT_MODELS_EXPAND_DEPTH: {
|
||||
type: "number",
|
||||
name: "defaultModelsExpandDepth"
|
||||
},
|
||||
DEFAULT_MODEL_EXPAND_DEPTH: {
|
||||
type: "number",
|
||||
name: "defaultModelExpandDepth"
|
||||
},
|
||||
DEFAULT_MODEL_RENDERING: {
|
||||
type: "string",
|
||||
name: "defaultModelRendering"
|
||||
},
|
||||
DISPLAY_REQUEST_DURATION: {
|
||||
type: "boolean",
|
||||
name: "displayRequestDuration"
|
||||
},
|
||||
DOC_EXPANSION: {
|
||||
type: "string",
|
||||
name: "docExpansion"
|
||||
},
|
||||
FILTER: {
|
||||
type: "string",
|
||||
name: "filter"
|
||||
},
|
||||
MAX_DISPLAYED_TAGS: {
|
||||
type: "number",
|
||||
name: "maxDisplayedTags"
|
||||
},
|
||||
SHOW_EXTENSIONS: {
|
||||
type: "boolean",
|
||||
name: "showExtensions"
|
||||
},
|
||||
SHOW_COMMON_EXTENSIONS: {
|
||||
type: "boolean",
|
||||
name: "showCommonExtensions"
|
||||
},
|
||||
USE_UNSAFE_MARKDOWN: {
|
||||
type: "boolean",
|
||||
name: "useUnsafeMarkdown"
|
||||
},
|
||||
OAUTH2_REDIRECT_URL: {
|
||||
type: "string",
|
||||
name: "oauth2RedirectUrl"
|
||||
},
|
||||
PERSIST_AUTHORIZATION: {
|
||||
type: "boolean",
|
||||
name: "persistAuthorization"
|
||||
},
|
||||
SHOW_MUTATED_REQUEST: {
|
||||
type: "boolean",
|
||||
name: "showMutatedRequest"
|
||||
},
|
||||
SUPPORTED_SUBMIT_METHODS: {
|
||||
type: "array",
|
||||
name: "supportedSubmitMethods"
|
||||
},
|
||||
TRY_IT_OUT_ENABLED: {
|
||||
type: "boolean",
|
||||
name: "tryItOutEnabled"
|
||||
},
|
||||
VALIDATOR_URL: {
|
||||
type: "string",
|
||||
name: "validatorUrl"
|
||||
},
|
||||
WITH_CREDENTIALS: {
|
||||
type: "boolean",
|
||||
name: "withCredentials",
|
||||
}
|
||||
}
|
||||
|
||||
const legacyVariables = {
|
||||
API_URL: {
|
||||
type: "string",
|
||||
name: "url",
|
||||
legacy: true
|
||||
},
|
||||
API_URLS: {
|
||||
type: "array",
|
||||
name: "urls",
|
||||
legacy: true
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Object.assign({}, standardVariables, legacyVariables)
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
||||
#
|
||||
# Custom headers and headers various browsers *should* be OK with but aren't
|
||||
#
|
||||
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type' always;
|
||||
#
|
||||
# Tell client that this pre-flight info is valid for 20 days
|
||||
#
|
||||
add_header 'Access-Control-Max-Age' $access_control_max_age always;
|
||||
|
||||
if ($request_method = OPTIONS) {
|
||||
return 204;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
types {
|
||||
text/plain yaml;
|
||||
text/plain yml;
|
||||
}
|
||||
|
||||
gzip on;
|
||||
gzip_static on;
|
||||
gzip_disable "msie6";
|
||||
|
||||
gzip_vary on;
|
||||
gzip_types text/plain text/css application/javascript;
|
||||
|
||||
map $request_method $access_control_max_age {
|
||||
OPTIONS 1728000; # 20 days
|
||||
}
|
||||
server_tokens off; # Hide Nginx version
|
||||
|
||||
server {
|
||||
listen $PORT;
|
||||
server_name localhost;
|
||||
index index.html index.htm;
|
||||
|
||||
location $BASE_URL {
|
||||
absolute_redirect off;
|
||||
alias /usr/share/nginx/html/;
|
||||
expires 1d;
|
||||
|
||||
location ~ swagger-initializer.js {
|
||||
expires -1;
|
||||
include templates/cors.conf;
|
||||
}
|
||||
|
||||
location ~* \.(?:json|yml|yaml)$ {
|
||||
#SWAGGER_ROOT
|
||||
expires -1;
|
||||
|
||||
include templates/cors.conf;
|
||||
}
|
||||
|
||||
include templates/cors.conf;
|
||||
include templates/embedding.conf;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#! /bin/sh
|
||||
|
||||
set -e
|
||||
NGINX_ROOT=/usr/share/nginx/html
|
||||
INITIALIZER_SCRIPT=$NGINX_ROOT/swagger-initializer.js
|
||||
NGINX_CONF=/etc/nginx/conf.d/default.conf
|
||||
|
||||
node /usr/share/nginx/configurator $INITIALIZER_SCRIPT
|
||||
|
||||
|
||||
if [ "$SWAGGER_JSON_URL" ]; then
|
||||
sed -i "s|https://petstore.swagger.io/v2/swagger.json|$SWAGGER_JSON_URL|g" $INITIALIZER_SCRIPT
|
||||
sed -i "s|http://example.com/api|$SWAGGER_JSON_URL|g" $INITIALIZER_SCRIPT
|
||||
fi
|
||||
|
||||
if [[ -f "$SWAGGER_JSON" ]]; then
|
||||
cp -s "$SWAGGER_JSON" "$NGINX_ROOT"
|
||||
REL_PATH="./$(basename $SWAGGER_JSON)"
|
||||
|
||||
if [[ -z "$SWAGGER_ROOT" ]]; then
|
||||
SWAGGER_ROOT="$(dirname $SWAGGER_JSON)"
|
||||
fi
|
||||
|
||||
if [[ "$BASE_URL" != "/" ]]
|
||||
then
|
||||
BASE_URL=$(echo $BASE_URL | sed 's/\/$//')
|
||||
sed -i \
|
||||
"s|#SWAGGER_ROOT|rewrite ^$BASE_URL(/.*)$ \$1 break;\n #SWAGGER_ROOT|" \
|
||||
$NGINX_CONF
|
||||
fi
|
||||
sed -i "s|#SWAGGER_ROOT|root $SWAGGER_ROOT/;|g" $NGINX_CONF
|
||||
|
||||
sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INITIALIZER_SCRIPT
|
||||
sed -i "s|http://example.com/api|$REL_PATH|g" $INITIALIZER_SCRIPT
|
||||
fi
|
||||
|
||||
# enable/disable the address and port for IPv6 addresses that nginx listens on
|
||||
if [[ -n "${PORT_IPV6}" ]]; then
|
||||
sed -i "s|${PORT};|${PORT};\n listen [::]:${PORT_IPV6};|g" $NGINX_CONF
|
||||
fi
|
||||
|
||||
# enable/disable CORS
|
||||
if [ "$CORS" != "true" ]; then
|
||||
truncate -s 0 /etc/nginx/templates/cors.conf
|
||||
fi
|
||||
|
||||
# allow/disallow embedding the swagger-ui in frames/iframes from different origins
|
||||
if [ "$EMBEDDING" != "false" ]; then
|
||||
truncate -s 0 /etc/nginx/templates/embedding.conf
|
||||
fi
|
||||
|
||||
find $NGINX_ROOT -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;
|
||||
@@ -0,0 +1,5 @@
|
||||
#
|
||||
# Prevent displaying inside an iframe
|
||||
#
|
||||
add_header 'X-Frame-Options' 'DENY' always;
|
||||
add_header 'Content-Security-Policy' "frame-ancestors 'none'" always;
|
||||
@@ -0,0 +1,227 @@
|
||||
# `swagger-ui-react`
|
||||
|
||||
[](http://badge.fury.io/js/swagger-ui-react)
|
||||
|
||||
`swagger-ui-react` is a flavor of Swagger UI suitable for use in React applications.
|
||||
|
||||
It has a few differences from the main version of Swagger UI:
|
||||
* Declares `react` and `react-dom` as peerDependencies instead of production dependencies
|
||||
* Exports a component instead of a constructor function
|
||||
|
||||
Versions of this module mirror the version of Swagger UI included in the distribution.
|
||||
|
||||
## Anonymized analytics
|
||||
|
||||
`swagger-ui-react` uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:
|
||||
|
||||
```
|
||||
// package.json
|
||||
{
|
||||
// ...
|
||||
"scarfSettings": {
|
||||
"enabled": false
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.
|
||||
|
||||
|
||||
## Quick start
|
||||
|
||||
Install `swagger-ui-react`:
|
||||
|
||||
```
|
||||
$ npm install swagger-ui-react
|
||||
```
|
||||
|
||||
Use it in your React application:
|
||||
|
||||
```js
|
||||
import SwaggerUI from "swagger-ui-react"
|
||||
import "swagger-ui-react/swagger-ui.css"
|
||||
|
||||
export default App = () => <SwaggerUI url="https://petstore.swagger.io/v2/swagger.json" />
|
||||
```
|
||||
|
||||
## Props
|
||||
|
||||
These props map to [Swagger UI configuration options](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md) of the same name.
|
||||
|
||||
#### `spec`: PropTypes.object
|
||||
|
||||
An OpenAPI document represented as a JavaScript object, JSON string, or YAML string for Swagger UI to display.
|
||||
|
||||
⚠️ Don't use this in conjunction with `url` - unpredictable behavior may occur.
|
||||
|
||||
#### `url`: PropTypes.string
|
||||
|
||||
Remote URL to an OpenAPI document that Swagger UI will fetch, parse, and display.
|
||||
|
||||
⚠️ Don't use this in conjunction with `spec` - unpredictable behavior may occur.
|
||||
|
||||
#### `layout`: PropTypes.string
|
||||
|
||||
The name of a component available via the plugin system to use as the top-level layout for Swagger UI. The default value is `BaseLayout`.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `onComplete`: PropTypes.func
|
||||
|
||||
> `(system) => void`
|
||||
|
||||
A callback function that is triggered when Swagger-UI finishes rendering an OpenAPI document.
|
||||
|
||||
Swagger UI's `system` object is passed as an argument.
|
||||
|
||||
#### `requestInterceptor`: PropTypes.func
|
||||
|
||||
> `req => req` or `req => Promise<req>`.
|
||||
|
||||
A function that accepts a request object, and returns either a request object
|
||||
or a Promise that resolves to a request object.
|
||||
|
||||
#### `responseInterceptor`: PropTypes.func
|
||||
|
||||
> `res => res` or `res => Promise<res>`.
|
||||
|
||||
A function that accepts a response object, and returns either a response object
|
||||
or a Promise that resolves to a response object.
|
||||
|
||||
#### `docExpansion`: PropTypes.oneOf(['list', 'full', 'none'])
|
||||
|
||||
Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). The default value is 'list'.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `defaultModelExpandDepth`: PropTypes.number
|
||||
|
||||
The default expansion depth for models (set to -1 completely hide the models).
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `defaultModelRendering`: PropTypes.oneOf(["example", "model"])
|
||||
|
||||
Controls how the model is shown when the API is first rendered. (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links.) The default value is 'example'.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
|
||||
#### `displayOperationId`: PropTypes.bool
|
||||
|
||||
Controls the display of operationId in operations list. The default is false.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `plugins`: PropTypes.arrayOf(PropTypes.object),
|
||||
|
||||
An array of objects that augment and modify Swagger UI's functionality. See Swagger UI's [Plugin API](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/plugin-api.md) for more details.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `supportedSubmitMethods`: PropTypes.arrayOf(PropTypes.oneOf(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']))
|
||||
|
||||
HTTP methods that have the Try it out feature enabled. An empty array disables Try it out for all operations. This does not filter the operations from the display.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `showExtensions`: PropTypes.bool
|
||||
|
||||
Controls the display of vendor extension (`x-`) fields and values for Operations, Parameters, Responses, and Schema.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `showCommonExtensions`: PropTypes.bool
|
||||
|
||||
Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `showMutatedRequest`: PropTypes.bool
|
||||
|
||||
If set to `true`, uses the mutated request returned from a requestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `presets`: PropTypes.arrayOf(PropTypes.func),
|
||||
|
||||
An array of functions that augment and modify Swagger UI's functionality. See Swagger UI's [Plugin API](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/plugin-api.md) for more details.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `tryItOutEnabled`: PropTypes.bool
|
||||
|
||||
Controls whether the "Try it out" section should start enabled. The default is false.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `displayRequestDuration`: PropTypes.bool
|
||||
|
||||
Controls the display of the request duration (in milliseconds) for "Try it out" requests. The default is false.
|
||||
|
||||
#### `filter`: PropTypes.oneOfType([PropTypes.string, PropTypes.bool])
|
||||
|
||||
If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown. Can be Boolean to enable or disable, or a string, in which case filtering will be enabled using that string as the filter expression. Filtering is case sensitive matching the filter expression anywhere inside the tag. See Swagger UI's [Plug Points](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/plug-points.md#fnopsfilter) to customize the filtering behavior.
|
||||
|
||||
#### `requestSnippetsEnabled`: PropTypes.bool,
|
||||
|
||||
Enables the request snippet section. When disabled, the legacy curl snippet will be used. The default is false.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `requestSnippets`: PropTypes.object,
|
||||
|
||||
Configures the request snippet core plugin. See Swagger UI's [Display Configuration](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#display) for more details.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `persistAuthorization`: PropTypes.bool
|
||||
|
||||
If set, it persists authorization data and it would not be lost on browser close/refresh. The default is false.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `withCredentials`: PropTypes.bool
|
||||
|
||||
If set to `true`, enables passing credentials, [as defined in the Fetch standard](https://fetch.spec.whatwg.org/#credentials), in CORS requests that are sent by the browser. Note that Swagger UI cannot currently set cookies cross-domain (see [swagger-js#1163](https://github.com/swagger-api/swagger-js/issues/1163)) - as a result, you will have to rely on browser-supplied cookies (which this setting enables sending) that Swagger UI cannot control.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `oauth2RedirectUrl`: PropTypes.string
|
||||
|
||||
Redirect url given as parameter to the oauth2 provider. Default the url refers to oauth2-redirect.html at the same path as the Swagger UI is available.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
#### `initialState`: PropTypes.object
|
||||
|
||||
Passes initial values to the Swagger UI state.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
|
||||
#### `uncaughtExceptionHandler`: PropTypes.func
|
||||
|
||||
Allows to define a custom uncaught exception handler. The default is `null`, which means that the default handler will be used.
|
||||
The default handler will log the error to the console.
|
||||
|
||||
⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
|
||||
|
||||
|
||||
## Limitations
|
||||
|
||||
* Not all configuration bindings are available.
|
||||
* Some props are only applied on mount, and cannot be updated reliably.
|
||||
* OAuth redirection handling is not supported.
|
||||
* Topbar/Standalone mode is not supported.
|
||||
|
||||
We intend to address these limitations based on user demand, so please open an issue or pull request if you have a specific request.
|
||||
|
||||
## Notes
|
||||
|
||||
* The `package.json` in the same folder as this README is _not_ the manifest that should be used for releases - another manifest is generated at build-time and can be found in `./dist/`.
|
||||
|
||||
---
|
||||
|
||||
For anything else, check the [Swagger-UI](https://github.com/swagger-api/swagger-ui) repository.
|
||||
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
"use client"
|
||||
|
||||
import React, { useEffect, useRef, useState } from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import SwaggerUIConstructor from "#swagger-ui"
|
||||
|
||||
const { config } = SwaggerUIConstructor
|
||||
|
||||
const usePrevious = (value) => {
|
||||
const ref = useRef()
|
||||
useEffect(() => {
|
||||
ref.current = value
|
||||
}, [value])
|
||||
return ref.current
|
||||
}
|
||||
|
||||
const SwaggerUI = ({
|
||||
spec = config.defaults.spec,
|
||||
url = config.defaults.url,
|
||||
layout = config.defaults.layout,
|
||||
requestInterceptor = config.defaults.requestInterceptor,
|
||||
responseInterceptor = config.defaults.responseInterceptor,
|
||||
supportedSubmitMethods = config.defaults.supportedSubmitMethods,
|
||||
queryConfigEnabled = config.defaults.queryConfigEnabled,
|
||||
plugins = config.defaults.plugins,
|
||||
displayOperationId = config.defaults.displayOperationId,
|
||||
showMutatedRequest = config.defaults.showMutatedRequest,
|
||||
docExpansion = config.defaults.docExpansion,
|
||||
defaultModelExpandDepth = config.defaults.defaultModelExpandDepth,
|
||||
defaultModelsExpandDepth = config.defaults.defaultModelsExpandDepth,
|
||||
defaultModelRendering = config.defaults.defaultModelRendering,
|
||||
presets = config.defaults.presets,
|
||||
deepLinking = config.defaults.deepLinking,
|
||||
showExtensions = config.defaults.showExtensions,
|
||||
showCommonExtensions = config.defaults.showCommonExtensions,
|
||||
filter = config.defaults.filter,
|
||||
requestSnippetsEnabled = config.defaults.requestSnippetsEnabled,
|
||||
requestSnippets = config.defaults.requestSnippets,
|
||||
tryItOutEnabled = config.defaults.tryItOutEnabled,
|
||||
displayRequestDuration = config.defaults.displayRequestDuration,
|
||||
withCredentials = config.defaults.withCredentials,
|
||||
persistAuthorization = config.defaults.persistAuthorization,
|
||||
oauth2RedirectUrl = config.defaults.oauth2RedirectUrl,
|
||||
onComplete = null,
|
||||
initialState = config.defaults.initialState,
|
||||
uncaughtExceptionHandler = config.defaults.uncaughtExceptionHandler,
|
||||
}) => {
|
||||
const [system, setSystem] = useState(null)
|
||||
const SwaggerUIComponent = system?.getComponent("App", "root")
|
||||
const prevSpec = usePrevious(spec)
|
||||
const prevUrl = usePrevious(url)
|
||||
|
||||
useEffect(() => {
|
||||
const systemInstance = SwaggerUIConstructor({
|
||||
plugins,
|
||||
spec,
|
||||
url,
|
||||
layout,
|
||||
defaultModelsExpandDepth,
|
||||
defaultModelRendering,
|
||||
presets: [SwaggerUIConstructor.presets.apis, ...presets],
|
||||
requestInterceptor,
|
||||
responseInterceptor,
|
||||
onComplete: () => {
|
||||
if (typeof onComplete === "function") {
|
||||
onComplete(systemInstance)
|
||||
}
|
||||
},
|
||||
docExpansion,
|
||||
supportedSubmitMethods,
|
||||
queryConfigEnabled,
|
||||
defaultModelExpandDepth,
|
||||
displayOperationId,
|
||||
tryItOutEnabled,
|
||||
displayRequestDuration,
|
||||
requestSnippetsEnabled,
|
||||
requestSnippets,
|
||||
showMutatedRequest,
|
||||
deepLinking,
|
||||
showExtensions,
|
||||
showCommonExtensions,
|
||||
filter,
|
||||
persistAuthorization,
|
||||
withCredentials,
|
||||
initialState,
|
||||
uncaughtExceptionHandler,
|
||||
...(typeof oauth2RedirectUrl === "string"
|
||||
? { oauth2RedirectUrl: oauth2RedirectUrl }
|
||||
: {}),
|
||||
})
|
||||
|
||||
setSystem(systemInstance)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (system) {
|
||||
const prevStateUrl = system.specSelectors.url()
|
||||
if (url !== prevStateUrl || url !== prevUrl) {
|
||||
system.specActions.updateSpec("")
|
||||
if (url) {
|
||||
system.specActions.updateUrl(url)
|
||||
system.specActions.download(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [system, url])
|
||||
|
||||
useEffect(() => {
|
||||
if (system) {
|
||||
const prevStateSpec = system.specSelectors.specStr()
|
||||
if (
|
||||
spec &&
|
||||
spec !== SwaggerUIConstructor.config.defaults.spec &&
|
||||
(spec !== prevStateSpec || spec !== prevSpec)
|
||||
) {
|
||||
const updatedSpec =
|
||||
typeof spec === "object" ? JSON.stringify(spec) : spec
|
||||
system.specActions.updateSpec(updatedSpec)
|
||||
}
|
||||
}
|
||||
}, [system, spec])
|
||||
|
||||
return SwaggerUIComponent ? <SwaggerUIComponent /> : null
|
||||
}
|
||||
|
||||
SwaggerUI.propTypes = {
|
||||
spec: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
||||
url: PropTypes.string,
|
||||
layout: PropTypes.string,
|
||||
requestInterceptor: PropTypes.func,
|
||||
responseInterceptor: PropTypes.func,
|
||||
onComplete: PropTypes.func,
|
||||
docExpansion: PropTypes.oneOf(["list", "full", "none"]),
|
||||
supportedSubmitMethods: PropTypes.arrayOf(
|
||||
PropTypes.oneOf([
|
||||
"get",
|
||||
"put",
|
||||
"post",
|
||||
"delete",
|
||||
"options",
|
||||
"head",
|
||||
"patch",
|
||||
"trace",
|
||||
])
|
||||
),
|
||||
queryConfigEnabled: PropTypes.bool,
|
||||
plugins: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.object),
|
||||
PropTypes.arrayOf(PropTypes.func),
|
||||
PropTypes.func,
|
||||
]),
|
||||
displayOperationId: PropTypes.bool,
|
||||
showMutatedRequest: PropTypes.bool,
|
||||
defaultModelExpandDepth: PropTypes.number,
|
||||
defaultModelsExpandDepth: PropTypes.number,
|
||||
defaultModelRendering: PropTypes.oneOf(["example", "model"]),
|
||||
presets: PropTypes.arrayOf(PropTypes.func),
|
||||
deepLinking: PropTypes.bool,
|
||||
showExtensions: PropTypes.bool,
|
||||
showCommonExtensions: PropTypes.bool,
|
||||
filter: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||
requestSnippetsEnabled: PropTypes.bool,
|
||||
requestSnippets: PropTypes.object,
|
||||
tryItOutEnabled: PropTypes.bool,
|
||||
displayRequestDuration: PropTypes.bool,
|
||||
persistAuthorization: PropTypes.bool,
|
||||
withCredentials: PropTypes.bool,
|
||||
oauth2RedirectUrl: PropTypes.string,
|
||||
initialState: PropTypes.object,
|
||||
uncaughtExceptionHandler: PropTypes.func,
|
||||
}
|
||||
SwaggerUI.System = SwaggerUIConstructor.System
|
||||
SwaggerUI.presets = SwaggerUIConstructor.presets
|
||||
SwaggerUI.plugins = SwaggerUIConstructor.plugins
|
||||
SwaggerUI.config = SwaggerUIConstructor.config
|
||||
|
||||
export default SwaggerUI
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
const jsonMerger = require("json-merger")
|
||||
|
||||
const result = jsonMerger.mergeFiles(["../../../package.json", "template.json"])
|
||||
|
||||
if (process.env.REACT_FLAVOR_VERSION_IDENTIFIER) {
|
||||
result.version = process.env.REACT_FLAVOR_VERSION_IDENTIFIER
|
||||
}
|
||||
|
||||
process.stdout.write(JSON.stringify(result, null, 2))
|
||||
@@ -0,0 +1,42 @@
|
||||
# Deploy `swagger-ui-react` to npm.
|
||||
|
||||
# https://www.peterbe.com/plog/set-ex
|
||||
set -ex
|
||||
|
||||
# Parameter Expansion: http://stackoverflow.com/questions/6393551/what-is-the-meaning-of-0-in-a-bash-script
|
||||
cd "${0%/*}"
|
||||
|
||||
mkdir -p ../dist
|
||||
|
||||
# Copy UI's dist files to our directory
|
||||
cp ../../../dist/swagger-ui-es-bundle-core.js ../dist
|
||||
cp ../../../dist/swagger-ui-es-bundle-core.js.map ../dist
|
||||
cp ../../../dist/swagger-ui.js ../dist
|
||||
cp ../../../dist/swagger-ui.js.map ../dist
|
||||
cp ../../../dist/swagger-ui-bundle.js ../dist
|
||||
cp ../../../dist/swagger-ui-es-bundle.js ../dist
|
||||
cp ../../../dist/swagger-ui.css ../dist
|
||||
cp ../../../dist/swagger-ui.css.map ../dist
|
||||
|
||||
# Create a releasable package manifest
|
||||
node create-manifest.js > ../dist/package.json
|
||||
|
||||
# Transpile our top-level component
|
||||
../../../node_modules/.bin/cross-env NODE_ENV=production BABEL_ENV=commonjs BROWSERSLIST_ENV=isomorphic-production ../../../node_modules/.bin/babel --config-file ../../../babel.config.js ../index.jsx > ../dist/index.cjs
|
||||
../../../node_modules/.bin/cross-env NODE_ENV=production BABEL_ENV=esm BROWSERSLIST_ENV=browser-production ../../../node_modules/.bin/babel --config-file ../../../babel.config.js ../index.jsx > ../dist/index.mjs
|
||||
|
||||
# Copy our README into the dist folder for npm
|
||||
cp ../README.md ../dist
|
||||
|
||||
# Copy LICENSE & NOTICE into the dist folder for npm
|
||||
cp ../../../LICENSE ../dist
|
||||
cp ../../../NOTICE ../dist
|
||||
|
||||
# Run the release from the dist folder
|
||||
cd ../dist
|
||||
|
||||
if [ "$PUBLISH_FLAVOR_REACT" = "true" ] ; then
|
||||
npm publish .
|
||||
else
|
||||
npm pack .
|
||||
fi
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"react": {
|
||||
"$remove": true
|
||||
},
|
||||
"react-dom": {
|
||||
"$remove": true
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"$remove": true
|
||||
},
|
||||
"devDependencies": {
|
||||
"$remove": true
|
||||
},
|
||||
"config": {
|
||||
"$remove": true
|
||||
},
|
||||
"name": "swagger-ui-react",
|
||||
"main": "index.cjs",
|
||||
"module": "index.mjs",
|
||||
"exports": {
|
||||
"$replace": {
|
||||
"./swagger-ui.css": "./swagger-ui.css",
|
||||
".": {
|
||||
"import": "./index.mjs",
|
||||
"require": "./index.cjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": {
|
||||
"$replace": {
|
||||
"#swagger-ui": {
|
||||
"browser": {
|
||||
"import": "./swagger-ui-es-bundle-core.js",
|
||||
"require": "./swagger-ui.js"
|
||||
},
|
||||
"node": {
|
||||
"import": "./swagger-ui-bundle.js",
|
||||
"require": "./swagger-ui-es-bundle.js"
|
||||
},
|
||||
"default": {
|
||||
"import": "./swagger-ui-bundle.js",
|
||||
"require": "./swagger-ui-es-bundle.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=16.8.0 <20",
|
||||
"react-dom": ">=16.8.0 <20"
|
||||
}
|
||||
}
|
||||
+28592
File diff suppressed because it is too large
Load Diff
+213
@@ -0,0 +1,213 @@
|
||||
{
|
||||
"name": "swagger-ui",
|
||||
"version": "5.32.6",
|
||||
"main": "./dist/swagger-ui.js",
|
||||
"module": "./dist/swagger-ui-es-bundle-core.js",
|
||||
"exports": {
|
||||
"./dist/swagger-ui.css": "./dist/swagger-ui.css",
|
||||
"./dist/oauth2-redirect.html": "./dist/oauth2-redirect.html",
|
||||
"./dist/swagger-ui-standalone-preset": "./dist/swagger-ui-standalone-preset.js",
|
||||
".": {
|
||||
"browser": {
|
||||
"import": "./dist/swagger-ui-es-bundle-core.js",
|
||||
"require": "./dist/swagger-ui.js"
|
||||
},
|
||||
"node": {
|
||||
"import": "./dist/swagger-ui-bundle.js",
|
||||
"require": "./dist/swagger-ui-es-bundle.js"
|
||||
},
|
||||
"default": {
|
||||
"import": "./dist/swagger-ui-bundle.js",
|
||||
"require": "./dist/swagger-ui-es-bundle.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"homepage": "https://github.com/swagger-api/swagger-ui",
|
||||
"repository": "git@github.com:swagger-api/swagger-ui.git",
|
||||
"contributors": [
|
||||
"(in alphabetical order)",
|
||||
"Anna Bodnia <anna.bodnia@gmail.com>",
|
||||
"Buu Nguyen <buunguyen@gmail.com>",
|
||||
"Josh Ponelat <jponelat@gmail.com>",
|
||||
"Kyle Shockey <kyleshockey@gmail.com>",
|
||||
"Robert Barnwell <robert@robertismy.name>",
|
||||
"Sahar Jafari <shr.jafari@gmail.com>",
|
||||
"Vladimir Gorej <vladimir.gorej@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"automated-release": "release-it -VV --config ./release/.release-it.json",
|
||||
"build": "npm run build-stylesheets && rimraf ./dist/swagger-ui.js ./dist/swagger-ui.js.map && npm run build-all-bundles",
|
||||
"build-all-bundles": "run-p --aggregate-output build:core build:bundle build:standalone build:es:bundle build:es:bundle:core",
|
||||
"build-stylesheets": "cross-env NODE_ENV=production BABEL_ENV=production BROWSERSLIST_ENV=browser-production webpack --color --config webpack/stylesheets.js && shx sed -i \"s/\\*zoom/zoom/g\" ./dist/swagger-ui.css",
|
||||
"build:bundle": "cross-env NODE_ENV=production BABEL_ENV=production BROWSERSLIST_ENV=isomorphic-production webpack --color --config webpack/bundle.js",
|
||||
"build:core": "cross-env NODE_ENV=production BABEL_ENV=production BROWSERSLIST_ENV=browser-production webpack --color --config webpack/core.js",
|
||||
"build:standalone": "cross-env NODE_ENV=production BABEL_ENV=production BROWSERSLIST_ENV=browser-production webpack --color --config webpack/standalone.js",
|
||||
"build:es:bundle": "cross-env NODE_ENV=production BABEL_ENV=production BROWSERSLIST_ENV=isomorphic-production webpack --color --config webpack/es-bundle.js",
|
||||
"build:es:bundle:core": "cross-env NODE_ENV=production BABEL_ENV=esm BROWSERSLIST_ENV=browser-production webpack --color --config webpack/es-bundle-core.js",
|
||||
"clean": "rimraf ./dist",
|
||||
"dev": "cross-env NODE_ENV=development BABEL_ENV=development BROWSERSLIST_ENV=browser-development webpack serve --config webpack/dev.js",
|
||||
"deps-license": "license-checker --production --csv --out $npm_package_config_deps_check_dir/licenses.csv && license-checker --development --csv --out $npm_package_config_deps_check_dir/licenses-dev.csv",
|
||||
"deps-size": "cross-env NODE_ENV=development webpack -p --config webpack/bundle.js --json | webpack-bundle-size-analyzer >| $npm_package_config_deps_check_dir/sizes.txt",
|
||||
"deps-check": "run-s deps-license deps-size",
|
||||
"lint": "eslint --ext \".js,.jsx\" src test dev-helpers flavors",
|
||||
"lint-errors": "eslint --quiet --ext \".js,.jsx\" src test dev-helpers flavors",
|
||||
"lint-fix": "eslint --ext \".js,.jsx\" src test dev-helpers flavors --fix",
|
||||
"lint-styles": "stylelint \"**/*.scss\"",
|
||||
"lint-styles-fix": "stylelint \"**/*.scss\" --fix",
|
||||
"test": "run-s lint-errors test:unit cy:ci",
|
||||
"test:artifact": "cross-env NODE_ENV=production BABEL_ENV=commonjs BROWSERSLIST_ENV=node-development jest --config ./config/jest/jest.artifact.config.js",
|
||||
"test:unit": "cross-env NODE_ENV=test BABEL_ENV=commonjs BROWSERSLIST_ENV=node-development jest --config ./config/jest/jest.unit.config.js",
|
||||
"cy:mock-api": "json-server --watch test/e2e-selenium/db.json --port 3204",
|
||||
"cy:server": "cross-env NODE_ENV=production BABEL_ENV=production BROWSERSLIST_ENV=browser-production webpack serve --config webpack/dev-e2e.js",
|
||||
"cy:start": "run-p -r cy:server cy:mock-api",
|
||||
"cy:open": "cross-env BROWSERSLIST_ENV=browser-production cypress open",
|
||||
"cy:run": "cross-env BROWSERSLIST_ENV=browser-production cypress run",
|
||||
"cy:ci": "start-server-and-test cy:start http://localhost:3204 cy:run",
|
||||
"cy:dev": "start-server-and-test cy:start http://localhost:3204 cy:open",
|
||||
"open-static": "npx open-cli http://localhost:3002",
|
||||
"security-audit": "run-s -sc security-audit:all security-audit:prod",
|
||||
"security-audit:prod": "npm-audit-ci-wrapper -p -t low",
|
||||
"security-audit:all": "npm-audit-ci-wrapper -t moderate",
|
||||
"serve-static": "ws -d dist/ --hostname 0.0.0.0 -p 3002",
|
||||
"start": "npm-run-all --parallel serve-static open-static"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs3": "^7.27.1",
|
||||
"@scarf/scarf": "=1.4.0",
|
||||
"base64-js": "^1.5.1",
|
||||
"buffer": "^6.0.3",
|
||||
"classnames": "^2.5.1",
|
||||
"css.escape": "1.5.1",
|
||||
"deep-extend": "0.6.0",
|
||||
"dompurify": "^3.4.0",
|
||||
"ieee754": "^1.2.1",
|
||||
"immutable": "^3.x.x",
|
||||
"js-file-download": "^0.4.12",
|
||||
"js-yaml": "=4.1.1",
|
||||
"lodash": "^4.18.1",
|
||||
"prop-types": "^15.8.1",
|
||||
"randexp": "^0.5.3",
|
||||
"randombytes": "^2.1.0",
|
||||
"react": ">=16.8.0 <20",
|
||||
"react-copy-to-clipboard": "5.1.0",
|
||||
"react-debounce-input": "=3.3.0",
|
||||
"react-dom": ">=16.8.0 <20",
|
||||
"react-immutable-proptypes": "2.2.0",
|
||||
"react-immutable-pure-component": "^2.2.0",
|
||||
"react-inspector": "^6.0.1",
|
||||
"react-redux": "^9.2.0",
|
||||
"react-syntax-highlighter": "^16.0.0",
|
||||
"redux": "^5.0.1",
|
||||
"redux-immutable": "^4.0.0",
|
||||
"remarkable": "^2.0.1",
|
||||
"reselect": "^5.1.1",
|
||||
"serialize-error": "^8.1.0",
|
||||
"sha.js": "^2.4.12",
|
||||
"swagger-client": "^3.37.4",
|
||||
"url-parse": "^1.5.10",
|
||||
"xml": "=1.0.1",
|
||||
"xml-but-prettier": "^1.0.1",
|
||||
"zenscroll": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "=7.26.4",
|
||||
"@babel/core": "=7.26.10",
|
||||
"@babel/eslint-parser": "=7.26.10",
|
||||
"@babel/plugin-transform-runtime": "=7.26.10",
|
||||
"@babel/preset-env": "=7.27.2",
|
||||
"@babel/preset-react": "=7.26.3",
|
||||
"@babel/register": "=7.27.1",
|
||||
"@cfaester/enzyme-adapter-react-18": "=0.8.0",
|
||||
"@commitlint/cli": "^19.8.0",
|
||||
"@commitlint/config-conventional": "^19.8.0",
|
||||
"@jest/globals": "=29.7.0",
|
||||
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.0",
|
||||
"@release-it/conventional-changelog": "=11.0.0",
|
||||
"@svgr/webpack": "=8.1.0",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"babel-loader": "^9.2.1",
|
||||
"babel-plugin-lodash": "=3.3.4",
|
||||
"babel-plugin-module-resolver": "=5.0.2",
|
||||
"babel-plugin-transform-react-remove-prop-types": "=0.4.24",
|
||||
"body-parser": "^1.20.4",
|
||||
"cheerio": "=1.0.0",
|
||||
"copy-webpack-plugin": "14.0.0",
|
||||
"cors": "^2.8.5",
|
||||
"cross-env": "=7.0.3",
|
||||
"css-loader": "=7.1.2",
|
||||
"cssnano": "=7.0.7",
|
||||
"cypress": "=14.2.0",
|
||||
"dedent": "^1.6.0",
|
||||
"deepmerge": "^4.3.1",
|
||||
"enzyme": "=3.11.0",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^10.1.1",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-jest": "^28.12.0",
|
||||
"eslint-plugin-prettier": "^5.2.3",
|
||||
"eslint-plugin-react": "^7.37.4",
|
||||
"esm": "=3.2.25",
|
||||
"expect": "=29.7.0",
|
||||
"express": "^4.22.1",
|
||||
"git-describe": "^4.1.0",
|
||||
"html-webpack-plugin": "^5.6.3",
|
||||
"husky": "=9.1.7",
|
||||
"inspectpack": "=4.7.1",
|
||||
"jest": "=29.7.0",
|
||||
"jest-environment-jsdom": "=29.7.0",
|
||||
"jest-transform-stub": "=2.0.0",
|
||||
"jsdom": "=26.0.0",
|
||||
"json-loader": "^0.5.7",
|
||||
"json-merger": "^2.0.0",
|
||||
"json-server": "=0.17.4",
|
||||
"less": "^4.2.2",
|
||||
"license-checker": "^25.0.0",
|
||||
"lint-staged": "^15.5.0",
|
||||
"local-web-server": "^5.4.0",
|
||||
"mini-css-extract-plugin": "^2.9.2",
|
||||
"npm-audit-ci-wrapper": "^3.0.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"oauth2-server": "^2.4.1",
|
||||
"open": "^10.1.0",
|
||||
"open-cli": "=8.0.0",
|
||||
"postcss": "^8.5.12",
|
||||
"postcss-loader": "^8.1.1",
|
||||
"postcss-preset-env": "^10.1.6",
|
||||
"postcss-scss": "^4.0.9",
|
||||
"prettier": "^3.5.3",
|
||||
"process": "^0.11.10",
|
||||
"react-refresh": "^0.17.0",
|
||||
"react-test-renderer": "^18.3.1",
|
||||
"release-it": "^20.0.1",
|
||||
"rimraf": "^6.0.1",
|
||||
"sass-embedded": "=1.86.0",
|
||||
"sass-loader": "^16.0.4",
|
||||
"shx": "=0.4.0",
|
||||
"sinon": "21.0.1",
|
||||
"source-map-support": "^0.5.21",
|
||||
"start-server-and-test": "^2.0.11",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"stylelint": "^16.19.1",
|
||||
"stylelint-prettier": "^5.0.3",
|
||||
"tachyons-sass": "^4.9.5",
|
||||
"terser-webpack-plugin": "^5.3.17",
|
||||
"webpack": "^5.97.1",
|
||||
"webpack-bundle-size-analyzer": "^3.1.0",
|
||||
"webpack-cli": "^6.0.1",
|
||||
"webpack-dev-server": "^5.2.2",
|
||||
"webpack-node-externals": "=3.0.0",
|
||||
"webpack-stats-plugin": "=1.1.3"
|
||||
},
|
||||
"overrides": {
|
||||
"@pmmmwh/react-refresh-webpack-plugin": {
|
||||
"webpack-dev-server": "$webpack-dev-server"
|
||||
},
|
||||
"enzyme": {
|
||||
"cheerio": "=1.0.0-rc.12"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"deps_check_dir": ".deps_check"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"hooks": {
|
||||
"before:bump": [
|
||||
"./release/check-for-breaking-changes.sh ${latestVersion} ${version}",
|
||||
"npm update swagger-client",
|
||||
"npm test"
|
||||
],
|
||||
"after:bump": ["npm run build"],
|
||||
"after:release": "export GIT_TAG=v${version} && echo GIT_TAG=v${version} > release/.version"
|
||||
},
|
||||
"git": {
|
||||
"requireUpstream": false,
|
||||
"changelog": "./release/get-changelog.sh",
|
||||
"commitMessage": "chore(release): cut the v${version} release",
|
||||
"tagName": "v${version}",
|
||||
"push": false
|
||||
},
|
||||
"github": {
|
||||
"release": true,
|
||||
"releaseName": "Swagger UI v${version} Released!",
|
||||
"draft": true
|
||||
},
|
||||
"plugins": {
|
||||
"@release-it/conventional-changelog": {
|
||||
"preset": "angular"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
CURRENT_VERSION=$1
|
||||
NEXT_VERSION=$2
|
||||
CURRENT_MAJOR=${CURRENT_VERSION:0:1}
|
||||
NEXT_MAJOR=${NEXT_VERSION:0:1}
|
||||
|
||||
if [ "$CURRENT_MAJOR" -ne "$NEXT_MAJOR" ] ;
|
||||
then if [ "$BREAKING_OKAY" = "true" ];
|
||||
then echo "breaking change detected but BREAKING_OKAY is set; continuing." && exit 0;
|
||||
else echo "breaking change detected and BREAKING_OKAY is not set; aborting." && exit 1;
|
||||
fi;
|
||||
fi;
|
||||
|
||||
echo "next version is not a breaking change; continuing.";
|
||||
@@ -0,0 +1,5 @@
|
||||
echo "_No release summary included._\n\n#### Changelog\n"
|
||||
|
||||
PREV_RELEASE_REF=$(git log --pretty=oneline | grep ' release: ' | head -n 2 | tail -n 1 | cut -f 1 -d " ")
|
||||
|
||||
git log --pretty=oneline $PREV_RELEASE_REF..HEAD | awk '{ $1=""; print}' | sed -e 's/^[ \t]*//' | sed 's/^feat/0,feat/' | sed 's/^improve/1,improve/' | sed 's/^fix/2,fix/'| sort | sed 's/^[0-2],//' | sed 's/^/* /'
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
name: swagger-ui
|
||||
version: master
|
||||
summary: The World's Most Popular API Framework
|
||||
description: |
|
||||
Swagger UI is part of the Swagger project. The Swagger project allows you to
|
||||
produce, visualize and consume your OWN RESTful services. No proxy or 3rd
|
||||
party services required. Do it your own way.
|
||||
|
||||
Swagger UI is a dependency-free collection of HTML, Javascript, and CSS
|
||||
assets that dynamically generate beautiful documentation and sandbox from a
|
||||
Swagger-compliant API. Because Swagger UI has no dependencies, you can host
|
||||
it in any server environment, or on your local machine.
|
||||
|
||||
grade: devel
|
||||
confinement: strict
|
||||
|
||||
apps:
|
||||
swagger-ui:
|
||||
command: sh -c \"cd $SNAP/lib/node_modules/swagger-ui/dist && http-server -a localhost -p 8080\"
|
||||
daemon: simple
|
||||
plugs: [network, network-bind]
|
||||
|
||||
parts:
|
||||
swagger-ui:
|
||||
source: .
|
||||
plugin: nodejs
|
||||
npm-run: [build]
|
||||
node-packages: [handlebars, http-server]
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"rules": {
|
||||
"import/no-extraneous-dependencies": [
|
||||
2,
|
||||
{
|
||||
"devDependencies": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg width="200px" height="200px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="lds-rolling" style="background-image: none; background-position: initial initial; background-repeat: initial initial;"><circle cx="50" cy="50" fill="none" ng-attr-stroke="{{config.color}}" ng-attr-stroke-width="{{config.width}}" ng-attr-r="{{config.radius}}" ng-attr-stroke-dasharray="{{config.dasharray}}" stroke="#555555" stroke-width="10" r="35" stroke-dasharray="164.93361431346415 56.97787143782138"><animateTransform attributeName="transform" type="rotate" calcMode="linear" values="0 50 50;360 50 50" keyTimes="0;1" dur="1s" begin="0s" repeatCount="indefinite"></animateTransform></circle></svg>
|
||||
|
After Width: | Height: | Size: 734 B |
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
class App extends React.Component {
|
||||
getLayout() {
|
||||
const { getComponent, layoutSelectors } = this.props
|
||||
const layoutName = layoutSelectors.current()
|
||||
const Component = getComponent(layoutName, true)
|
||||
|
||||
return Component
|
||||
? Component
|
||||
: () => <h1> No layout defined for "{layoutName}" </h1>
|
||||
}
|
||||
|
||||
render() {
|
||||
const Layout = this.getLayout()
|
||||
|
||||
return <Layout />
|
||||
}
|
||||
}
|
||||
|
||||
App.propTypes = {
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
layoutSelectors: PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
export default App
|
||||
@@ -0,0 +1,93 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export default class ApiKeyAuth extends React.Component {
|
||||
static propTypes = {
|
||||
authorized: PropTypes.object,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
errSelectors: PropTypes.object.isRequired,
|
||||
schema: PropTypes.object.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
onChange: PropTypes.func,
|
||||
authSelectors: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
let { name, schema } = this.props
|
||||
let value = this.getValue()
|
||||
|
||||
this.state = {
|
||||
name: name,
|
||||
schema: schema,
|
||||
value: value
|
||||
}
|
||||
}
|
||||
|
||||
getValue () {
|
||||
let { name, authorized } = this.props
|
||||
|
||||
return authorized && authorized.getIn([name, "value"])
|
||||
}
|
||||
|
||||
onChange =(e) => {
|
||||
let { onChange } = this.props
|
||||
let value = e.target.value
|
||||
let newState = Object.assign({}, this.state, { value: value })
|
||||
|
||||
this.setState(newState)
|
||||
onChange(newState)
|
||||
}
|
||||
|
||||
render() {
|
||||
let { schema, getComponent, errSelectors, name, authSelectors } = this.props
|
||||
const Input = getComponent("Input")
|
||||
const Row = getComponent("Row")
|
||||
const Col = getComponent("Col")
|
||||
const AuthError = getComponent("authError")
|
||||
const Markdown = getComponent("Markdown", true)
|
||||
const JumpToPath = getComponent("JumpToPath", true)
|
||||
const path = authSelectors.selectAuthPath(name)
|
||||
let value = this.getValue()
|
||||
let errors = errSelectors.allErrors().filter( err => err.get("authId") === name)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h4>
|
||||
<code>{ name || schema.get("name") }</code> (apiKey)
|
||||
<JumpToPath path={path} />
|
||||
</h4>
|
||||
{ value && <h6>Authorized</h6>}
|
||||
<Row>
|
||||
<Markdown source={ schema.get("description") } />
|
||||
</Row>
|
||||
<Row>
|
||||
<p>Name: <code>{ schema.get("name") }</code></p>
|
||||
</Row>
|
||||
<Row>
|
||||
<p>In: <code>{ schema.get("in") }</code></p>
|
||||
</Row>
|
||||
<Row>
|
||||
<label htmlFor="api_key_value">Value:</label>
|
||||
{
|
||||
value ? <code> ****** </code>
|
||||
: <Col>
|
||||
<Input
|
||||
id="api_key_value"
|
||||
type="text"
|
||||
onChange={ this.onChange }
|
||||
autoFocus
|
||||
/>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
{
|
||||
errors.valueSeq().map( (error, key) => {
|
||||
return <AuthError error={ error }
|
||||
key={ key }/>
|
||||
} )
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import ImPropTypes from "react-immutable-proptypes"
|
||||
|
||||
export default class Auths extends React.Component {
|
||||
static propTypes = {
|
||||
authorized: ImPropTypes.orderedMap.isRequired,
|
||||
schema: ImPropTypes.orderedMap.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
onAuthChange: PropTypes.func.isRequired,
|
||||
errSelectors: PropTypes.object.isRequired,
|
||||
authSelectors: PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
let {
|
||||
schema,
|
||||
name,
|
||||
getComponent,
|
||||
onAuthChange,
|
||||
authorized,
|
||||
errSelectors,
|
||||
authSelectors
|
||||
} = this.props
|
||||
const ApiKeyAuth = getComponent("apiKeyAuth")
|
||||
const BasicAuth = getComponent("basicAuth")
|
||||
|
||||
let authEl
|
||||
|
||||
const type = schema.get("type")
|
||||
|
||||
switch(type) {
|
||||
case "apiKey": authEl = <ApiKeyAuth key={ name }
|
||||
schema={ schema }
|
||||
name={ name }
|
||||
errSelectors={ errSelectors }
|
||||
authorized={ authorized }
|
||||
getComponent={ getComponent }
|
||||
onChange={ onAuthChange }
|
||||
authSelectors = { authSelectors } />
|
||||
break
|
||||
case "basic": authEl = <BasicAuth key={ name }
|
||||
schema={ schema }
|
||||
name={ name }
|
||||
errSelectors={ errSelectors }
|
||||
authorized={ authorized }
|
||||
getComponent={ getComponent }
|
||||
onChange={ onAuthChange }
|
||||
authSelectors = { authSelectors } />
|
||||
break
|
||||
default: authEl = <div key={ name }>Unknown security definition type { type }</div>
|
||||
}
|
||||
|
||||
return (<div key={`${name}-jump`}>
|
||||
{ authEl }
|
||||
</div>)
|
||||
}
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export default class AuthorizationPopup extends React.Component {
|
||||
close =() => {
|
||||
let { authActions } = this.props
|
||||
|
||||
authActions.showDefinitions(false)
|
||||
}
|
||||
|
||||
render() {
|
||||
let { authSelectors, authActions, getComponent, errSelectors, specSelectors, fn: { AST = {} } } = this.props
|
||||
let definitions = authSelectors.shownDefinitions()
|
||||
const Auths = getComponent("auths")
|
||||
const CloseIcon = getComponent("CloseIcon")
|
||||
|
||||
return (
|
||||
<div className="dialog-ux">
|
||||
<div className="backdrop-ux"></div>
|
||||
<div className="modal-ux">
|
||||
<div className="modal-dialog-ux">
|
||||
<div className="modal-ux-inner">
|
||||
<div className="modal-ux-header">
|
||||
<h3>Available authorizations</h3>
|
||||
<button type="button" className="close-modal" onClick={ this.close }>
|
||||
<CloseIcon />
|
||||
</button>
|
||||
</div>
|
||||
<div className="modal-ux-content">
|
||||
|
||||
{
|
||||
definitions.valueSeq().map(( definition, key ) => {
|
||||
return <Auths key={ key }
|
||||
AST={AST}
|
||||
definitions={ definition }
|
||||
getComponent={ getComponent }
|
||||
errSelectors={ errSelectors }
|
||||
authSelectors={ authSelectors }
|
||||
authActions={ authActions }
|
||||
specSelectors={ specSelectors }/>
|
||||
})
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
fn: PropTypes.object.isRequired,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
authSelectors: PropTypes.object.isRequired,
|
||||
specSelectors: PropTypes.object.isRequired,
|
||||
errSelectors: PropTypes.object.isRequired,
|
||||
authActions: PropTypes.object.isRequired,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export default class AuthorizeBtn extends React.Component {
|
||||
static propTypes = {
|
||||
onClick: PropTypes.func,
|
||||
isAuthorized: PropTypes.bool,
|
||||
showPopup: PropTypes.bool,
|
||||
getComponent: PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
render() {
|
||||
let { isAuthorized, showPopup, onClick, getComponent } = this.props
|
||||
|
||||
//must be moved out of button component
|
||||
const AuthorizationPopup = getComponent("authorizationPopup", true)
|
||||
const LockAuthIcon = getComponent("LockAuthIcon", true)
|
||||
const UnlockAuthIcon = getComponent("UnlockAuthIcon", true)
|
||||
|
||||
return (
|
||||
<div className="auth-wrapper">
|
||||
<button className={isAuthorized ? "btn authorize locked" : "btn authorize unlocked"} onClick={onClick}>
|
||||
<span>Authorize</span>
|
||||
{isAuthorized ? <LockAuthIcon /> : <UnlockAuthIcon />}
|
||||
</button>
|
||||
{ showPopup && <AuthorizationPopup /> }
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export default class AuthorizeOperationBtn extends React.Component {
|
||||
static propTypes = {
|
||||
isAuthorized: PropTypes.bool.isRequired,
|
||||
onClick: PropTypes.func,
|
||||
getComponent: PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
onClick =(e) => {
|
||||
e.stopPropagation()
|
||||
let { onClick } = this.props
|
||||
|
||||
if(onClick) {
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
let { isAuthorized, getComponent } = this.props
|
||||
|
||||
const LockAuthOperationIcon = getComponent("LockAuthOperationIcon", true)
|
||||
const UnlockAuthOperationIcon = getComponent("UnlockAuthOperationIcon", true)
|
||||
|
||||
return (
|
||||
<button className="authorization__btn"
|
||||
aria-label={isAuthorized ? "authorization button locked" : "authorization button unlocked"}
|
||||
onClick={this.onClick}>
|
||||
{isAuthorized ? <LockAuthOperationIcon className="locked" /> : <UnlockAuthOperationIcon className="unlocked"/>}
|
||||
</button>
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import ImPropTypes from "react-immutable-proptypes"
|
||||
|
||||
export default class Auths extends React.Component {
|
||||
static propTypes = {
|
||||
definitions: ImPropTypes.iterable.isRequired,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
authSelectors: PropTypes.object.isRequired,
|
||||
authActions: PropTypes.object.isRequired,
|
||||
errSelectors: PropTypes.object.isRequired,
|
||||
specSelectors: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
|
||||
this.state = {}
|
||||
}
|
||||
|
||||
onAuthChange =(auth) => {
|
||||
let { name } = auth
|
||||
|
||||
this.setState({ [name]: auth })
|
||||
}
|
||||
|
||||
submitAuth =(e) => {
|
||||
e.preventDefault()
|
||||
|
||||
let { authActions } = this.props
|
||||
authActions.authorizeWithPersistOption(this.state)
|
||||
}
|
||||
|
||||
logoutClick =(e) => {
|
||||
e.preventDefault()
|
||||
|
||||
let { authActions, definitions } = this.props
|
||||
let auths = definitions.map( (val, key) => {
|
||||
return key
|
||||
}).toArray()
|
||||
|
||||
this.setState(auths.reduce((prev, auth) => {
|
||||
prev[auth] = ""
|
||||
return prev
|
||||
}, {}))
|
||||
|
||||
authActions.logoutWithPersistOption(auths)
|
||||
}
|
||||
|
||||
close =(e) => {
|
||||
e.preventDefault()
|
||||
let { authActions } = this.props
|
||||
|
||||
authActions.showDefinitions(false)
|
||||
}
|
||||
|
||||
render() {
|
||||
let { definitions, getComponent, authSelectors, errSelectors } = this.props
|
||||
const AuthItem = getComponent("AuthItem")
|
||||
const Oauth2 = getComponent("oauth2", true)
|
||||
const Button = getComponent("Button")
|
||||
|
||||
let authorized = authSelectors.authorized()
|
||||
|
||||
let authorizedAuth = definitions.filter( (definition, key) => {
|
||||
return !!authorized.get(key)
|
||||
})
|
||||
|
||||
let nonOauthDefinitions = definitions.filter( schema => schema.get("type") !== "oauth2")
|
||||
let oauthDefinitions = definitions.filter( schema => schema.get("type") === "oauth2")
|
||||
|
||||
return (
|
||||
<div className="auth-container">
|
||||
{
|
||||
!!nonOauthDefinitions.size && <form onSubmit={ this.submitAuth }>
|
||||
{
|
||||
nonOauthDefinitions.map( (schema, name) => {
|
||||
return <AuthItem
|
||||
key={name}
|
||||
schema={schema}
|
||||
name={name}
|
||||
getComponent={getComponent}
|
||||
onAuthChange={this.onAuthChange}
|
||||
authorized={authorized}
|
||||
errSelectors={errSelectors}
|
||||
authSelectors={authSelectors}
|
||||
/>
|
||||
}).toArray()
|
||||
}
|
||||
<div className="auth-btn-wrapper">
|
||||
{
|
||||
nonOauthDefinitions.size === authorizedAuth.size ? <Button className="btn modal-btn auth" onClick={ this.logoutClick } aria-label="Remove authorization">Logout</Button>
|
||||
: <Button type="submit" className="btn modal-btn auth authorize" aria-label="Apply credentials">Authorize</Button>
|
||||
}
|
||||
<Button className="btn modal-btn auth btn-done" onClick={ this.close }>Close</Button>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
|
||||
{
|
||||
oauthDefinitions && oauthDefinitions.size ? <div>
|
||||
<div className="scope-def">
|
||||
<p>Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.</p>
|
||||
<p>API requires the following scopes. Select which ones you want to grant to Swagger UI.</p>
|
||||
</div>
|
||||
{
|
||||
definitions.filter( schema => schema.get("type") === "oauth2")
|
||||
.map( (schema, name) =>{
|
||||
return (<div key={ name }>
|
||||
<Oauth2 authorized={ authorized }
|
||||
schema={ schema }
|
||||
name={ name } />
|
||||
</div>)
|
||||
}
|
||||
).toArray()
|
||||
}
|
||||
</div> : null
|
||||
}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import ImPropTypes from "react-immutable-proptypes"
|
||||
|
||||
export default class BasicAuth extends React.Component {
|
||||
static propTypes = {
|
||||
authorized: ImPropTypes.map,
|
||||
schema: ImPropTypes.map,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
errSelectors: PropTypes.object.isRequired,
|
||||
authSelectors: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
let { schema, name } = this.props
|
||||
|
||||
let value = this.getValue()
|
||||
let username = value.username
|
||||
|
||||
this.state = {
|
||||
name: name,
|
||||
schema: schema,
|
||||
value: !username ? {} : {
|
||||
username: username
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getValue () {
|
||||
let { authorized, name } = this.props
|
||||
|
||||
return authorized && authorized.getIn([name, "value"]) || {}
|
||||
}
|
||||
|
||||
onChange =(e) => {
|
||||
let { onChange } = this.props
|
||||
let { value, name } = e.target
|
||||
|
||||
let newValue = this.state.value
|
||||
newValue[name] = value
|
||||
|
||||
this.setState({ value: newValue })
|
||||
|
||||
onChange(this.state)
|
||||
}
|
||||
|
||||
render() {
|
||||
let { schema, getComponent, name, errSelectors, authSelectors } = this.props
|
||||
const Input = getComponent("Input")
|
||||
const Row = getComponent("Row")
|
||||
const Col = getComponent("Col")
|
||||
const AuthError = getComponent("authError")
|
||||
const JumpToPath = getComponent("JumpToPath", true)
|
||||
const Markdown = getComponent("Markdown", true)
|
||||
const path = authSelectors.selectAuthPath(name)
|
||||
let username = this.getValue().username
|
||||
let errors = errSelectors.allErrors().filter( err => err.get("authId") === name)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h4>Basic authorization<JumpToPath path={path} /></h4>
|
||||
{ username && <h6>Authorized</h6> }
|
||||
<Row>
|
||||
<Markdown source={ schema.get("description") } />
|
||||
</Row>
|
||||
<Row>
|
||||
<label htmlFor="auth_username">Username:</label>
|
||||
{
|
||||
username ? <code> { username } </code>
|
||||
: <Col>
|
||||
<Input
|
||||
id="auth_username"
|
||||
type="text"
|
||||
required="required"
|
||||
name="username"
|
||||
onChange={ this.onChange }
|
||||
autoFocus
|
||||
/>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
<Row>
|
||||
<label htmlFor="auth_password">Password:</label>
|
||||
{
|
||||
username ? <code> ****** </code>
|
||||
: <Col>
|
||||
<Input
|
||||
id="auth_password"
|
||||
autoComplete="new-password"
|
||||
name="password"
|
||||
type="password"
|
||||
onChange={ this.onChange }
|
||||
/>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
{
|
||||
errors.valueSeq().map( (error, key) => {
|
||||
return <AuthError error={ error }
|
||||
key={ key }/>
|
||||
} )
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export default class AuthError extends React.Component {
|
||||
|
||||
static propTypes = {
|
||||
error: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
render() {
|
||||
let { error } = this.props
|
||||
|
||||
let level = error.get("level")
|
||||
let message = error.get("message")
|
||||
let source = error.get("source")
|
||||
|
||||
return (
|
||||
<div className="errors">
|
||||
<b>{ source } { level }</b>
|
||||
<span>{ message }</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import oauth2Authorize from "core/oauth2-authorize"
|
||||
|
||||
export default class Oauth2 extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string,
|
||||
authorized: PropTypes.object,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
schema: PropTypes.object.isRequired,
|
||||
authSelectors: PropTypes.object.isRequired,
|
||||
authActions: PropTypes.object.isRequired,
|
||||
errSelectors: PropTypes.object.isRequired,
|
||||
oas3Selectors: PropTypes.object.isRequired,
|
||||
specSelectors: PropTypes.object.isRequired,
|
||||
errActions: PropTypes.object.isRequired,
|
||||
getConfigs: PropTypes.any
|
||||
}
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
let { name, schema, authorized, authSelectors } = this.props
|
||||
let auth = authorized && authorized.get(name)
|
||||
let authConfigs = authSelectors.getConfigs() || {}
|
||||
let username = auth && auth.get("username") || ""
|
||||
let clientId = auth && auth.get("clientId") || authConfigs.clientId || ""
|
||||
let clientSecret = auth && auth.get("clientSecret") || authConfigs.clientSecret || ""
|
||||
let passwordType = auth && auth.get("passwordType") || "basic"
|
||||
let scopes = auth && auth.get("scopes") || authConfigs.scopes || []
|
||||
if (typeof scopes === "string") {
|
||||
scopes = scopes.split(authConfigs.scopeSeparator || " ")
|
||||
}
|
||||
|
||||
this.state = {
|
||||
appName: authConfigs.appName,
|
||||
name: name,
|
||||
schema: schema,
|
||||
scopes: scopes,
|
||||
clientId: clientId,
|
||||
clientSecret: clientSecret,
|
||||
username: username,
|
||||
password: "",
|
||||
passwordType: passwordType
|
||||
}
|
||||
}
|
||||
|
||||
close = (e) => {
|
||||
e.preventDefault()
|
||||
let { authActions } = this.props
|
||||
|
||||
authActions.showDefinitions(false)
|
||||
}
|
||||
|
||||
authorize =() => {
|
||||
let { authActions, errActions, getConfigs, authSelectors, oas3Selectors } = this.props
|
||||
let configs = getConfigs()
|
||||
let authConfigs = authSelectors.getConfigs()
|
||||
|
||||
errActions.clear({authId: name,type: "auth", source: "auth"})
|
||||
oauth2Authorize({
|
||||
auth: this.state,
|
||||
currentServer: oas3Selectors.serverEffectiveValue(oas3Selectors.selectedServer()),
|
||||
authActions,
|
||||
errActions,
|
||||
configs,
|
||||
authConfigs
|
||||
})
|
||||
}
|
||||
|
||||
onScopeChange =(e) => {
|
||||
let { target } = e
|
||||
let { checked } = target
|
||||
let scope = target.dataset.value
|
||||
|
||||
if ( checked && this.state.scopes.indexOf(scope) === -1 ) {
|
||||
let newScopes = this.state.scopes.concat([scope])
|
||||
this.setState({ scopes: newScopes })
|
||||
} else if ( !checked && this.state.scopes.indexOf(scope) > -1) {
|
||||
this.setState({ scopes: this.state.scopes.filter((val) => val !== scope) })
|
||||
}
|
||||
}
|
||||
|
||||
onInputChange =(e) => {
|
||||
let { target : { dataset : { name }, value } } = e
|
||||
let state = {
|
||||
[name]: value
|
||||
}
|
||||
|
||||
this.setState(state)
|
||||
}
|
||||
|
||||
selectScopes =(e) => {
|
||||
if (e.target.dataset.all) {
|
||||
this.setState({
|
||||
scopes: Array.from((this.props.schema.get("allowedScopes") || this.props.schema.get("scopes")).keys())
|
||||
})
|
||||
} else {
|
||||
this.setState({ scopes: [] })
|
||||
}
|
||||
}
|
||||
|
||||
logout =(e) => {
|
||||
e.preventDefault()
|
||||
let { authActions, errActions, name } = this.props
|
||||
|
||||
errActions.clear({authId: name, type: "auth", source: "auth"})
|
||||
authActions.logoutWithPersistOption([ name ])
|
||||
}
|
||||
|
||||
render() {
|
||||
let {
|
||||
schema, getComponent, authSelectors, errSelectors, name, specSelectors
|
||||
} = this.props
|
||||
const Input = getComponent("Input")
|
||||
const Row = getComponent("Row")
|
||||
const Col = getComponent("Col")
|
||||
const Button = getComponent("Button")
|
||||
const AuthError = getComponent("authError")
|
||||
const JumpToPath = getComponent("JumpToPath", true)
|
||||
const Markdown = getComponent("Markdown", true)
|
||||
const InitializedInput = getComponent("InitializedInput")
|
||||
|
||||
const { isOAS3 } = specSelectors
|
||||
|
||||
let oidcUrl = isOAS3() ? schema.get("openIdConnectUrl") : null
|
||||
|
||||
// Auth type consts
|
||||
const AUTH_FLOW_IMPLICIT = "implicit"
|
||||
const AUTH_FLOW_PASSWORD = "password"
|
||||
const AUTH_FLOW_ACCESS_CODE = isOAS3() ? (oidcUrl ? "authorization_code" : "authorizationCode") : "accessCode"
|
||||
const AUTH_FLOW_APPLICATION = isOAS3() ? (oidcUrl ? "client_credentials" : "clientCredentials") : "application"
|
||||
|
||||
const path = authSelectors.selectAuthPath(name)
|
||||
|
||||
let authConfigs = authSelectors.getConfigs() || {}
|
||||
let isPkceCodeGrant = !!authConfigs.usePkceWithAuthorizationCodeGrant
|
||||
|
||||
let flow = schema.get("flow")
|
||||
let flowToDisplay = flow === AUTH_FLOW_ACCESS_CODE && isPkceCodeGrant ? flow + " with PKCE" : flow
|
||||
let scopes = schema.get("allowedScopes") || schema.get("scopes")
|
||||
let authorizedAuth = authSelectors.authorized().get(name)
|
||||
let isAuthorized = !!authorizedAuth
|
||||
let errors = errSelectors.allErrors().filter( err => err.get("authId") === name)
|
||||
let isValid = !errors.filter( err => err.get("source") === "validation").size
|
||||
let description = schema.get("description")
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h4>{name} (OAuth2, { flowToDisplay }) <JumpToPath path={path} /></h4>
|
||||
{ !this.state.appName ? null : <h5>Application: { this.state.appName } </h5> }
|
||||
{ description && <Markdown source={ schema.get("description") } /> }
|
||||
|
||||
{ isAuthorized && <h6>Authorized</h6> }
|
||||
|
||||
{ oidcUrl && <p>OpenID Connect URL: <code>{ oidcUrl }</code></p> }
|
||||
{ ( flow === AUTH_FLOW_IMPLICIT || flow === AUTH_FLOW_ACCESS_CODE ) && <p>Authorization URL: <code>{ schema.get("authorizationUrl") }</code></p> }
|
||||
{ ( flow === AUTH_FLOW_PASSWORD || flow === AUTH_FLOW_ACCESS_CODE || flow === AUTH_FLOW_APPLICATION ) && <p>Token URL:<code> { schema.get("tokenUrl") }</code></p> }
|
||||
<p className="flow">Flow: <code>{ flowToDisplay }</code></p>
|
||||
|
||||
{
|
||||
flow !== AUTH_FLOW_PASSWORD ? null
|
||||
: <Row>
|
||||
<Row>
|
||||
<label htmlFor="oauth_username">username:</label>
|
||||
{
|
||||
isAuthorized ? <code> { this.state.username } </code>
|
||||
: <Col tablet={10} desktop={10}>
|
||||
<input id="oauth_username" type="text" data-name="username" onChange={ this.onInputChange } autoFocus/>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
{
|
||||
|
||||
}
|
||||
<Row>
|
||||
<label htmlFor="oauth_password">password:</label>
|
||||
{
|
||||
isAuthorized ? <code> ****** </code>
|
||||
: <Col tablet={10} desktop={10}>
|
||||
<input id="oauth_password" type="password" data-name="password" onChange={ this.onInputChange }/>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
<Row>
|
||||
<label htmlFor="password_type">Client credentials location:</label>
|
||||
{
|
||||
isAuthorized ? <code> { this.state.passwordType } </code>
|
||||
: <Col tablet={10} desktop={10}>
|
||||
<select id="password_type" data-name="passwordType" onChange={ this.onInputChange }>
|
||||
<option value="basic">Authorization header</option>
|
||||
<option value="request-body">Request body</option>
|
||||
</select>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
</Row>
|
||||
}
|
||||
{
|
||||
( flow === AUTH_FLOW_APPLICATION || flow === AUTH_FLOW_IMPLICIT || flow === AUTH_FLOW_ACCESS_CODE || flow === AUTH_FLOW_PASSWORD ) &&
|
||||
( !isAuthorized || isAuthorized && this.state.clientId) && <Row>
|
||||
<label htmlFor={ `client_id_${flow}` }>client_id:</label>
|
||||
{
|
||||
isAuthorized ? <code> ****** </code>
|
||||
: <Col tablet={10} desktop={10}>
|
||||
<InitializedInput id={`client_id_${flow}`}
|
||||
type="text"
|
||||
required={ flow === AUTH_FLOW_PASSWORD }
|
||||
initialValue={ this.state.clientId }
|
||||
data-name="clientId"
|
||||
onChange={ this.onInputChange }/>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
}
|
||||
|
||||
{
|
||||
( (flow === AUTH_FLOW_APPLICATION || flow === AUTH_FLOW_ACCESS_CODE || flow === AUTH_FLOW_PASSWORD) && <Row>
|
||||
<label htmlFor={ `client_secret_${flow}` }>client_secret:</label>
|
||||
{
|
||||
isAuthorized ? <code> ****** </code>
|
||||
: <Col tablet={10} desktop={10}>
|
||||
<InitializedInput id={ `client_secret_${flow}` }
|
||||
initialValue={ this.state.clientSecret }
|
||||
type="password"
|
||||
data-name="clientSecret"
|
||||
onChange={ this.onInputChange }/>
|
||||
</Col>
|
||||
}
|
||||
|
||||
</Row>
|
||||
)}
|
||||
|
||||
{
|
||||
!isAuthorized && scopes && scopes.size ? <div className="scopes">
|
||||
<h2>
|
||||
Scopes:
|
||||
<a onClick={this.selectScopes} data-all={true}>select all</a>
|
||||
<a onClick={this.selectScopes}>select none</a>
|
||||
</h2>
|
||||
{ scopes.map((description, name) => {
|
||||
return (
|
||||
<Row key={ name }>
|
||||
<div className="checkbox">
|
||||
<Input data-value={ name }
|
||||
id={`${name}-${flow}-checkbox-${this.state.name}`}
|
||||
disabled={ isAuthorized }
|
||||
checked={ this.state.scopes.includes(name) }
|
||||
type="checkbox"
|
||||
onChange={ this.onScopeChange }/>
|
||||
<label htmlFor={`${name}-${flow}-checkbox-${this.state.name}`}>
|
||||
<span className="item"></span>
|
||||
<div className="text">
|
||||
<p className="name">{name}</p>
|
||||
<p className="description">{description}</p>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</Row>
|
||||
)
|
||||
}).toArray()
|
||||
}
|
||||
</div> : null
|
||||
}
|
||||
|
||||
{
|
||||
errors.valueSeq().map( (error, key) => {
|
||||
return <AuthError error={ error }
|
||||
key={ key }/>
|
||||
} )
|
||||
}
|
||||
<div className="auth-btn-wrapper">
|
||||
{ isValid &&
|
||||
( isAuthorized ? <Button className="btn modal-btn auth authorize" onClick={ this.logout } aria-label="Remove authorization">Logout</Button>
|
||||
: <Button className="btn modal-btn auth authorize" onClick={ this.authorize } aria-label="Apply given OAuth2 credentials">Authorize</Button>
|
||||
)
|
||||
}
|
||||
<Button className="btn modal-btn auth btn-done" onClick={ this.close }>Close</Button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import React, { Component } from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export default class Clear extends Component {
|
||||
|
||||
onClick =() => {
|
||||
let { specActions, path, method } = this.props
|
||||
specActions.clearResponse( path, method )
|
||||
specActions.clearRequest( path, method )
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<button className="btn btn-clear opblock-control__btn" onClick={ this.onClick }>
|
||||
Clear
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
specActions: PropTypes.object.isRequired,
|
||||
path: PropTypes.string.isRequired,
|
||||
method: PropTypes.string.isRequired,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { safeBuildUrl, sanitizeUrl } from "core/utils/url"
|
||||
|
||||
class Contact extends React.Component {
|
||||
static propTypes = {
|
||||
data: PropTypes.object,
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
specSelectors: PropTypes.object.isRequired,
|
||||
selectedServer: PropTypes.string,
|
||||
url: PropTypes.string.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, getComponent, selectedServer, url: specUrl } = this.props
|
||||
const name = data.get("name", "the developer")
|
||||
const url = safeBuildUrl(data.get("url"), specUrl, { selectedServer })
|
||||
const email = data.get("email")
|
||||
|
||||
const Link = getComponent("Link")
|
||||
|
||||
return (
|
||||
<div className="info__contact">
|
||||
{url && (
|
||||
<div>
|
||||
<Link href={sanitizeUrl(url)} target="_blank">
|
||||
{name} - Website
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
{email && (
|
||||
<Link href={sanitizeUrl(`mailto:${email}`)}>
|
||||
{url ? `Send email to ${name}` : `Contact ${name}`}
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Contact
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user