Skip to content

Commit

Permalink
Make openapi-server generation automated
Browse files Browse the repository at this point in the history
  • Loading branch information
lampajr committed Feb 14, 2024
1 parent 3bb4f6d commit 7c54315
Show file tree
Hide file tree
Showing 3 changed files with 457 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ openapi/validate: bin/openapi-generator-cli
openapi-generator-cli validate -i api/openapi/model-registry.yaml

# generate the openapi server implementation
# note: run manually only when model-registry.yaml api changes, for model changes gen/openapi is run automatically
.PHONY: gen/openapi-server
gen/openapi-server: bin/openapi-generator-cli openapi/validate
openapi-generator-cli generate \
-i api/openapi/model-registry.yaml -g go-server -o internal/server/openapi --package-name openapi --global-property models \
-i api/openapi/model-registry.yaml -g go-server -o internal/server/openapi --package-name openapi --global-property models,apis \
--ignore-file-override ./.openapi-generator-ignore --additional-properties=outputAsLibrary=true,enumClassPrefix=true,router=chi,sourceFolder=,onlyInterfaces=true,isGoSubmodule=true,enumClassPrefix=true,useOneOfDiscriminatorLookup=true \
--template-dir ./templates/go-server
./scripts/gen_type_asserts.sh
sed -i 's/, orderByParam/, model.OrderByField(orderByParam)/g' internal/server/openapi/api_model_registry_service.go
sed -i 's/, sortOrderParam/, model.SortOrder(sortOrderParam)/g' internal/server/openapi/api_model_registry_service.go
gofmt -w internal/server/openapi

# generate the openapi schema model and client
Expand Down Expand Up @@ -156,7 +157,7 @@ build/odh: vet
go build

.PHONY: gen
gen: deps gen/grpc gen/openapi gen/converter
gen: deps gen/grpc gen/openapi gen/openapi-server gen/converter
go generate ./...

.PHONY: lint
Expand Down
5 changes: 3 additions & 2 deletions internal/server/openapi/api_model_registry_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* REST API for Model Registry to create and manage ML model metadata
*
* API version: 1.0.0
* API version: v1alpha1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

Expand All @@ -15,6 +15,7 @@ import (
"strings"

"github.com/go-chi/chi/v5"

model "github.com/opendatahub-io/model-registry/pkg/openapi"
)

Expand Down Expand Up @@ -692,7 +693,7 @@ func (c *ModelRegistryServiceAPIController) GetModelVersion(w http.ResponseWrite
EncodeJSONResponse(result.Body, &result.Code, w)
}

// GetModelVersionArtifacts - List All ModelVersion's artifacts
// GetModelVersionArtifacts - List all artifacts associated with the `ModelVersion`
func (c *ModelRegistryServiceAPIController) GetModelVersionArtifacts(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
modelversionIdParam := chi.URLParam(r, "modelversionId")
Expand Down
Loading

0 comments on commit 7c54315

Please sign in to comment.