-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add schema generation * update gh action * test gh action with changed schema * run make generate-schema * update readme
- Loading branch information
1 parent
6c9c215
commit 05bfbd2
Showing
10 changed files
with
3,273 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//go:build generateschema | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/invopop/jsonschema" | ||
"github.com/invopop/yaml" | ||
"github.com/xenitab/azcagit/src/source" | ||
) | ||
|
||
func main() { | ||
err := run() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "schema generation returned an error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run() error { | ||
err := generateSchema(&source.SourceApp{}, "app") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = generateSchema(&source.SourceJob{}, "job") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func generateSchema[T any](t T, name string) error { | ||
schema := jsonschema.Reflect(&t) | ||
schemaJson, err := schema.MarshalJSON() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var schemaJsonRaw interface{} | ||
err = json.Unmarshal(schemaJson, &schemaJsonRaw) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
prettySchemaJson, err := json.MarshalIndent(schemaJsonRaw, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
schemaYaml, err := yaml.JSONToYAML(schemaJson) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
currDir, err := os.Getwd() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.WriteFile(fmt.Sprintf("%s/schemas/%s.json", currDir, name), prettySchemaJson, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.WriteFile(fmt.Sprintf("%s/schemas/%s.yaml", currDir, name), schemaYaml, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.