Skip to content

Commit

Permalink
use python instead of python-experimental for py client
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuyangh committed May 14, 2022
1 parent a7d3c45 commit 9246f44
Show file tree
Hide file tree
Showing 94 changed files with 5,409 additions and 5,636 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/py-client-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: "Python API Client Release"

on:
push:
branches: [main, "feat/openapi-py-client"]
branches: [main]
paths:
[
"openapi/openapi.yaml",
".github/workflows/py-client-release.yml",
"openapi/python_explerimental_client_template/*",
"openapi/python_client_urllib3_templates/*",
]

jobs:
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Generate Python Client
run: |
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.4.0/openapi-generator-cli-5.4.0.jar -O openapi-generator-cli.jar
java -jar openapi-generator-cli.jar generate -i openapi/openapi.yaml -g python-experimental -o python_client -t openapi/python_explerimental_client_template "--additional-properties=packageName=explainaboard_api_client,packageVersion=${{ steps.gen_tag.outputs.tag }}"
java -jar openapi-generator-cli.jar generate -i openapi/openapi.yaml -g python -o python_client -t "openapi/python_client_urllib3_templates" "--additional-properties=packageName=explainaboard_api_client,packageVersion=${{ steps.gen_tag.outputs.tag }}"
- name: "build"
run: |
cd python_client
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ swagger-codegen-cli*.jar
openapi-generator-cli*.jar
frontend/src/clients/openapi
openapi/python_client
openapi/python_experimental_client_templates
.env
11 changes: 10 additions & 1 deletion openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,16 @@ components:
format: url
paper_info:
$ref: "#/components/schemas/PaperInfo"
required: [task, is_private, model_name, metric_names, paper_info]
required:
[
task,
is_private,
model_name,
metric_names,
paper_info,
source_language,
target_language,
]

