Skip to content

Commit

Permalink
Switch to using openapi schema and openapi-generator (#2)
Browse files Browse the repository at this point in the history
* update repo

* add package

* add supporting files

* update build test lint job

* update golang ci config

* add golangci-lint config

* format files

* add format job

* add -d flag
  • Loading branch information
thisisibrahimd authored Jul 18, 2024
1 parent 4c272c1 commit e11928f
Show file tree
Hide file tree
Showing 43 changed files with 7,433 additions and 649 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,51 @@ on:
pull_request:
branches: [ "main" ]

permissions:
contents: read
pull-requests: read
checks: write

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.5'

- run: |
gofmt -d -e ./..
lint:
needs: [format]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.5'

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59

build:
build-and-test:
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22.5'

- name: Build
run: go build -v ./...
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

output:
show-stats: true
4 changes: 4 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tools]
just = "latest"
go = "1.22.5"
golangci-lint = "latest"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# openslo-spec
# openslo-go

This repository contains generated go code for the openslo spec defined in jsonschema.
This repository contains generated go code for the openslo spec defined in [thisisibrahimd/openslo](https://github.com/thisisbrahimd/openslo).

4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/thisisibrahimd/openslo-spec

go 1.22.4
go 1.22.5

require gopkg.in/validator.v2 v2.0.1
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY=
gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8=
40 changes: 15 additions & 25 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
openslo_spec_dir := "pkg/openslo"
openslo_schema_dir := "openslo/schemas"
openapi_schema_url := "https://raw.githubusercontent.com/thisisibrahimd/OpenSLO/feature/add-budget-adjustment-spec/schemas/v1/schema.yaml"

gen: gen-v1-spec

gen-v1-spec:
mkdir -p {{ openslo_spec_dir }}/v1
quicktype --quiet --telemetry disable --field-tags yaml,json --omit-empty -l go -s schema -o {{ openslo_spec_dir }}/v1/openslo_v1.go --package openslo_v1 \
{{ openslo_schema_dir }}/v1/alertcondition.schema.json \
{{ openslo_schema_dir }}/v1/alertnotificationtarget.schema.json \
{{ openslo_schema_dir }}/v1/alertpolicy.schema.json \
{{ openslo_schema_dir }}/v1/budgetadjustment.schema.json \
{{ openslo_schema_dir }}/v1/datasource.schema.json \
{{ openslo_schema_dir }}/v1/service.schema.json \
{{ openslo_schema_dir }}/v1/sli.schema.json \
{{ openslo_schema_dir }}/v1/slo.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/alertcondition-spec.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/alertnotificationtarget-spec.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/alertpolicy-spec.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/budgetadjustment-spec.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/datasource-spec.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/description.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/duration-shorthand.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/general.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/metadata.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/metricsource.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/name.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/service-spec.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/sli-spec.schema.json \
-S {{ openslo_schema_dir }}/v1/parts/slo-spec.schema.json
GO_POST_PROCESS_FILE="$(which gofmt) -w" openapi-generator \
generate \
-i {{ openapi_schema_url }} \
-g go \
-o {{ openslo_spec_dir }}/v1 \
--inline-schema-name-mappings AlertPolicyCondition_inner=AlertPolicyCondition,AlertPolicyNotificationTarget_inner=AlertPolicyNotificationTarget \
--global-property models,modelDocs=false,supportingFiles \
--package-name openslo_v1 \
--model-package openslo_v1 \
--enable-post-process-file
rm {{ openslo_spec_dir }}/v1/.openapi-generator/VERSION {{ openslo_spec_dir }}/v1/.openapi-generator/FILES
rmdir {{ openslo_spec_dir }}/v1/.openapi-generator
12 changes: 12 additions & 0 deletions pkg/openslo/v1/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
api/openapi.yaml
README.md
git_push.sh
.gitignore
configuration.go
client.go
response.go
go.mod
go.sum
.travis.yml
*/VERSION
*/FILES
232 changes: 232 additions & 0 deletions pkg/openslo/v1/model_alert_condition.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e11928f

Please sign in to comment.