Skip to content

Commit

Permalink
Merge pull request #9 from dylibso/date-time
Browse files Browse the repository at this point in the history
feat: add support for date-time format using time.Time
  • Loading branch information
nilslice authored Jul 31, 2024
2 parents e0010ec + f342cfe commit 0f4b7f9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,28 @@ jobs:
run: |
cd tests && ./test.sh
- name: Run Bindgen Test
run: |
# we already have a folder named bundle
# move it before we get the simulation bundle
# TODO change the name
mv bundle template-bundle
# get the latest release
RELEASE_INFO=$(curl -s "https://api.github.com/repos/dylibso/xtp-bindgen-test/releases/latest")
ASSET_URL=$(echo $RELEASE_INFO | grep -oP '"browser_download_url": "\K(.*bundle.zip)(?=")')
if [ -z "$ASSET_URL" ]; then
echo "Asset URL not found. Please check the asset name or the repository."
exit 1
fi
# download and unzip the bundle
curl -L -o bundle.zip "$ASSET_URL"
unzip bundle.zip
cd bundle/
# Using ../template-bundle so we test the head template
xtp plugin init --schema-file schema.yaml --template ../template-bundle --path exampleplugin --name exampleplugin --feature stub-with-code-samples
xtp plugin build --path exampleplugin
xtp plugin test exampleplugin/dist/plugin.wasm --with test.wasm --mock-host mock.wasm
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { getContext, helpers, Property } from "@dylibso/xtp-bindgen";

function toGolangType(property: Property): string {
if (property.$ref) return property.$ref.name;

switch (property.type) {
case "string":
if (property.format === "date-time") {
return "time.Time";
}
return "string";
case "number":
if (property.format === "float") {
Expand Down
2 changes: 2 additions & 0 deletions template/pdk.gen.go.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main

import (
<% if (JSON.stringify(schema).includes("enum")) { %>"errors"<% } %>
<% if (JSON.stringify(schema).includes("date-time")) { %>"time"<% } %>

pdk "github.com/extism/go-pdk"
)

Expand Down
6 changes: 2 additions & 4 deletions tests/schemas/fruit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ exports:
- lang: typescript
source: |
console.log('Hello World!')
- lang: go
source: |-
println("Hello World!")
return nil
- name: topLevelPrimitives
description: |
This demonstrates how you can accept or return primtive types.
Expand Down Expand Up @@ -119,6 +115,8 @@ schemas:
description: |
A datetime object, we will automatically serialize and deserialize
this for you.
- name: writeParams
$ref: "#/schemas/WriteParams"
contentType: application/json
description: A complex json object
version: v1-draft

0 comments on commit 0f4b7f9

Please sign in to comment.