SystemOutputProps:
type: object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# {{{projectName}}}
{{#if appDescriptionWithNewLines}}
{{{appDescriptionWithNewLines}}}
{{/if}}
{{#appDescriptionWithNewLines}}
{{{.}}}
{{/appDescriptionWithNewLines}}

This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: {{appVersion}}
- Package version: {{packageVersion}}
{{#unless hideGenerationTimestamp}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/unless}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#if infoUrl}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/if}}
{{/infoUrl}}

## Requirements.

Python {{generatorLanguageVersion}}
v3.9 is needed so one can combine classmethod and property decorators to define
object schema properties as classes
Python {{{generatorLanguageVersion}}}

## Installation & Usage
### pip install
Expand Down
111 changes: 111 additions & 0 deletions openapi/python_client_urllib3_templates/README_common.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
```python
{{#apiInfo}}{{#apis}}{{#-last}}{{#hasHttpSignatureMethods}}import datetime{{/hasHttpSignatureMethods}}{{/-last}}{{/apis}}{{/apiInfo}}
import time
import {{{packageName}}}
from pprint import pprint
{{#apiInfo}}
{{#apis}}
{{#-first}}
from {{apiPackage}} import {{classFilename}}
{{#imports}}
{{{import}}}
{{/imports}}
{{#operations}}
{{#operation}}
{{#-first}}
{{> python_doc_auth_partial}}

# Enter a context with an instance of the API client
with {{{packageName}}}.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = {{classFilename}}.{{{classname}}}(api_client)
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}

try:
{{#summary}} # {{{.}}}
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}
pprint(api_response){{/returnType}}
except {{{packageName}}}.ApiException as e:
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
{{/-first}}
{{/operation}}
{{/operations}}
{{/-first}}
{{/apis}}
{{/apiInfo}}
```

## Documentation for API Endpoints

All URIs are relative to *{{basePath}}*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

## Documentation For Models

{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
{{/model}}{{/models}}

## Documentation For Authorization

{{^authMethods}}
All endpoints do not require authorization.
{{/authMethods}}
{{#authMethods}}
{{#last}} Authentication schemes defined for the API:{{/last}}
## {{{name}}}

{{#isApiKey}}
- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication
{{/isBasicBasic}}
{{#isBasicBearer}}
- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
{{/isBasicBearer}}
{{#isHttpSignature}}
- **Type**: HTTP signature authentication
{{/isHttpSignature}}
{{/isBasic}}
{{#isOAuth}}
- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}

## Author

{{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}}
{{/-last}}{{/apis}}{{/apiInfo}}

## Notes for Large OpenAPI documents
If the OpenAPI document is large, imports in {{{packageName}}}.apis and {{{packageName}}}.models may fail with a
RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:

Solution 1:
Use specific imports for apis and models like:
- `from {{{packageName}}}.api.default_api import DefaultApi`
- `from {{{packageName}}}.model.pet import Pet`

Solution 2:
Before importing the package, adjust the maximum recursion limit as shown below:
```
import sys
sys.setrecursionlimit(1500)
import {{{packageName}}}
from {{{packageName}}}.apis import *
from {{{packageName}}}.models import *
```
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
# {{{projectName}}}
{{#if appDescription}}
{{{appDescription}}}
{{/if}}
{{#appDescription}}
{{{.}}}
{{/appDescription}}

The `{{packageName}}` package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: {{appVersion}}
- Package version: {{packageVersion}}
{{#unless hideGenerationTimestamp}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/unless}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#if infoUrl}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/if}}
{{/infoUrl}}

## Requirements.

Python {{generatorLanguageVersion}}
Python {{{generatorLanguageVersion}}}

## Installation & Usage

This python library package is generated without supporting files like setup.py or requirements files

To be able to use it, you will need these dependencies in your own package that uses this library:

* urllib3 >= 1.15
* certifi
* urllib3 >= 1.25.3
* python-dateutil
{{#if asyncio}}
{{#asyncio}}
* aiohttp
{{/if}}
{{#if tornado}}
{{/asyncio}}
{{#tornado}}
* tornado>=4.2,<5
{{/if}}
{{/tornado}}

## Getting Started

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{#with apiInfo}}
{{#each apis}}
{{#if @first}}
{{#apiInfo}}
{{#apis}}
{{#-first}}
# do not import all apis into this module because that uses a lot of memory and stack frames
# if you need the ability to import all apis from one package, import them with
# from {{packageName}}.apis import {{classname}}
{{/if}}
{{/each}}
{{/with}}
{{/-first}}
{{/apis}}
{{/apiInfo}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{#with apiInfo}}
{{#each apis}}
{{#if @first}}
# coding: utf-8
{{#apiInfo}}
{{#apis}}
{{#-first}}

# flake8: noqa

Expand All @@ -10,15 +9,15 @@
# raise a `RecursionError`.
# In order to avoid this, import only the API that you directly need like:
#
# from {{packagename}}.{{apiPackage}}.{{classFilename}} import {{classname}}
# from {{packagename}}.api.{{classFilename}} import {{classname}}
#
# or import this package, but before doing it, use:
#
# import sys
# sys.setrecursionlimit(n)

# Import APIs into API package:
{{/if}}
from {{packageName}}.{{apiPackage}}.{{classFilename}} import {{classname}}
{{/each}}
{{/with}}
{{/-first}}
from {{apiPackage}}.{{classFilename}} import {{classname}}
{{/apis}}
{{/apiInfo}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# reference which would not work in python2
# do not import all models into this module because that uses a lot of memory and stack frames
# if you need the ability to import all models from one package, import them with
# from {{packageName}}.models import ModelA, ModelB
# from {{packageName}.models import ModelA, ModelB
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# coding: utf-8

# flake8: noqa

# import all models into this package
# if you have many models here with many references from one model to another this may
# raise a RecursionError
# to avoid this, import only the models that you directly need like:
# from from {{packageName}}.{{modelPackage}}.pet import Pet
# from from {{modelPackage}}.pet import Pet
# or import this package, but before doing it, use:
# import sys
# sys.setrecursionlimit(n)

{{#each models}}
{{#with model}}
from {{packageName}}.{{modelPackage}}.{{classFilename}} import {{classname}}
{{/with}}
{{/each}}
{{#models}}
{{#model}}
from {{modelPackage}}.{{classFilename}} import {{classname}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

# flake8: noqa

{{>partial_header}}
Expand All @@ -11,9 +9,9 @@ from {{packageName}}.api_client import ApiClient

# import Configuration
from {{packageName}}.configuration import Configuration
{{#if hasHttpSignatureMethods}}
{{#hasHttpSignatureMethods}}
from {{packageName}}.signing import HttpSigningConfiguration
{{/if}}
{{/hasHttpSignatureMethods}}

# import exceptions
from {{packageName}}.exceptions import OpenApiException
Expand All @@ -22,7 +20,7 @@ from {{packageName}}.exceptions import ApiTypeError
from {{packageName}}.exceptions import ApiValueError
from {{packageName}}.exceptions import ApiKeyError
from {{packageName}}.exceptions import ApiException
{{#if recursionLimit}}
{{#recursionLimit}}

__import__('sys').setrecursionlimit({{recursionLimit}})
{{/if}}
__import__('sys').setrecursionlimit({{{.}}})
{{/recursionLimit}}
Loading

0 comments on commit 9246f44

Please sign in to comment.