Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update api spec #99

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
Tags: []Tag{},
Examples: []string{},
Paths: []string{},
Types: []string{},
Types: map[string]string{},

Check warning on line 61 in cmd/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/main.go#L61

Added line #L61 was not covered by tests
WorkingDirectory: wd,
}
// Format the tags for our data.
Expand Down
2 changes: 1 addition & 1 deletion cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Data struct {
WorkingDirectory string
Examples []string
Paths []string
Types []string
Types map[string]string
}

// Tag holds information about tags.
Expand Down
14 changes: 8 additions & 6 deletions cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
}

// Add the type to our types.
data.Types = append(data.Types, enumString)
data.Types[enum.Name] = enumString

Check warning on line 180 in cmd/types.go

View check run for this annotation

Codecov / codecov/patch

cmd/types.go#L180

Added line #L180 was not covered by tests

return nil
}
Expand Down Expand Up @@ -268,7 +268,7 @@
}

// Add the type to our types.
data.Types = append(data.Types, objectString)
data.Types[object.Name] = objectString

Check warning on line 271 in cmd/types.go

View check run for this annotation

Codecov / codecov/patch

cmd/types.go#L271

Added line #L271 was not covered by tests

return nil
}
Expand Down Expand Up @@ -328,15 +328,17 @@
}

for index, oneOf := range s.OneOf {
// We should have a better way of avoiding duplicates. This is a hot fix, but does not scale.
if types[index] == "InputFormat coords" || types[index] == "OutputFormat coords" || types[index] == "ModelingCmd path" || types[index] == "ModelingCmd interaction" || types[index] == "ModelingCmd window" || types[index] == "OkModelingCmdResponse entity_id" {
continue
// Check if we already have this type defined.
iname := printProperty(types[index])
if _, ok := data.Types[iname]; ok {
// We should name the type after the one of.
iname = printProperty(name + " " + types[index])

Check warning on line 335 in cmd/types.go

View check run for this annotation

Codecov / codecov/patch

cmd/types.go#L331-L335

Added lines #L331 - L335 were not covered by tests
}

// Check if we already have a schema for this one of.
reference, ok := spec.Components.Schemas[types[index]]
if !ok {
if err := data.generateSchemaType(types[index], oneOf.Value, spec); err != nil {
if err := data.generateSchemaType(iname, oneOf.Value, spec); err != nil {

Check warning on line 341 in cmd/types.go

View check run for this annotation

Codecov / codecov/patch

cmd/types.go#L341

Added line #L341 was not covered by tests
return err
}
}
Expand Down
8 changes: 6 additions & 2 deletions examples_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions kittycad.go.patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
},
{
"value": {
"example": "// Cmd: Submit one modeling operation.\n// \n// Response depends on which command was submitted, so unfortunately the OpenAPI schema can't generate the right response type.\n// \n// \n// Parameters\n// \n// \t- `body`: A graphics command submitted to the KittyCAD engine via the Modeling API.\n// \n// Cmd: Submit one modeling operation.\n// Response depends on which command was submitted, so unfortunately the OpenAPI schema can't generate the right response type.\n//\n// Parameters\n//\n// - `body`: A graphics command submitted to the KittyCAD engine via the Modeling API.\nfunc ExampleModelingService_Cmd() {\n\tclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tif err := client.Modeling.Cmd(kittycad.ModelingCmdReq{Cmd: \"\", CmdID: kittycad.ParseUUID(\"6ba7b810-9dad-11d1-80b4-00c04fd430c8\")}); err != nil {\n\t\tpanic(err)\n\t}\n\n}\n",
"example": "// Cmd: Submit one modeling operation.\n// \n// Response depends on which command was submitted, so unfortunately the OpenAPI schema can't generate the right response type.\n// \n// \n// Parameters\n// \n// \t- `body`: A graphics command submitted to the KittyCAD engine via the Modeling API.\n// \n// Cmd: Submit one modeling operation.\n// Response depends on which command was submitted, so unfortunately the OpenAPI schema can't generate the right response type.\n//\n// Parameters\n//\n// - `body`: A graphics command submitted to the KittyCAD engine via the Modeling API.\nfunc ExampleModelingService_Cmd() {\n\tclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tresult, err := client.Modeling.Cmd(kittycad.ModelingCmdReq{Cmd: \"\", CmdID: kittycad.ParseUUID(\"6ba7b810-9dad-11d1-80b4-00c04fd430c8\")})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"%#v\", result)\n\n}\n",
"libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#ModelingService.Cmd"
},
"op": "add",
Expand Down Expand Up @@ -609,7 +609,7 @@
},
{
"value": {
"example": "// CommandsWs: Open a websocket which accepts modeling commands.\n// \n// Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.\n// \n// \n// Parameters\n// \n// \t- `fps`\n// \t- `unlockedFramerate`\n// \t- `videoResHeight`\n// \t- `videoResWidth`\n// \n// CommandsWs: Open a websocket which accepts modeling commands.\n// Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.\n//\n// Parameters\n//\n// - `fps`\n// - `unlockedFramerate`\n// - `videoResHeight`\n// - `videoResWidth`\nfunc ExampleModelingService_CommandsWs() {\n\tclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create the websocket connection.\n\tws, err := client.Modeling.CommandsWs(123, true, 123, 123)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tdefer ws.Close()\n\n\tdone := make(chan struct{})\n\n\tgo func() {\n\t\tdefer close(done)\n\t\tfor {\n\t\t\t_, message, err := ws.ReadMessage()\n\t\t\tif err != nil {\n\t\t\t\tlog.Println(\"read:\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlog.Printf(\"recv: %s\", message)\n\t\t}\n\t}()\n\n\tticker := time.NewTicker(time.Second)\n\tdefer ticker.Stop()\n\n\tinterrupt := make(chan os.Signal, 1)\n\tsignal.Notify(interrupt, os.Interrupt)\n\n\tfor {\n\t\tselect {\n\t\tcase \u003c-done:\n\t\t\treturn\n\t\tcase t := \u003c-ticker.C:\n\t\t\terr := ws.WriteMessage(websocket.TextMessage, []byte(t.String()))\n\t\t\tif err != nil {\n\t\t\t\tlog.Println(\"write:\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\tcase \u003c-interrupt:\n\t\t\tlog.Println(\"interrupt\")\n\n\t\t\t// Cleanly close the connection by sending a close message and then\n\t\t\t// waiting (with timeout) for the server to close the connection.\n\t\t\terr := ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, \"\"))\n\t\t\tif err != nil {\n\t\t\t\tlog.Println(\"write close:\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tselect {\n\t\t\tcase \u003c-done:\n\t\t\tcase \u003c-time.After(time.Second):\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n\n}\n",
"example": "// CommandsWs: Open a websocket which accepts modeling commands.\n// \n// Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.\n// \n// \n// Parameters\n// \n// \t- `fps`\n// \t- `unlockedFramerate`\n// \t- `videoResHeight`\n// \t- `videoResWidth`\n// \t- `webrtc`\n// \n// CommandsWs: Open a websocket which accepts modeling commands.\n// Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.\n//\n// Parameters\n//\n// - `fps`\n// - `unlockedFramerate`\n// - `videoResHeight`\n// - `videoResWidth`\n// - `webrtc`\nfunc ExampleModelingService_CommandsWs() {\n\tclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create the websocket connection.\n\tws, err := client.Modeling.CommandsWs(123, true, 123, 123, true)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tdefer ws.Close()\n\n\tdone := make(chan struct{})\n\n\tgo func() {\n\t\tdefer close(done)\n\t\tfor {\n\t\t\t_, message, err := ws.ReadMessage()\n\t\t\tif err != nil {\n\t\t\t\tlog.Println(\"read:\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlog.Printf(\"recv: %s\", message)\n\t\t}\n\t}()\n\n\tticker := time.NewTicker(time.Second)\n\tdefer ticker.Stop()\n\n\tinterrupt := make(chan os.Signal, 1)\n\tsignal.Notify(interrupt, os.Interrupt)\n\n\tfor {\n\t\tselect {\n\t\tcase \u003c-done:\n\t\t\treturn\n\t\tcase t := \u003c-ticker.C:\n\t\t\terr := ws.WriteMessage(websocket.TextMessage, []byte(t.String()))\n\t\t\tif err != nil {\n\t\t\t\tlog.Println(\"write:\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\tcase \u003c-interrupt:\n\t\t\tlog.Println(\"interrupt\")\n\n\t\t\t// Cleanly close the connection by sending a close message and then\n\t\t\t// waiting (with timeout) for the server to close the connection.\n\t\t\terr := ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, \"\"))\n\t\t\tif err != nil {\n\t\t\t\tlog.Println(\"write close:\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tselect {\n\t\t\tcase \u003c-done:\n\t\t\tcase \u003c-time.After(time.Second):\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n\n}\n",
"libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#ModelingService.CommandsWs"
},
"op": "add",
Expand Down
26 changes: 18 additions & 8 deletions paths.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading