Skip to content

Commit

Permalink
Remove format datetime for sdk-go
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Aug 13, 2024
1 parent de7c123 commit 528895e
Show file tree
Hide file tree
Showing 3 changed files with 24,314 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ curl --silent -o "$root/outscale-ori.yaml" "$oapi_yaml_url"
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"
mv "/tmp/outscale.yaml" "$root/old-outscale.yaml"


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

# OpenAPI format can use `oneOf` fields
# https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/#oneof
#
# `oneOf`usage are problematic for some SDK generators from openapi-generator project:
# https://openapi-generator.tech/docs/generators/
#
# Waiting for generators to manage `oneOf`, this quick and dirty patcher will remove them.

require 'psych'

api = Psych.load_file(ARGV[0])
old = Psych.load_file(ARGV[1])

old_schema = old["components"]["schemas"]

api["components"]["schemas"].each do |call_name, call|
#puts key
call["properties"].each do |arg_name,arg_info|
#print arg_name, ": ", arg_info.key?("oneOf"), "\n"
if arg_info.key?("oneOf") then
arg_info["oneOf"][0].each do |key, val|
arg_info[key] = val
end
arg_info.delete("oneOf")
elsif arg_info.key?("items") and arg_info["items"].key?("oneOf") then
arg_info["items"] = arg_info["items"]["oneOf"][0]
arg_info["items"].delete("oneOf")
end
if old_schema.key?(call_name) then
old_arg_prop = old_schema[call_name]["properties"]
if old_arg_prop.key?(arg_name) then
if old_arg_prop[arg_name].key?("format") then
arg_info["format"] = old_arg_prop[arg_name]["format"]
elsif old_arg_prop[arg_name].key?("items") then
arg_info["items"] = old_arg_prop[arg_name]["items"]
end
end
end
if arg_info["format"] == "date-time" then
arg_info.delete("format")
end
end
end

puts Psych.dump(api)
Loading

0 comments on commit 528895e

Please sign in to comment.