From 66917be588e19fa1dcbebb97c9b22c11f9866cdc Mon Sep 17 00:00:00 2001 From: Domenico Andreoli Date: Fri, 21 Apr 2023 10:29:57 +0200 Subject: [PATCH 1/2] Accept Content-Type `text/yaml` --- cmd/internal/utils/endpoint.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/internal/utils/endpoint.go b/cmd/internal/utils/endpoint.go index b4a69421..2e87378b 100644 --- a/cmd/internal/utils/endpoint.go +++ b/cmd/internal/utils/endpoint.go @@ -34,7 +34,7 @@ func DecodeRequestBody(w http.ResponseWriter, req *http.Request, data any, known } switch content_type[0] { - case "application/yaml": + case "application/yaml", "text/yaml": dec := yaml.NewDecoder(req.Body) dec.KnownFields(knownFields) err := dec.Decode(data) From 43abeafc39b5457d269ed32ffd13ded22a5a03b7 Mon Sep 17 00:00:00 2001 From: Domenico Andreoli Date: Thu, 20 Apr 2023 11:29:06 +0200 Subject: [PATCH 2/2] Add openapi spec --- .github/workflows/main.yml | 3 + .license_ignore | 2 + Makefile | 10 +- docs/api-spec.html | 351 +++++++++++++++++++++++++++++++++++++ docs/api-spec.yaml | 70 ++++++++ 5 files changed, 435 insertions(+), 1 deletion(-) create mode 100644 docs/api-spec.html create mode 100644 docs/api-spec.yaml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b9c0e38..7627a7cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,6 +47,9 @@ jobs: - name: Lint code run: make lint + - name: Check docs + run: make docs + - name: Run unit tests env: TEST_SCHEMA_URI: "./etc/ecs-8.2.0.tar.gz" diff --git a/.license_ignore b/.license_ignore index ac3e4997..afe3bfb2 100644 --- a/.license_ignore +++ b/.license_ignore @@ -15,6 +15,8 @@ requirements.txt runtime.txt setup.cfg +docs/api-spec.html + scripts/generate-alerts.sh scripts/generate-network-events.sh diff --git a/Makefile b/Makefile index aea12263..7febee65 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ define embed-python endef endif +REDOCLY := npx -y @redocly/cli + rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) all: lint tests @@ -32,6 +34,7 @@ prereq-go: prereq-py lint: $(PYTHON) -m black -q --check geneve tests || ($(PYTHON) -m black geneve tests; false) $(PYTHON) -m isort -q --check geneve tests || ($(PYTHON) -m isort geneve tests; false) + $(REDOCLY) lint docs/api-spec.yaml license-check: bash scripts/license_check.sh @@ -92,6 +95,11 @@ package: pkg-build $(MAKE) pkg-install VENV=$(VENV) rm -rf $(VENV) +docs/api-spec.html: docs/api-spec.yaml + $(REDOCLY) build-docs --output $@ $< + +docs: docs/api-spec.html + CREDS_FILE=credentials-cloud-stack.json cloud-stack-up: @@ -135,4 +143,4 @@ override TEST_STACK_VERSION := $(shell \ ) endif -.PHONY: lint tests online_tests run up down +.PHONY: docs lint tests online_tests run up down diff --git a/docs/api-spec.html b/docs/api-spec.html new file mode 100644 index 00000000..56505476 --- /dev/null +++ b/docs/api-spec.html @@ -0,0 +1,351 @@ + + + + + + Geneve + + + + + + + + + +

Geneve (0.2.0)

Download OpenAPI specification:Download

Domenico Andreoli: domenico.andreoli@elastic.co

Geneve REST API

+

info

Return server status

Authorizations:
None

Responses

schema

Create a new schema

Authorizations:
None
path Parameters
name
required
string
Request Body schema: text/plain
object (schema)

Responses

+ + + + diff --git a/docs/api-spec.yaml b/docs/api-spec.yaml new file mode 100644 index 00000000..8f51c119 --- /dev/null +++ b/docs/api-spec.yaml @@ -0,0 +1,70 @@ +# 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. + +openapi: "3.1.0" +info: + title: Geneve + description: Geneve REST API + version: 0.2.0 + contact: + name: Domenico Andreoli + email: domenico.andreoli@elastic.co +servers: + - url: http://localhost:9256/api + description: Geneve +security: + - {} +paths: + "/status": + get: + tags: ["info"] + summary: Return server status + operationId: get-status + responses: + "200": + description: A source is returned + content: + text/plain: + schema: + type: string + properties: {} + "/schema/{name}": + parameters: + - name: name + in: path + required: true + schema: + type: string + put: + tags: ["schema"] + summary: Create a new schema + operationId: create-schema + requestBody: + content: + text/plain: + schema: + $ref: "#/components/schemas/schema" + responses: + "200": + description: pippo +tags: + - name: info + - name: schema +components: + schemas: + schema: + type: object