Skip to content

Commit

Permalink
Update api spec (#99)
Browse files Browse the repository at this point in the history
* YOYO NEW API SPEC!

* updates

Signed-off-by: Jess Frazelle <[email protected]>

---------

Signed-off-by: Jess Frazelle <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jessfraz and github-actions[bot] authored Aug 30, 2023
1 parent 5935440 commit 12fe3ea
Show file tree
Hide file tree
Showing 8 changed files with 2,647 additions and 1,119 deletions.
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 @@ func run() error {
Tags: []Tag{},
Examples: []string{},
Paths: []string{},
Types: []string{},
Types: map[string]string{},
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 @@ func (data *Data) generateEnumType(name string, s *openapi3.Schema, additionalDo
}

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

return nil
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (data *Data) generateObjectType(name string, s *openapi3.Schema, spec *open
}

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

return nil
}
Expand Down Expand Up @@ -328,15 +328,17 @@ func (data *Data) generateOneOfType(name string, s *openapi3.Schema, spec *opena
}

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 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 {
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

0 comments on commit 12fe3ea

Please sign in to comment.