-
Notifications
You must be signed in to change notification settings - Fork 2
Supports defining remote versions in .shape-docs.yml #150
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
Conversation
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
…versions # Conflicts: # src/features/projects/domain/getSelection.ts # src/features/projects/domain/index.ts # src/features/projects/view/client/ProjectsPage.tsx
Base automatically changed from
enhancement/simplifies-navigation
to
develop
November 11, 2023 15:27
|
|
||
| private sortVersions(versions: Version[], defaultBranchName: string): Version[] { | ||
| const candidateDefaultBranches = [ | ||
| defaultBranchName, "main", "master", "develop", "development" |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trunk? 🙈
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ulrikandersen Sure! It's added in this commit: e9811e1
ulrikandersen
previously approved these changes
Nov 13, 2023
Contributor
Author
|
Merging this. The only change after @ulrikandersen's approval is in e9811e1. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The changes in this PR adds support for specifying remote versions and their specifications in the .shape-docs.yml file, removing the need for copying specifications that are already hosted publicly online into our GitHub repositories.
Motivation
The benefit of not copying public configurations into our repositories is that we avoid the documentation becoming stale. Currently projects like ok-openapi and avida-openapi have non-trivial GitHub Actions workflows running periodically to copy OpenAPI specifications into the projects. However, as soon as these copies have been established they are becoming stale and developers may not see the most up to date version when visiting Shape Docs.
However, there are also downside to displaying publicly available documentation, namely:
The solution is straightforward in both cases though: developers should rely on using GitHub Actions workflows to copy the OpenAPI specifications into our GitHub repositories. As such, it is not a requirement to use this new feature but it's an optimization that can be applied wherever it makes sense.
Solution
With the changes in this PR we add the new
remoteVersionskey to the .shape-docs.yml file which lists the versions to display and the specifications for each version. A working example for the Avida project will look like this:A similar more extensive configuration of the OK project can look like this:
Details
There are a few details worth highlighting in this implementation.
New Rules for URLs
Most importantly, we no longer require URLs pointing to a specification to end with ".yml" or ".yaml". Earlier we would use the presence of this file extension to determine that the URL contained the ID of a specification. As developers can now create their own specifications, we get rid requirement as manually creating a specification with a name that looks like a filename seems odd.
This makes it impossible to determine which parts of the URL is the version ID. Consider the following URL:
With the path:
Because the URL ends with
.ymland because we assume that filenames do not contain a slash, it is apparent that "openapi.yml" is the ID of the specification. Similarly, because GitHub repository names cannot contain a slash, we know that anything between the first and second slash is the project ID. That leaves anything between the project ID and the specification ID to be the version ID.Things get trickier when the URL does not end with ".yml" or ".yaml" and even more so if the user decides to visit the following path to navigate to the first (and possibly only) OpenAPI specification on a branch, it gets even trickier.
We still know that the project ID must be anything between the first and the second slash. We make a guess that the specification ID is anything after the last slash. That leaves anything between the project ID and specification ID to be the version ID.
When attempting to find a version with ID
johnsmith/enhancementin the project with the IDok, we will find that no such version exists. So we concatenate the version ID and the specification ID and see if we can find a version with IDjohnsmith/enhancement/stories-endpoint. That succeeds and since we no longer have a valid specification ID, we display the first OpenAPI specification in that version.CORS
CORS may disallow loading OpenAPI specifications from a third-party host. To workaround this we introduce the
/api/proxy?url={url}endpoint which fetches the OpenAPI specification and returns it under our own domain.