Skip to content
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Edit `openapi.config.json` to use your local or HTTPS OpenAPI specification and
}
```

`source`, `name`, `apiKey.environment`, and the `python` `client`, `package`, `project`, and `version` keys are required; everything else is optional. `python.install` defaults to `pip install <project>`, `python.readme` replaces the generated package README, `repository` fills the package URLs, and `docs.basePath` mounts the documentation under a sub-path. Relative paths resolve against the configuration file. The first OpenAPI server becomes the SDK's default base URL. HTTP bearer authentication and header-based API keys are derived from `components.securitySchemes`.
`source`, `name`, `apiKey.environment`, and the `python` `client`, `package`, and `project` keys are required; everything else is optional. `python.version` defaults to the contract's `info.version` so one bump in the API releases the SDK, `python.install` defaults to `pip install <project>`, `python.readme` replaces the generated package README, `repository` fills the package URLs, and `docs.basePath` mounts the documentation under a sub-path. Relative paths resolve against the configuration file. The first OpenAPI server becomes the SDK's default base URL. HTTP bearer authentication and header-based API keys are derived from `components.securitySchemes`.
Set `OPENAPI_CONFIG` to use a configuration outside this repository, such as a product-specific consumer:

```bash
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Ultralytics OpenAPI 可从声明为 OpenAPI 3.0 至 3.2.0 的规范中读取 `GE
}
```

`source`、`name`、`apiKey.environment` 以及 `python` 中的 `client`、`package`、`project` 和 `version` 为必填项,其余均为可选。`python.install` 默认为 `pip install <project>`,`python.readme` 会替换生成包的 README,`repository` 用于填充包的 URL,`docs.basePath` 可将文档挂载到子路径。相对路径相对于配置文件解析。第一个 OpenAPI 服务器将成为 SDK 的默认基础 URL。HTTP Bearer 认证和基于请求头的 API 密钥均派生自 `components.securitySchemes`。
`source`、`name`、`apiKey.environment` 以及 `python` 中的 `client`、`package` 和 `project` 为必填项,其余均为可选。`python.version` 默认为契约的 `info.version`,因此在 API 中升版一次即可发布 SDK;`python.install` 默认为 `pip install <project>`,`python.readme` 会替换生成包的 README,`repository` 用于填充包的 URL,`docs.basePath` 可将文档挂载到子路径。相对路径相对于配置文件解析。第一个 OpenAPI 服务器将成为 SDK 的默认基础 URL。HTTP Bearer 认证和基于请求头的 API 密钥均派生自 `components.securitySchemes`。
设置 `OPENAPI_CONFIG` 可使用此仓库之外的配置,例如产品专属的使用方配置:

```bash
Expand Down
3 changes: 1 addition & 2 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface OpenApiConfig {
project: string;
readme?: string;
requiresPython?: string;
version: string;
version?: string;
};
source: string;
}
Expand All @@ -38,7 +38,6 @@ export function getConfig(): OpenApiConfig {
"python.client": config.python?.client,
"python.package": config.python?.package,
"python.project": config.python?.project,
"python.version": config.python?.version,
source: config.source,
};
const missing = Object.entries(required).find(([, value]) => !value)?.[0];
Expand Down
6 changes: 5 additions & 1 deletion lib/generators/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,10 @@ export async function generatePython(
output: string,
): Promise<number> {
const resources = prepare(document);
const version = config.python.version ?? document.info.version;
if (!/^\d+(\.\d+)*((a|b|rc)\d+)?(\.post\d+)?(\.dev\d+)?$/.test(version)) {
throw new Error(`Set python.version: contract version "${version}" is not a valid Python package version`);
}
const root = `${output}/src/${config.python.package}`;
const baseUrl = resolveServerUrl(document);
const readmeExample = [...resources]
Expand Down Expand Up @@ -844,7 +848,7 @@ export async function generatePython(
await Promise.all([
Bun.write(
`${output}/pyproject.toml`,
`[build-system]\nrequires = ["uv_build>=0.12.3,<0.13"]\nbuild-backend = "uv_build"\n\n[project]\nname = "${config.python.project}"\nversion = "${config.python.version}"\n${projectMetadata}\nreadme = "README.md"\nlicense = "${license.id}"\nlicense-files = ["LICENSE"]\ndependencies = ["httpx>=0.28,<1"]${projectUrls}\n\n[tool.ruff]\nline-length = 120\n\n[tool.uv.build-backend]\nmodule-name = "${config.python.package}"\n`,
`[build-system]\nrequires = ["uv_build>=0.12.3,<0.13"]\nbuild-backend = "uv_build"\n\n[project]\nname = "${config.python.project}"\nversion = "${version}"\n${projectMetadata}\nreadme = "README.md"\nlicense = "${license.id}"\nlicense-files = ["LICENSE"]\ndependencies = ["httpx>=0.28,<1"]${projectUrls}\n\n[tool.ruff]\nline-length = 120\n\n[tool.uv.build-backend]\nmodule-name = "${config.python.package}"\n`,
),
Bun.write(`${output}/README.md`, readme),
Bun.write(`${output}/LICENSE`, licenseText),
Expand Down