Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecated kcl-openapi tool and just used as a normal go package #122

Merged
merged 1 commit into from
Nov 4, 2024
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
61 changes: 0 additions & 61 deletions .github/workflows/release.yml

This file was deleted.

77 changes: 0 additions & 77 deletions .goreleaser.yml

This file was deleted.

63 changes: 6 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,79 +17,28 @@ Main use cases:
+ Kubernetes CRD
+ Translate Kubernetes CRD to KCL code

## Quick Start

### Install

The kcl-openapi tool can be installed in both ways:

- [go install](#1-go-install)
- [curl|sh install (MacOS & Linux)](#2-curlsh-install-macos--linux)
- [download from release](#3-download-from-release)

## 1 go install

```shell
go install kcl-lang.io/kcl-openapi@latest
```

## 2 Curl|sh install (MacOS & Linux)

If you don't have to go, you can install the CLI with this one-liner:

```shell
curl -fsSL https://kcl-lang.io/script/install-kcl-openapi.sh | /bin/bash
```

## 3 Download from release

```shell
# 1. download the released binary from:
# https://github.com/kcl-lang/kcl-openapi/releases

# 2. Unzip the package and add the binary location to PATH
export PATH="<Your directory to store KCLOpenAPI binary>:$PATH"
```

## Features

The tool translates Swagger OpenAPI spec and Kubernetes CRD to KCL models.
The package translates Swagger OpenAPI spec and Kubernetes CRD to KCL models.

### Translate Swagger OpenAPI Spec to KCL

The tool now supports [OpenAPI 2.0](https://swagger.io/specification/v2/). By parsing the "Definitions" section of the spec, the KCL OpenAPI
tool will extract the defined models from it and generate the corresponding KCL representation.

The command is as follows:

```shell
kcl-openapi generate model -f ${your_open_api_spec} -t ${the_kcl_files_output_dir}
```
The package now supports [OpenAPI 2.0](https://swagger.io/specification/v2/). By parsing the "Definitions" section of the spec, the KCL OpenAPI
package will extract the defined models from it and generate the corresponding KCL representation.

> **Note**: The [Kubernetes KCL models](https://github.com/orgs/KusionStack/packages/container/package/k8s) among all versions are pre-generated, you get it by executing `kpm add k8s:<version>` under your project. For detailed information about kpm usage, please refer to [kpm quick start guide](https://github.com/kcl-lang/kpm#quick-start).
Alternatively, if you may want to generate them yourself, please refer [Generate KCL Packages from Kubernetes OpenAPI Specs](./docs/generate_from_k8s_spec.md).
> **Note**: The [Kubernetes KCL models](https://github.com/orgs/KusionStack/packages/container/package/k8s) among all versions are pre-generated, you get it by executing `kcl mod add k8s:<version>` under your project. Alternatively, if you may want to generate them yourself, please refer [Generate KCL Packages from Kubernetes OpenAPI Specs](./docs/generate_from_k8s_spec.md).

### Translate Kubernetes CRD to KCL

The tool can also translate
The package can also translate
the [Kubernetes CRD](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/) to KCL models.
By parsing the `spec.versions[n].schema.openAPIV3Schema` (n means the latest version of the spec will be used) section of the CRD, the KCL
OpenAPI tool will extract the structural schema and generate the corresponding KCL representation.

The command is as follows:

```shell
kcl-openapi generate model --crd -f ${your_CRD.yaml} -t ${the_kcl_files_output_dir} --skip-validation
```
OpenAPI package will extract the structural schema and generate the corresponding KCL representation.

## KCL OpenAPI Spec

The [KCL OpenAPI Spec](https://www.kcl-lang.io/docs/tools/cli/openapi/openapi-to-kcl) defines a complete specification of how OpenAPI objects are mapped to KCL language elements.

## Ask for help

If the tool isn't working as you expect, please reach out to us by filing an [issue](https://github.com/kcl-lang/kcl-openapi/issues).

## License

Apache License Version 2.0
Expand Down
Loading