Skip to content

Commit

Permalink
tidied up the classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hallett committed Jul 24, 2023
1 parent 6b123fd commit 4bbb771
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 325 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## 0.1.0

- Initial version
- Mostly works with a simple FastAPI generated spec (3.0.2)
- Works with Twilio's spec (see example_openapi_specs/ directory) (3.0.1)
- Almost works with stripes

### 0.2.0

- Improved CLI output
- Now supports an openapi spec generated from a dotnet project (`Microsoft.OpenApi.Models`)
- async client support
- HTTP Bearer authentication support
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Plus - there is no complex boilerplate and the generated code is very small.
* Fully typed API Client using Pydantic.
* Minimalist and easy to use - the generated code is tiny.
* Choose either sync (default) or async - we support both.
* Generates authentication code for you (curently only supports HTTP Bearer auth)
* Written entirely in Python - no need to install other languages to use OpenAPI.

We're built on:
Expand All @@ -34,7 +35,7 @@ poetry add clientele
### From URLs

```sh
clientele generate -u URL_TO_OPEN_API.json -o output/
clientele generate -u http://URL_TO_OPEN_API.json -o output/
```

### From files
Expand All @@ -47,4 +48,17 @@ clientele generate -f path/to/file.json -o output/

```sh
clientele generate -f path/to/file.json -o output/ --async t
```
```

## Authentication

If your OpenAPI spec provides security information for the following authentication methods:

* HTTP Bearer

Then clientele will provide you information on the environment variables you need to set to
make this work during the generation. For example:

```sh
[info ] Generated HTTP Bearer auth, use with this environment variable to use: {EXAMPLE_BEARER_AUTH}
```
153 changes: 153 additions & 0 deletions example_openapi_specs/simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"openapi": "3.0.2",
"info": {
"title": "Simple API Example",
"version": "0.1.0"
},
"paths": {
"/health-check": {
"get": {
"summary": "Health Check",
"description": "Standard health check.",
"operationId": "health_check_health_check_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HealthCheckResponse"
}
}
}
}
}
}
},
"/test-input": {
"post": {
"summary": "Test Input",
"description": "A POST API endpoint for testing",
"operationId": "test_input_test_input_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TestInputData"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TestInputResponse"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {
"$ref": "#/components/schemas/ValidationError"
}
}
}
},
"HealthCheckResponse": {
"title": "HealthCheckResponse",
"type": "object",
"properties": {
"status": {
"title": "Status",
"type": "string"
}
}
},
"TestInputData": {
"title": "TestInputData",
"required": [
"my_title"
],
"type": "object",
"properties": {
"my_title": {
"title": "My Title",
"type": "string"
}
}
},
"TestInputResponse": {
"title": "TestInputResponse",
"required": [
"title"
],
"type": "object",
"properties": {
"title": {
"title": "Title",
"type": "string"
}
}
},
"ValidationError": {
"title": "ValidationError",
"required": [
"loc",
"msg",
"type"
],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
}
},
"msg": {
"title": "Message",
"type": "string"
},
"type": {
"title": "Error Type",
"type": "string"
}
}
}
}
}
}
7 changes: 6 additions & 1 deletion src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ def generate(url, file, output, asyncio):
with open(file, "r") as f:
spec = Spec.from_file(f)
log.info(
f"Found API client for {spec['info']['title']} | version {spec['info']['version']}"
f"Found API specification for {spec['info']['title']} | version {spec['info']['version']}"
)
major, _, _ = spec["openapi"].split(".")
if int(major) < 3:
log.warning(
f"clientele only supports OpenAPI version 3.0.0 and up, and you have {spec['openapi']}"
)
return
log.info(f"OpenAPI version {spec['openapi']}")
if asyncio:
log.info("Generating async client...")
else:
log.info("Generating sync client...")
Generator(spec=spec, asyncio=asyncio, output_dir=output).generate(url=url)


Expand Down
Loading

0 comments on commit 4bbb771

Please sign in to comment.