Skip to content

Commit

Permalink
Run pre-commit on generated files changes (#1640)
Browse files Browse the repository at this point in the history
* run pre-commit on generated files changes

* pre-commit fixes

---------

Co-authored-by: ci.datadog-api-spec <[email protected]>
  • Loading branch information
skarimo and ci.datadog-api-spec authored Nov 21, 2023
1 parent 9e5638a commit 5c4fb6d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .generator/src/generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def cli(specs, output):
api_j2 = env.get_template("api.j2")
model_j2 = env.get_template("model.j2")
package_j2 = env.get_template("package.j2")
datadog_api_client_j2 = env.get_template("datadog_api_client.j2")

extra_files = {
"model_base.rb": env.get_template("model_base.j2"),
Expand Down Expand Up @@ -120,6 +121,10 @@ def cli(specs, output):
with filename.open("w") as fp:
fp.write(template.render(all_apis=all_apis, all_specs=all_specs, all_models=all_models))

datadog_api_client_output = output / "datadog_api_client.rb"
with datadog_api_client_output.open("w") as fp:
fp.write(datadog_api_client_j2.render(all_apis=all_apis))

# Parameter mappings for bdd tests
scenarios_test_output = pathlib.Path("../features/")
for name, template in test_scenarios_files.items():
Expand Down
19 changes: 19 additions & 0 deletions .generator/src/generator/templates/datadog_api_client.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=begin
{% include "api_info.j2" %}
=end

require 'datadog_api_client/models'
require_relative 'datadog_api_client/inflector'

loader = Zeitwerk::Loader.new
loader.tag = File.basename(__FILE__, ".rb")
loader.collapse("#{__dir__}/datadog_api_client/*/models/")
loader.collapse("#{__dir__}/datadog_api_client/*/api/")

{%- for version, apis in all_apis.items() %}
loader.push_dir("#{__dir__}/datadog_api_client/{{ version }}", namespace: DatadogAPIClient::{{ version|upper }})
{%- endfor %}
# Ignore model_base.rb from being loaded in by zeitwerk as it is loaded in by default
loader.ignore("#{__dir__}/datadog_api_client/*/model_base.rb")
loader.inflector = {{ module_name }}::{{ module_name }}Inflector.new
loader.setup
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
name: Generate
language: system
entry: bash -c "./generate.sh"
files: '^(\.generator/.*|\.pre-commit-config\.yaml|Makefile|\features/.*)'
files: '^(\.generator/.*|\.pre-commit-config\.yaml|Makefile|\features/.*|lib/.*)'
pass_filenames: false
- id: format-examples
name: Format generated examples
Expand Down
17 changes: 16 additions & 1 deletion lib/datadog_api_client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
=begin
#Datadog API V2 Collection
#Collection of all Datadog Public endpoints.
The version of the OpenAPI document: 1.0
Contact: [email protected]
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator
Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2020-Present Datadog, Inc.
=end

require 'datadog_api_client/models'
require_relative 'datadog_api_client/inflector'

Expand All @@ -10,4 +25,4 @@
# Ignore model_base.rb from being loaded in by zeitwerk as it is loaded in by default
loader.ignore("#{__dir__}/datadog_api_client/*/model_base.rb")
loader.inflector = DatadogAPIClient::DatadogAPIClientInflector.new
loader.setup
loader.setup

0 comments on commit 5c4fb6d

Please sign in to comment.