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

sort routes alphabetically (254) #496

Merged
merged 4 commits into from
Jul 28, 2014
Merged

sort routes alphabetically (254) #496

merged 4 commits into from
Jul 28, 2014

Conversation

chatch
Copy link

@chatch chatch commented Jul 20, 2014

No description provided.

@chatch
Copy link
Author

chatch commented Jul 20, 2014

actually this belongs on #254
is it possible to move it?

@chatch
Copy link
Author

chatch commented Jul 23, 2014

hi @rage-shadowman you mean pass the sorter into the MainView? and instead of sortAlphabetically=true you have something like sort=alpha where alpha maps to the function?

@rage-shadowman
Copy link

I mean rather than setting options.sortAlphabetically to a boolean, you would set options.sorter or maybe options.sortFn to a function, which, in your example would be the alphabetical sorter function.

We could make it sort any way we like by just passing in a different function which might take into account whether it is a GET or POST, or the number of required arguments or anything else we might want to use.

@chatch
Copy link
Author

chatch commented Jul 27, 2014

changed option name to 'sorter' and documented in README.md.
sorter can be 'alpha' or 'method'.
implemented 'method' for HTTP method sort order.

fehguy added a commit that referenced this pull request Jul 28, 2014
sort routes alphabetically (254)
@fehguy fehguy merged commit c948b40 into swagger-api:master Jul 28, 2014
@rage-shadowman
Copy link

Ok, I think I see what 'method' is for. Not as hideous as I thought, but still more complicated than it needs to be and crippled in functuonality.

@chatch
Copy link
Author

chatch commented Jul 29, 2014

okay now i understand your original meaning of passing the sorter through ... sorry, i didn't fully get it before.

i think there are some advantages to providing these predefined sorters:

  • they will cover most user sort requirements simply
  • no knowledge of the internal SwaggerApi structure is required for the user calling new SwaggerUI. just give me 'sorter : alpha' or 'sorter : method' as documented in README.md.
  • any changes to the predefined sorters or the SwaggerApi won't affect the index.html(s) or wherever new SwaggerUI is called

but ideally both predefined sorters AND a custom / pass through sorter is supported. maybe we can do something like : if 'sorter' type is 'string' then it's a reference to a predefined sort otherwise it's a provided function...

@rage-shadowman
Copy link

A sorter always needs to know the structure of what it is sorting, that is just the nature of the beast. So it would probably make sense to have 2 separate sorters for this: apiSorter and operationSorter. You can see my fork for an example if you like. I haven't tested it so I didn't send a pull request. And maybe it should allow strings but check if the parameter is of type 'function'. It may even be useful to have a propertySorter for models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants