Skip to content

Commit

Permalink
feat: add privateKey sdk options, more helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrt1n committed Aug 7, 2024
1 parent 8d40293 commit d94f9fc
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 58 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
###############################################################################

include makefiles/ci.mk

include makefiles/test.mk

###############################################################################
Expand All @@ -18,6 +17,11 @@ include makefiles/start.mk
###############################################################################
include makefiles/tag.mk

###############################################################################
### Swagger, OpenAPI, and Speakeasy ###
###############################################################################
include makefiles/api.mk

###############################################################################
### Docker Utils ###
###############################################################################
Expand Down
14 changes: 13 additions & 1 deletion cardinal/server/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -649,5 +649,17 @@
}
}
},
"x-original-swagger-version": "2.0"
"x-original-swagger-version": "2.0",
"x-speakeasy-globals": {
"parameters": [
{
"name": "privateKey",
"in": "query",
"schema": {
"type": "string"
},
"x-speakeasy-globals-hidden": true
}
]
}
}
60 changes: 60 additions & 0 deletions makefiles/api.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#################
# swagger #
#################

.PHONY: swaggo-install

swaggo-install:
echo "--> Installing swaggo/swag cli"
go install github.com/swaggo/swag/cmd/swag@latest

swagger:
$(MAKE) swaggo-install
swag init -g cardinal/server/server.go -o cardinal/server/docs/ --parseDependency

swagger-check:
$(MAKE) swaggo-install

@echo "--> Generate latest Swagger specs"
cd cardinal && \
mkdir -p .tmp/swagger && \
swag init -g server/server.go -o .tmp/swagger --parseInternal --parseDependency

@echo "--> Compare existing and latest Swagger specs"
cd cardinal && \
docker run --rm -v ./:/local-repo ghcr.io/argus-labs/devops-infra-swagger-diff:2.0.0 \
/local-repo/server/docs/swagger.json /local-repo/.tmp/swagger/swagger.json && \
echo "swagger-diff: no changes detected"

@echo "--> Cleanup"
rm -rf .tmp/swagger

#####################
# swagger codegen #
#####################

.PHONY: swagger-codegen
SWAGGER_DIR = cardinal/server/docs
GEN_DIR = .tmp/swagger-codegen

swagger-codegen-install:
@echo "--> Installing swagger-codegen"
wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.57/swagger-codegen-cli-3.0.57.jar -O swagger-codegen-cli.jar
echo '#!/usr/bin/java -jar' > swagger-codegen
cat swagger-codegen-cli.jar >> swagger-codegen
chmod +x swagger-codegen
mv swagger-codegen ~/.local/bin/
rm swagger-codegen-cli.jar

swagger-codegen:
@echo "--> Generating OpenAPI v3.0 document from $(SWAGGER_DIR)"
swagger-codegen generate -l openapi -i "$(SWAGGER_DIR)/swagger.json" -o $(GEN_DIR)
node ./scripts/pre-speakeasy.js "$(GEN_DIR)/openapi.json"
mv "$(GEN_DIR)/openapi.json" $(SWAGGER_DIR)
@echo "--> Cleanup"
rm -rf $(TMP_DIR)

speakeasy:
$(MAKE) swagger-codegen
speakeasy run
./scripts/post-speakeasy.sh
56 changes: 0 additions & 56 deletions makefiles/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,59 +92,3 @@ unit-test-all:
$(MAKE) unit-test evm
$(MAKE) unit-test sign
$(MAKE) unit-test relay/nakama

#################
# swagger #
#################

.PHONY: swaggo-install

swaggo-install:
echo "--> Installing swaggo/swag cli"
go install github.com/swaggo/swag/cmd/swag@latest

swagger:
$(MAKE) swaggo-install
swag init -g cardinal/server/server.go -o cardinal/server/docs/ --parseDependency

swagger-check:
$(MAKE) swaggo-install

@echo "--> Generate latest Swagger specs"
cd cardinal && \
mkdir -p .tmp/swagger && \
swag init -g server/server.go -o .tmp/swagger --parseInternal --parseDependency

@echo "--> Compare existing and latest Swagger specs"
cd cardinal && \
docker run --rm -v ./:/local-repo ghcr.io/argus-labs/devops-infra-swagger-diff:2.0.0 \
/local-repo/server/docs/swagger.json /local-repo/.tmp/swagger/swagger.json && \
echo "swagger-diff: no changes detected"

@echo "--> Cleanup"
rm -rf .tmp/swagger

#####################
# swagger codegen #
#####################

.PHONY: swagger-codegen
SWAGGER_DIR = cardinal/server/docs
GEN_DIR = .tmp/swagger-codegen

swagger-codegen-install:
@echo "--> Installing swagger-codegen"
wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.57/swagger-codegen-cli-3.0.57.jar -O swagger-codegen-cli.jar
echo '#!/usr/bin/java -jar' > swagger-codegen
cat swagger-codegen-cli.jar >> swagger-codegen
chmod +x swagger-codegen
mv swagger-codegen ~/.local/bin/
rm swagger-codegen-cli.jar

swagger-codegen:
@echo "--> Generating OpenAPI v3.0 document from $(SWAGGER_DIR)"
swagger-codegen generate -l openapi -i "$(SWAGGER_DIR)/swagger.json" -o $(GEN_DIR)
node ./scripts/customize-openapi.js "$(GEN_DIR)/openapi.json"
mv "$(GEN_DIR)/openapi.json" $(SWAGGER_DIR)
@echo "--> Cleanup"
rm -rf $(TMP_DIR)
7 changes: 7 additions & 0 deletions scripts/post-speakeasy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/bash

sed -i 's/privateKey?: string | undefined;/privateKey: string;/' cardinal/sdk/typescript/src/lib/config.ts
sed -i 's/privateKey?: string | undefined;/privateKey: string;/' cardinal/sdk/typescript/lib/config.d.ts

sed -i 's/serverURL?: string;/serverURL: string;/' cardinal/sdk/typescript/src/lib/config.ts
sed -i 's/serverURL?: string;/serverURL: string;/' cardinal/sdk/typescript/lib/config.d.ts
14 changes: 14 additions & 0 deletions scripts/customize-openapi.js → scripts/pre-speakeasy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ data.paths['/events'].get['x-speakeasy-ignore'] = true
data.paths['/query/{queryGroup}/{queryName}'].post['x-speakeasy-ignore'] = true
data.paths['/tx/{txGroup}/{txName}'].post['x-speakeasy-ignore'] = true

// sdk global params
data['x-speakeasy-globals'] = {
parameters: [
{
name: 'privateKey',
in: 'query',
schema: {
type: 'string'
},
'x-speakeasy-globals-hidden': true
}
]
}

try {
fs.writeFileSync(openapiPath, JSON.stringify(data, null, 2))
console.log('Updated openapi.json with speakeasy attributes')
Expand Down

0 comments on commit d94f9fc

Please sign in to comment.