Skip to content

Instantly share code, notes, and snippets.

@mtsmfm
Last active July 4, 2019 20:38
Show Gist options
  • Save mtsmfm/341968bb8f2d18fcc250a4e0440db938 to your computer and use it in GitHub Desktop.
Save mtsmfm/341968bb8f2d18fcc250a4e0440db938 to your computer and use it in GitHub Desktop.
convert from json hyper schema to swagger spec
require 'yaml'
require 'pathname'
require 'active_support/all'
def convert(f)
filename = Pathname.new(f)
yaml = YAML.load_file(filename)
name = filename.basename('.yml').to_s
File.write(filename, {
name.camelize => {
'type' => yaml['type'],
'properties' => yaml['definitions'].except('identity')
}
}.to_yaml)
api_file = 'schemata/api.yml'
api_yaml = YAML.load_file(api_file)
yaml['links'].each do |link|
api_yaml['paths'] << {
link['href'] => {
link['method'].downcase => {
'description' => link['description'],
'parameters' => link.dig('schema', 'properties') || nil,
'responses' => {
200 => {
'description' => name,
'schema' => {'$ref' => './x.yml#/definitions/X'}
}
}
}
}
}
end
File.write(
api_file,
api_yaml.to_yaml
)
end
Dir['schemata/**/*.yml'].each do |f|
next if f == 'schemata/api.yml'
convert(f)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment