-
Notifications
You must be signed in to change notification settings - Fork 14
Reintroduce OpenAPI v3.2 Specification - with version selector #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,44 @@ | ||
| import { Controller } from "@hotwired/stimulus" | ||
| export default class Toggle extends Controller { | ||
| static targets = ["button", "item"] | ||
| click() { | ||
|
|
||
| connect() { | ||
| this.handleClickOutside = this.handleClickOutside.bind(this) | ||
| document.addEventListener('click', this.handleClickOutside) | ||
| } | ||
|
|
||
| disconnect() { | ||
| document.removeEventListener('click', this.handleClickOutside) | ||
| } | ||
|
|
||
| handleClickOutside(event) { | ||
| if (this.itemTarget.getAttribute("data-toggle-active") === "true" && | ||
| !this.element.contains(event.target)) { | ||
| this.close() | ||
| } | ||
| } | ||
|
|
||
| click(event) { | ||
| event.stopPropagation() | ||
|
|
||
| if (this.itemTarget.getAttribute("data-toggle-active") === "true") { | ||
| this.buttonTarget.setAttribute("aria-pressed", false) | ||
| this.itemTarget.setAttribute("data-toggle-active", false) | ||
| this.close() | ||
| } else { | ||
| this.buttonTarget.setAttribute("aria-pressed", true) | ||
| this.itemTarget.setAttribute("data-toggle-active", true) | ||
| this.open() | ||
| } | ||
| } | ||
|
|
||
| open() { | ||
| this.buttonTarget.setAttribute("aria-pressed", true) | ||
| this.buttonTarget.setAttribute("aria-expanded", true) | ||
| this.itemTarget.setAttribute("data-toggle-active", true) | ||
| this.element.setAttribute("data-toggle-active", true) | ||
| } | ||
|
|
||
| close() { | ||
| this.buttonTarget.setAttribute("aria-pressed", false) | ||
| this.buttonTarget.setAttribute("aria-expanded", false) | ||
| this.itemTarget.setAttribute("data-toggle-active", false) | ||
| this.element.setAttribute("data-toggle-active", false) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| .dropdown { | ||
| position: relative; | ||
| } | ||
|
|
||
| .dropdown-trigger { | ||
| align-items: center; | ||
| gap: var(--spacing-3); | ||
| background: none; | ||
| border: none; | ||
| color: var(--text-color); | ||
| padding: 0px; | ||
| cursor: pointer; | ||
| font-size: var(--text-base); | ||
| } | ||
|
|
||
| .dropdown-label { | ||
| color: var(--text-color) | ||
| } | ||
|
|
||
| .dropdown-caret { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| transition: transform 0.2s ease-in-out; | ||
| } | ||
|
|
||
|
|
||
| .dropdown[data-toggle-active="true"] .dropdown-caret { | ||
| transform: rotate(90deg); | ||
| } | ||
|
|
||
| .dropdown-menu { | ||
| position: absolute; | ||
| right: -6px; | ||
| background: var(--bg-color); | ||
| border: var(--border-default); | ||
| border-radius: calc(var(--spacing-px) + var(--spacing-05)); | ||
| box-shadow: 0 8px 24px rgba(var(--black-rgb), 0.12); | ||
| z-index: 20; | ||
| display: none; | ||
| padding: var(--spacing-1); | ||
| } | ||
|
|
||
| .dropdown-menu[data-toggle-active="true"] { | ||
| display: block; | ||
| width: 70px; | ||
| } | ||
|
|
||
| .dropdown-list { | ||
| list-style: none; | ||
| margin: 0; | ||
| padding: 0; | ||
|
|
||
| svg { | ||
| width: var(--spacing-3); | ||
| height: var(--spacing-3); | ||
| } | ||
| } | ||
|
|
||
| .dropdown-item { | ||
| margin: 0; | ||
| padding: var(--spacing-05) calc(var(--spacing-2) + var(--spacing-05)); | ||
| } | ||
|
|
||
| .dropdown-item > a, | ||
| .dropdown-item > span { | ||
| display: block; | ||
| color: var(--text-color, var(--black)); | ||
| text-decoration: none; | ||
| font-size: var(--text-base); | ||
| } | ||
|
|
||
| .dropdown-item:hover:not(.disabled) { | ||
| background: var(--bg-color-selected); | ||
| text-decoration: none; | ||
| border-radius: calc(var(--spacing-px) + var(--spacing-05)); | ||
| } | ||
|
|
||
| .dropdown-item.is-current { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| flex-direction: row; | ||
| gap: var(--spacing-4); | ||
| } | ||
|
|
||
| .dropdown-item.disabled > span { | ||
| text-decoration: line-through; | ||
| cursor: not-allowed; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <div class="dropdown" data-controller="toggle"> | ||
| <button class="dropdown-trigger" data-toggle-target="button" data-action="toggle#click" aria-haspopup="true" aria-expanded="false"> | ||
| <span class="dropdown-label"><%= @current_version %></span> | ||
| <span class="dropdown-caret"> | ||
| <%= svg "images/icons/caret-right.svg" %> | ||
| </span> | ||
| </button> | ||
| <div class="dropdown-menu" data-toggle-target="item" data-toggle-active="false" role="menu"> | ||
| <ul class="dropdown-list"> | ||
| <% @available_versions.each do |version| %> | ||
| <% if version == @current_version %> | ||
| <li class="dropdown-item is-current" aria-current="true" data-action="click->toggle#click"> | ||
| <span><%= version %></span> | ||
| <%= svg "images/icons/checkmark.svg" %> | ||
| </li> | ||
| <% elsif page_exist_in_version?(version) %> | ||
| <li class="dropdown-item"> | ||
| <%= link_to page_url_in_version(version) do %> | ||
| <%= version %> | ||
| <% end %> | ||
| </li> | ||
| <% else %> | ||
| <li class="dropdown-item disabled"> | ||
| <span><%= version %></span> | ||
| </li> | ||
| <% end %> | ||
| <% end %> | ||
| </ul> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| class Guides::VersionSelector < Bridgetown::Component | ||
| ENTRIES_VERSIONS = { | ||
| "3.1" => "openapi_v3-1", | ||
| "3.2" => "openapi_v3-2" | ||
| } | ||
|
|
||
| def initialize(entries:, current_url:, current_version:, available_versions:) | ||
| @entries = entries | ||
| @current_url = current_url&.to_s | ||
| @current_version = current_version | ||
| @available_versions = available_versions | ||
| end | ||
|
|
||
| def entries_urls_for_version(version) | ||
| version_key = ENTRIES_VERSIONS[version] # following logic from Builders::Sidebar | ||
| version_pages = @entries.dig(version_key) || [] # list of groups for this OpenAPI version | ||
| version_pages_first_level = version_pages.reject { |page| page.dig("items") } # for example /cheatsheet.md | ||
| version_pages_items = version_pages.flat_map { |page| page.dig("items") }.compact_blank || [] # list of all items / pages displayed for this version. | ||
|
|
||
| version_pages_items.map { |item| item&.resource&.relative_url&.to_s } + | ||
| version_pages_first_level.map { |page| page&.resource&.relative_url&.to_s } | ||
| end | ||
|
|
||
|
|
||
| def page_exist_in_version?(version) | ||
| page_url_in_version(version).in?(entries_urls_for_version(version)) | ||
| end | ||
|
|
||
| def page_url_in_version(version) | ||
| @current_url.gsub(@current_version, version) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| collection_name: guides | ||
| root: /guides/openapi/specification/v3.2 | ||
| resources: | ||
| - type: category | ||
| label: Introduction to OpenAPI | ||
| items: | ||
| - label: What is OpenAPI? | ||
| link: /introduction/what-is-openapi/ | ||
| - label: History and Evolution of OpenAPI | ||
| link: /introduction/history/ | ||
| - label: Benefits of Using OpenAPI | ||
| link: /introduction/benefits/ | ||
| - type: category | ||
| label: Understanding OpenAPI Structure | ||
| items: | ||
| - label: Basic Structure | ||
| link: /understanding-structure/basic-structure/ | ||
| - label: Defining API Servers | ||
| link: /understanding-structure/api-servers/ | ||
| - label: Paths and Operations | ||
| link: /understanding-structure/paths-operations/ | ||
| - label: Parameters (Path, Query, Header, and Cookie) | ||
| link: /understanding-structure/parameters/ | ||
| - label: Parameter Serialization | ||
| link: /understanding-structure/parameter-serialization/ | ||
| - label: HTTP Requests | ||
| link: /understanding-structure/http-requests/ | ||
| - label: HTTP Responses | ||
| link: /understanding-structure/http-responses/ | ||
| - label: Components Section | ||
| link: /understanding-structure/components/ | ||
| - type: category | ||
| label: Defining Data Models | ||
| items: | ||
| - label: Schema and Data Types | ||
| link: /data-models/schema-and-data-types/ | ||
| - label: JSON Schema in OpenAPI | ||
| link: /data-models/json-schema/ | ||
| - label: Examples and Default Values | ||
| link: /data-models/examples/ | ||
| - label: Schema Composition | ||
| link: /data-models/schema-composition/ | ||
| - label: Representing XML | ||
| link: /data-models/representing-xml/ | ||
| - type: category | ||
| label: Advanced OpenAPI Specification | ||
| items: | ||
| - label: Splitting OpenAPI into Multiple Documents | ||
| link: /advanced/splitting-documents-with-ref/ | ||
| - label: Multipart Form Data | ||
| link: /advanced/multipart-form-data/ | ||
| - label: Pagination | ||
| link: /advanced/pagination/ | ||
| - label: File Uploads | ||
| link: /advanced/file-uploads/ | ||
| - label: Supporting Multiple Content Types | ||
| link: /advanced/multiple-content-types/ | ||
| - label: Handling Error Formats | ||
| link: /advanced/error-formats/ | ||
| - label: Security (Authentication and Authorization) | ||
| link: /advanced/security/ | ||
| - label: Callbacks and Webhooks | ||
| link: /advanced/callbacks-webhooks/ | ||
| - label: JSON Streaming | ||
| link: /advanced/json-streaming/ | ||
| - type: category | ||
| label: Documenting APIs | ||
| items: | ||
| - label: Adding Descriptions and Summaries | ||
| link: /documentation/descriptions-and-summaries/ | ||
| - label: Grouping Operations with Tags | ||
| link: /documentation/grouping-operations-with-tags/ | ||
| - label: Linking to External Documentation | ||
| link: /documentation/external-documentation/ | ||
| - type: category | ||
| label: Extending OpenAPI | ||
| items: | ||
| - label: Custom Extensions and Vendor Extensions | ||
| link: /extending/extensions/ | ||
| - label: Enriching OpenAPI with Overlays | ||
| link: /extending/overlays/ | ||
| - label: The Perfect Modern OpenAPI Workflow | ||
| link: /the-perfect-modern-openapi-workflow/ | ||
| - label: The Cheat Sheet | ||
| link: /cheatsheet/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.