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

Generate OpenAPI schema for Elasticsearch Serverless #2047

Merged
merged 17 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 16 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
13 changes: 0 additions & 13 deletions .editorconfig

This file was deleted.

4 changes: 2 additions & 2 deletions .github/check-license-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function check_license_header {

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

for f in $(git ls-files | grep '\.js$'); do
for f in $(git ls-files | grep -v schema-wasm-lib/pkg |grep '\.js$'); do
if ! check_license_header $f; then
nErrors=$((nErrors+1))
fi
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ clean-dep: ## Clean npm dependencies
transform-expand-generics: ## Create a new schema with all generics expanded
@npm run transform-expand-generics --prefix compiler

transform-to-openapi: ## Generate the OpenAPI definition from the compiled schema
@npm run transform-to-openapi --prefix compiler

dump-routes: ## Create a new schema with all generics expanded
@npm run dump-routes --prefix compiler

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

bump:
@echo ">> bumping..."
Expand Down
11 changes: 11 additions & 0 deletions compiler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"format:fix": "prettier --config .prettierrc.json --write ../specification/",
"generate-schema": "ts-node src/index.ts",
"transform-expand-generics": "ts-node src/transform/expand-generics.ts",
"transform-to-openapi": "ts-node src/transform/schema-to-openapi.ts",
"filter-by-availability": "ts-node src/transform/filter-by-availability.ts",
"dump-routes": "ts-node src/dump/extract-routes.ts",
"compile:specification": "tsc --project ../specification/tsconfig.json --noEmit",
Expand All @@ -36,6 +37,7 @@
"fastest-levenshtein": "^1.0.12",
"ora": "^5.4.1",
"safe-stable-stringify": "^2.3.1",
"schema-wasm-lib": "file:../openapi-converter/schema-wasm-lib/pkg",
"semver": "^7.5.2",
"ts-morph": "^13.0.3",
"zx": "^4.3.0"
Expand Down
39 changes: 39 additions & 0 deletions compiler/src/transform/schema-to-openapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { convert_schema_to_openapi } from 'schema-wasm-lib'
import { argv } from 'zx'
import { join } from 'path'
import { readFileSync, writeFileSync } from 'fs'

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

const inputText = readFileSync(
inputPath,
{ encoding: 'utf8' }
)

const output = convert_schema_to_openapi(inputText, 'serverless')

writeFileSync(
outputPath,
output,
'utf8'
)
2 changes: 2 additions & 0 deletions openapi-converter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
target
Loading
Loading