-
Notifications
You must be signed in to change notification settings - Fork 338
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
Prism should read yml files too SO-200 #299
Conversation
XVincentX
commented
May 14, 2019
•
edited
Loading
edited
- Correctly reveals yml files as yaml for graphite
- Handles startup exceptions and prints them out
- Updates the README
@@ -64,3 +66,8 @@ export class GraphFacade { | |||
return compact(nodes.map<IHttpOperation>(node => node.data as IHttpOperation)); | |||
} | |||
} | |||
|
|||
function transformLanguage(lang: string) { |
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.
Suggest a simple map over function:
import { Languages } from '@stoplight/graphite/graph';
const langMap = {
json: Languages.Json,
yaml: Languages.Yaml,
yml: Languages.Yaml,
}
This way can also check that language
exists in langMap
and report error if it does not.
language = langMap[language];
if (!language) {
// report error and stop or whatever
}
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.
Ah interesting idea, I didn't think of reusing that part of graphite!
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.
@marbemac how about importing the function that does that in graphite and use it?
import { filenameToLanguage } from '@stoplight/graphite/backends/filesystem/utils'
…
language: filenameToLanguage(path)
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.
Even better! Still suggest reporting an error if language is undefined.
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.
The language will never be undefined; the function is using a proxied map returning the string you set in case it's not in the map
https://github.com/stoplightio/graphite/blob/master/src/backends/filesystem/utils.ts#L15-L26
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.
Ah, got it - ok well then 🤷♂, hopefully folks don't feed prism files that are not json or yaml.
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.
As long as you verified e2e this solves the problem, implementation looks good to me!
@philsturgeon How about you follow the guide and try to release Prism? |