Skip to content

Commit 8d00b77

Browse files
committed
Add openapi conversion in the "contrib" target, misc cleanup
1 parent e863d62 commit 8d00b77

File tree

8 files changed

+49
-93416
lines changed

8 files changed

+49
-93416
lines changed

.github/check-license-headers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ function check_license_header {
2727

2828
cd "$TOP"
2929
nErrors=0
30-
for f in $(git ls-files | grep '\.ts$'); do
30+
for f in $(git ls-files | grep -v schema-wasm-lib/pkg | grep '\.ts$'); do
3131
if ! check_license_header $f; then
3232
nErrors=$((nErrors+1))
3333
fi
3434
done
3535

36-
for f in $(git ls-files | grep '\.js$'); do
36+
for f in $(git ls-files | grep -v schema-wasm-lib/pkg |grep '\.js$'); do
3737
if ! check_license_header $f; then
3838
nErrors=$((nErrors+1))
3939
fi

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ clean-dep: ## Clean npm dependencies
4747
transform-expand-generics: ## Create a new schema with all generics expanded
4848
@npm run transform-expand-generics --prefix compiler
4949

50+
transform-to-openapi: ## Generate the OpenAPI definition from the compiled schema
51+
@npm run transform-to-openapi --prefix compiler
52+
5053
dump-routes: ## Create a new schema with all generics expanded
5154
@npm run dump-routes --prefix compiler
5255

53-
contrib: | generate license-check spec-format-fix ## Pre contribution target
56+
contrib: | generate license-check spec-format-fix transform-to-openapi ## Pre contribution target
5457

5558
bump:
5659
@echo ">> bumping..."

compiler/src/transform/schema-to-openapi.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
import {convert_schema_to_openapi} from 'schema-wasm-lib';
221
import {argv} from "zx";
322
import {join} from "path";
423
import {readFileSync, writeFileSync} from "fs";
524

6-
725
const inputPath = argv.input ?? join(__dirname, '..', '..', '..', 'output', 'schema', 'schema.json')
826
const outputPath = argv.output ?? join(__dirname, '..', '..', '..', 'output', 'openapi', 'elasticsearch-serverless-openapi.json')
927

openapi-converter/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
REQUIRED_BINS := wasm-pack cargo
2+
$(foreach bin,$(REQUIRED_BINS),\
3+
$(if $(shell command -v $(bin) 2> /dev/null),,$(error Please install `$(bin)`)))
4+
5+
.PHONY: schema-wasm-lib
6+
7+
schema-wasm-lib:
8+
wasm-pack build --release -t nodejs schema-wasm-lib
9+
# we do commit the result in git
10+
rm schema-wasm-lib/pkg/.gitignore

openapi-converter/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# Elasticsearch Rust client generator and other code-generation utilities written in Rust.
1+
# Rust API schema manipulation utilities
22

3-
Workspace members:
3+
This directory contains a set of Rust crates to manipulate and transform the API specification's `schema.json` file. The primary feature is conversion of `schema.json` to an OpenAPI schema for Elasticsearch Serverless.
4+
5+
## Workspace members
46

57
* [`clients_schema`](./clients_schema/): a Rust implementation of the [Elasticsearch specification schema](https://github.com/elastic/elasticsearch-specification/blob/main/compiler/src/model/metamodel.ts) metamodel.
68
* [`clients_schema_to_openapi`](./clients_schema_to_openapi): conversion of the `schema.json` format to OpenAPI. Supersedes [elasticsearch-openapi](https://github.com/elastic/elasticsearch-openapi).
7-
* [`openapi_to_clients_schema`](./openapi_to_clients_schema): experimental, translate an OpenAPI specification to an Elasticsearch
8-
schema that can be used as input for code generation.
9+
* [`schema-wasm-lib`](./schema-wasm-lib): a WebAssembly library that exposes features of this workspace, to allow its use from the larger [schema toolchain](../compiler).
10+
* [`openapi_to_clients_schema`](./openapi_to_clients_schema): experimental, incomplete, work in progress: translate an OpenAPI specification to an Elasticsearch schema that can be used as input for code generation.
11+
12+
## Building
13+
14+
The output of this directory is the `schema-wasm-lib` WebAssembly library. It must be built and committed in this repository every time the Rust code is changed.

openapi-converter/clients_schema_to_openapi/.spectral.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extends: ["spectral:oas"]
44

55
# Silence some rules
66
rules:
7-
operation-tags: off # Operation must have non-empty "tags" array.
8-
oas3-api-servers: off # OpenAPI "servers" must be present and non-empty array.
9-
info-contact: off # Info object must have "contact" object.
10-
info-description: off # Info "description" must be present and non-empty string
7+
oas3-api-servers: off # OpenAPI "servers" must be present and non-empty array.
8+
info-contact: off # Info object must have "contact" object.
9+
info-description: off # Info "description" must be present and non-empty string.
10+
operation-tag-defined: off # Operation tags must be defined in global tags.

openapi-converter/schema-wasm-lib/Makefile

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)