Skip to content
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

feat: ensuring that exported definitions are sorted by path and method #225

Merged
merged 1 commit into from
Nov 4, 2021

Conversation

erunion
Copy link
Member

@erunion erunion commented Nov 4, 2021

🧰 What's being changed?

A common problem we've had with large codebases is that we can't guarantee that exported definitions are always exported with the same ordering. This often results in us making in non-API changes to a codebase that happen to also force a resorting of operations within the exported API definition for who knows why.

To combat that I'm introducing a force of alphabetical sorting on paths, path operations, and component schemas.

🧬 Testing

There aren't any snapshot updates here because i changed the __tests__/__fixtures__/project-openapi/api.js fixture to have non-alpha sorted content -- ensuring that these changes work.

@erunion erunion added the enhancement New feature or request label Nov 4, 2021
function mergeEndpointsWithBase(swaggerBase = {}, endpoints = []) {
// To ensure consistent sorting of HTTP methods let's universally enforce the following order.
const methodPriority = new Map();
['get', 'post', 'put', 'patch', 'delete', 'options', 'head', 'trace'].forEach((x, i) => methodPriority.set(x, i));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since logically when reading an API definition having delete come before a get operation doesn't really make sense I'm forcing the sort to be this specific order.

@erunion erunion merged commit c272295 into main Nov 4, 2021
@erunion erunion deleted the feat/force-alphabetical-exports branch November 4, 2021 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants