Skip to content

Commit

Permalink
feat: add openapi generator (#17)
Browse files Browse the repository at this point in the history
* feat: add openapi generator

* fix:add GET to  openapi generator

* add some function description

* fix: stdin test

* fix: utils test

* fix: linting

* remove vendor

* feat: add openapi generation for single files or specified folders

* fix: http test lint

* fix: contracts newlines and resize

* fix: show help when no flag or arguments is provided

* fix: better type handling from introspection

* feat: execute slangroom on api request

* fix: better type handling, allow to define properties in metadata

* fix: utils test

* fix: add validation of request body against jsonschema before passing to slangroom

* add stepci openapi testing

* fix: test and actions

* fix: openapi actions

* fix: remove slangroom created data from introspection

* fix actions

* fix actions add setup go  to openapi

* fix actions

* fix actions

* ci: add some emoji, fix dependencies between jobs and enable ci when merge PR on main

* ci: main instead of master

* test: fix random order of missing parameters

* fix: better error handling when output is not json

* ci: merge go and stepci tests

* ci: better name

* fix: remove debug print

---------

Co-authored-by: Filippo Trotter <[email protected]>
Co-authored-by: Filippo Trotter <[email protected]>
Co-authored-by: matteo-cristino <[email protected]>
  • Loading branch information
4 people authored Dec 17, 2024
1 parent d56bc92 commit 78f94ff
Show file tree
Hide file tree
Showing 99 changed files with 1,131 additions and 16,064 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
name: CI
name: 📢 Lint, Test & Publish
on:
push:
branches:
- main
pull_request:
branches:
- '**'
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
lint:
name: 🚨 Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -18,6 +22,7 @@ jobs:
go-version: 1.23.1
- uses: golangci/golangci-lint-action@v6
test:
name: 🧪 Test
runs-on: ubuntu-latest
needs: lint
steps:
Expand All @@ -27,9 +32,15 @@ jobs:
go-version: 1.23.1
- name: Install slangroom-exec
run: make build
- name: Run test
- name: Run go tests
run: go test -v ./...
- name: Run stepci tests
run: |
out/bin/gemini -d &
sleep 5
npx stepci run workflow.stepci.yml
release:
name: 🔖 Release
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
!/.env.sample
!/.cruft.json
!/.goreleaser.yaml
!/workflow.stepci.yml

!.github/workflows/*.yml

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ $(SLANGROOM_EXEC):


## Build:
build: vendor $(SLANGROOM_EXEC) ## Build your project and put the output binary in out/bin/
build: $(SLANGROOM_EXEC) ## Build your project and put the output binary in out/bin/
mkdir -p out/bin
GO111MODULE=on $(GOCMD) build -mod vendor -o out/bin/$(BINARY_NAME) .
GO111MODULE=on $(GOCMD) build -o out/bin/$(BINARY_NAME) .

clean: ## Remove build related file
rm -fr ./bin
Expand Down
81 changes: 55 additions & 26 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ var listCmd = &cobra.Command{
if len(args) == 0 {
// If no folder argument is provided, list embedded files
fmt.Println("Listing embedded slangroom files:")

// If the daemon flag is set, start the HTTP server
if daemon {
if err := httpserver.StartHTTPServer("contracts", "", nil); err != nil {
log.Printf("Failed to start HTTP server: %v\n", err)
os.Exit(1)
}
return
}
err := fouter.CreateFileRouter("", &contracts, "contracts", func(file fouter.SlangFile) {
fmt.Printf("Found file: %s (Path: %s)\n", strings.TrimSuffix(file.FileName, extension), file.Path)
})
Expand All @@ -70,16 +61,6 @@ var listCmd = &cobra.Command{
// If a folder argument is provided, list files in that folder
folder := args[0]
fmt.Printf("Listing contracts in folder: %s\n", folder)

if daemon {
if err := httpserver.StartHTTPServer(folder, "", nil); err != nil {
log.Printf("Failed to start HTTP server: %v\n", err)
os.Exit(1)
}
return
}

// List slangroom files in the specified folder
err := fouter.CreateFileRouter(folder, nil, "", func(file fouter.SlangFile) {
fmt.Printf("Found file: %s (Path: %s)\n", strings.TrimSuffix(file.FileName, extension), file.Path)
})
Expand Down Expand Up @@ -148,7 +129,7 @@ func addEmbeddedFileCommands() {

// Set the command's run function
fileCmd.Run = func(_ *cobra.Command, args []string) {
runFileCommand(file, args, metadata, argContents, isMetadata, relativePath, &input)
runFileCommand(file, args, metadata, argContents, isMetadata, &input)
}

// Add the file command to its directory's command
Expand All @@ -164,9 +145,47 @@ func addEmbeddedFileCommands() {
// It accepts a folder and file path and can optionally start an HTTP server if the daemon flag is set.
var runCmd = &cobra.Command{
Use: filepath.Base(os.Args[0]) + " [folder]",
Short: "Execute a specific slangroom file in a dynamically specified folder",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
Short: "Execute a specific slangroom file in a dynamically specified folder or in the embedded folder contracts",
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
if daemon {
if len(args) == 0 {
httpInput := httpserver.HTTPInput{
BinaryName: filepath.Base(os.Args[0]),
EmbeddedFolder: &contracts,
EmbeddedPath: "contracts",
}
if err := httpserver.StartHTTPServer(httpInput); err != nil {
log.Printf("Failed to start HTTP server: %v\n", err)
os.Exit(1)
}
return
}
folder := args[0]
filePath := filepath.Join(args[1:]...)
isDir, err := utils.IsDir(filepath.Join(folder, filePath))
if isDir && err == nil {
httpInput := httpserver.HTTPInput{
BinaryName: filepath.Base(os.Args[0]),
Path: filepath.Join(folder, filePath),
}
if err := httpserver.StartHTTPServer(httpInput); err != nil {
log.Printf("Failed to start HTTP server: %v\n", err)
os.Exit(1)
}
return
}
}

if len(args) < 1 {
log.Println("Error: folder or argument is required")
if err := cmd.Help(); err != nil {
log.Printf("Failed to start the program: %v\n", err)
os.Exit(1)
}

return
}
folder := args[0]
filePath := filepath.Join(args[1:]...)
input := slangroom.SlangroomInput{}
Expand All @@ -190,7 +209,11 @@ var runCmd = &cobra.Command{

// Start HTTP server if daemon flag is set
if daemon {
if err := httpserver.StartHTTPServer(folder, filePath, nil); err != nil {
httpInput := httpserver.HTTPInput{
BinaryName: filepath.Base(os.Args[0]),
Path: file.Path,
}
if err := httpserver.StartHTTPServer(httpInput); err != nil {
log.Printf("Failed to start HTTP server: %v\n", err)
os.Exit(1)
}
Expand Down Expand Up @@ -219,7 +242,7 @@ var runCmd = &cobra.Command{
},
}

func runFileCommand(file fouter.SlangFile, args []string, metadata *utils.CommandMetadata, argContents map[string]interface{}, isMetadata bool, relativePath string, input *slangroom.SlangroomInput) {
func runFileCommand(file fouter.SlangFile, args []string, metadata *utils.CommandMetadata, argContents map[string]interface{}, isMetadata bool, input *slangroom.SlangroomInput) {
filename := strings.TrimSuffix(file.FileName, extension)
err := utils.LoadAdditionalData(file.Dir, filename, input)
if err != nil {
Expand Down Expand Up @@ -249,7 +272,13 @@ func runFileCommand(file fouter.SlangFile, args []string, metadata *utils.Comman
}
// Start HTTP server if daemon flag is set
if daemon {
if err := httpserver.StartHTTPServer("contracts", relativePath, input); err != nil {
httpInput := httpserver.HTTPInput{
BinaryName: filepath.Base(os.Args[0]),
EmbeddedFolder: &contracts,
EmbeddedPath: "contracts",
FileName: filename,
}
if err := httpserver.StartHTTPServer(httpInput); err != nil {
log.Printf("Failed to start HTTP server: %v\n", err)
os.Exit(1)
}
Expand Down
Loading

0 comments on commit 78f94ff

Please sign in to comment.