write the data back out.

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2022-02-27 21:59:28 -08:00
parent 653d2b21ee
commit 89a450f697
3 changed files with 687 additions and 659 deletions

View File

@ -15,7 +15,7 @@ generate: docker-image ## Generate the api client.
--name python-generator \
-v $(CURDIR):/usr/src \
--workdir /usr/src \
$(DOCKER_IMAGE_NAME) sh -c 'poetry run python generate/generate.py && poetry run autopep8 --in-place --aggressive --aggressive kittycad/models/*.py && poetry run autopep8 --in-place --aggressive --aggressive kittycad/api/*.py'
$(DOCKER_IMAGE_NAME) sh -c 'poetry run python generate/generate.py && poetry run autopep8 --in-place --aggressive --aggressive kittycad/models/*.py && poetry run autopep8 --in-place --aggressive --aggressive kittycad/api/*.py && poetry run autopep8 --in-place --aggressive --aggressive kittycad/*.py && poetry run autopep8 --in-place --aggressive --aggressive generate/*.py'
.PHONY: shell
shell: docker-image ## Pop into a shell in the docker image.

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
from openapi_parser.parser.loader import OpenApiParser
import json
import os
import re
@ -23,6 +24,29 @@ def main():
# Generate the paths.
generatePaths(cwd, parser)
# Add the client information to the generation.
data = parser.data
data['info']['x-python'] = {
'client': """# Create a client with your token.
from kittycad import Client
client = Client(token="$TOKEN")
# - OR -
# Create a new client with your token parsed from the environment variable:
# KITTYCAD_API_TOKEN.
from kittycad import ClientFromEnv
client = ClientFromEnv()""",
'install': 'pip install kittycad',
}
# Rewrite the spec back out.
f = open(path, 'w')
f.write(json.dumps(data, indent=4))
f.close()
def generatePaths(cwd: str, parser: OpenApiParser):
# Make sure we have the directory.

View File

@ -318,8 +318,12 @@
"title": "KittyCAD API",
"version": "0.0.2-6f1ca7e",
"x-go": {
"client": "// Create a client with your token and host.\nclient, err := kittycad.NewClient(\"$TOKEN\", \"your apps user agent\")\nif err != nil {\n panic(err)\n}\n\n// - OR -\n\n// Create a new client with your token and host parsed from the environment\n// variables: KITTYCAD_API_TOKEN.\nclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\nif err != nil {\n panic(err)\n}",
"client": "// Create a client with your token.\nclient, err := kittycad.NewClient(\"$TOKEN\", \"your apps user agent\")\nif err != nil {\n panic(err)\n}\n\n// - OR -\n\n// Create a new client with your token parsed from the environment\n// variable: KITTYCAD_API_TOKEN.\nclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\nif err != nil {\n panic(err)\n}",
"install": "go get github.com/kittycad/kittycad.go"
},
"x-python": {
"client": "# Create a client with your token.\nfrom kittycad import Client\n\nclient = Client(token=\"$TOKEN\")\n\n# - OR -\n\n# Create a new client with your token parsed from the environment variable:\n# KITTYCAD_API_TOKEN.\nfrom kittycad import ClientFromEnv\n\nclient = ClientFromEnv()",
"install": "pip install kittycad"
}
},
"openapi": "3.0.0",