Skip to content

Commit

Permalink
Patch OpenAPI versions for codegen (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte authored Jan 15, 2025
2 parents c05516d + f89fb59 commit 7ff6b29
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Javascript
/node_modules

#PHP
# PHP
/vendor/
composer.lock

#IDE
# IDE
.vscode
.idea

# Rust
target/

# Codegen script
/.codegen-tmp/
1 change: 0 additions & 1 deletion go/.gitignore

This file was deleted.

28 changes: 18 additions & 10 deletions regen_openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ if [ -n "$1" ]; then
curl "$1" | python -m json.tool > openapi.json
fi

cd $(dirname "$0")
mkdir -p .codegen-tmp
# OpenAPI version has to be overwritten to avoid broken codegen paths in OpenAPI generator.
# Spec version is overwritten to avoid unnecessary diffs on comments.
jq --indent 4 '.openapi = "3.0.2" | .info.version = "1.1.1"' \
< openapi.json \
> .codegen-tmp/openapi.json

# For some languages, write a separate OpenAPI spec file where optional fields
# of non-`Patch` schemas are set to not be nullable, so the codegen doesn't wrap
# the struct fields in double options.
Expand All @@ -27,28 +35,28 @@ jq --indent 4 '.components.schemas |= with_entries(
end
end
)' \
< openapi.json \
| tee go/openapi.json \
> rust/openapi.json
< .codegen-tmp/openapi.json \
> .codegen-tmp/openapi-less-null.json

yarn openapi-generator-cli generate -i openapi.json -g typescript -o javascript/src/openapi -c javascript/openapi-generator-config.json --type-mappings=set=Array -t javascript/templates
yarn openapi-generator-cli generate -i .codegen-tmp/openapi.json -g typescript -o javascript/src/openapi -c javascript/openapi-generator-config.json --type-mappings=set=Array -t javascript/templates

# Cleanup previous codegen, allowing us to spot removals.
# If the removals are expected, stage them eg. `git add -u`, then commit them.
rm -f go/internal/openapi/*.go
yarn openapi-generator-cli generate -i go/openapi.json -g go -o go/internal/openapi -c go/openapi-generator-config.json -t go/templates
yarn openapi-generator-cli generate -i .codegen-tmp/openapi-less-null.json -g go -o go/internal/openapi -c go/openapi-generator-config.json -t go/templates

yarn openapi-generator-cli generate -i openapi.json -g java -o java/lib/generated/openapi -c java/openapi-generator-config.json -t java/templates
yarn openapi-generator-cli generate -i .codegen-tmp/openapi.json -g java -o java/lib/generated/openapi -c java/openapi-generator-config.json -t java/templates

yarn openapi-generator-cli generate -i openapi.json -g kotlin -o kotlin/lib/generated/openapi -c kotlin/openapi-generator-config.json -t kotlin/templates
yarn openapi-generator-cli generate -i .codegen-tmp/openapi.json -g kotlin -o kotlin/lib/generated/openapi -c kotlin/openapi-generator-config.json -t kotlin/templates

yarn openapi-generator-cli generate -i openapi.json -g ruby -o ruby -c ruby/openapi-generator-config.json -t ruby/templates
yarn openapi-generator-cli generate -i .codegen-tmp/openapi.json -g ruby -o ruby -c ruby/openapi-generator-config.json -t ruby/templates

yarn openapi-generator-cli generate -i openapi.json -g csharp -o csharp/ -c csharp/openapi-generator-config.json --global-property apis,models,supportingFiles,apiTests=false,apiDocs=false,modelTests=false,modelDocs=false
yarn openapi-generator-cli generate -i .codegen-tmp/openapi.json -g csharp -o csharp/ -c csharp/openapi-generator-config.json --global-property apis,models,supportingFiles,apiTests=false,apiDocs=false,modelTests=false,modelDocs=false

# Cleanup previous codegen, allowing us to spot removals.
# If the removals are expected, stage them eg. `git add -u`, then commit them.
rm -rf rust/src/models
yarn openapi-generator-cli generate -i rust/openapi.json -g rust -o rust/ -c rust/openapi-generator-config.json -t rust/templates
yarn openapi-generator-cli generate -i .codegen-tmp/openapi-less-null.json -g rust -o rust/ -c rust/openapi-generator-config.json -t rust/templates

rm -rf .codegen-tmp
echo Note: Python generation is not executed automatically.
2 changes: 0 additions & 2 deletions rust/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
Cargo.lock

/.openapi-generator/
/openapi.json

6 changes: 5 additions & 1 deletion tools/bump_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const filesPaths = [
"python/svix/__init__.py",
// Ruby
"ruby/Gemfile.lock",
"ruby/lib/svix/version.rb"
"ruby/lib/svix/version.rb",
// OpenAPI spec
"server/openapi.json",
// Cloud OpenAPI spec - not necessary but any other time of updating seems weirder
"openapi.json",
];

const rootDir = join(__dirname, "..");
Expand Down

0 comments on commit 7ff6b29

Please sign in to comment.