Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mv "$root/outscale.yaml" "/tmp/outscale.yaml"
$root/hacks/patch.rb "$root/outscale-ori.yaml" "$root/old-outscale.yaml" > "$root/outscale.yaml"
$root/hacks/patch-nooneof.rb "$root/outscale-ori.yaml" > "$root/outscale-java.yaml"
$root/hacks/patch-nodatetime.rb "$root/outscale-ori.yaml" "$root/old-outscale.yaml" > "$root/outscale-go.yaml"
$root/hacks/patch-noproperties-array.rb "$root/outscale-ori.yaml" > "$root/outscale-c.yaml"
mv "/tmp/outscale.yaml" "$root/old-outscale.yaml"

rm "$root/outscale-ori.yaml"
38 changes: 38 additions & 0 deletions hacks/patch-noproperties-array.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/ruby

# OpenAPI format can reference schemas that have no properties.
#
# Array items that reference these schemas can cause issues for the C generator.

require 'psych'

api = Psych.load_file(ARGV[0])

no_properties = []
api["components"]["schemas"].each do |call_name, call|
unless call.key?("properties")
no_properties << { name: call_name, type: call["type"] }
end
end

api["components"]["schemas"].each do |schema_name, schema|
if schema.key?("properties") then
schema["properties"].each do |prop_name, prop_info|
if prop_info["type"] == "array" && prop_info.key?("items")
items = prop_info["items"]
if items.key?("$ref")
if items["$ref"] =~ %r{#/components/schemas/(\w+)}
ref_name = $1
schema = no_properties.find { |s| s[:name] == ref_name }
if schema
items.delete("$ref")
items["type"] = schema[:type]
end
end
end
end
end
end
end

puts Psych.dump(api)
Loading