From f775582fda9d770c322e0b2163b105f81cc1e918 Mon Sep 17 00:00:00 2001 From: Andrew Shannon Brown Date: Tue, 19 Nov 2019 13:01:08 -0800 Subject: [PATCH] Add summary and archived query params to flags endpoint (#37) * Add summary and archived query params to flags endpoint * Add bravado validation * Bump version --- .circleci/config.yml | 4 ++++ Makefile | 4 +++- README.md | 4 ++-- scripts/bravado-validate.py | 6 ++++++ spec/info.yaml | 2 +- spec/parameters.yaml | 12 ++++++++++++ spec/paths/flags.yaml | 2 ++ 7 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 scripts/bravado-validate.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 87bf783..b007e06 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,6 +22,10 @@ jobs: sudo mv ./swagger-codegen-cli.jar /usr/local/bin sudo chmod +x /usr/local/bin/swagger-codegen + - run: + name: Install pip + command: sudo apt install python-pip + - run: name: Loading previous client repos command: | diff --git a/Makefile b/Makefile index 6e9dc56..8cd6a4b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/bash VERSION=$(shell cat $(TARGETS_PATH)/openapi.json | jq -r '.info.version' ) REVISION:=$(shell git rev-parse --short HEAD) -SWAGGER_VERSION=2.4.0 +SWAGGER_VERSION=2.4.8 SWAGGER_JAR=swagger-codegen-cli-${SWAGGER_VERSION}.jar SWAGGER_DOWNLOAD_URL=http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/${SWAGGER_VERSION}/${SWAGGER_JAR} @@ -99,9 +99,11 @@ load_prior_targets: git submodule add -b gh-pages $(REPO_USER_URL)/ld-openapi$(RELEASE_SUFFIX) gh-pages openapi_yaml: $(SWAGGER_JAR) $(TARGETS_PATH) $(MULTI_FILE_SWAGGER) $(CHECK_CODEGEN) + pip install bravado $(MULTI_FILE_SWAGGER) openapi.yaml > $(TARGET_OPENAPI_JSON) $(MULTI_FILE_SWAGGER) -o yaml openapi.yaml > $(TARGET_OPENAPI_YAML) $(CODEGEN) validate -i $(TARGET_OPENAPI_YAML) + python scripts/bravado-validate.py $(TARGETS_PATH): mkdir -p $@ diff --git a/README.md b/README.md index 27facd2..1540d1e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ http://azimi.me/2015/07/16/split-swagger-into-smaller-files.html ## Compiling the spec -The spec is joined from multiple files using a multi-file Swagger tool. To compile the just spec run `make openapi_yaml`. +The spec is joined from multiple files using a multi-file Swagger tool. To compile just the spec run `make openapi_yaml`. Alternatively, you can test a multi-file Swagger spec using VSCode, or by following these instructions for the online editor: @@ -31,7 +31,7 @@ We use the spec to build some internals tools in go. Tests for other specs are Server/client code for the API can be automatically generated. To generate the code: - 1. Ensure that you have `wget`, `yarn`, and `jq` installed. + 1. Ensure that you have `wget`, `yarn`, `jq`, and `pip` installed. 1. Run the `generate` command: ``` > make diff --git a/scripts/bravado-validate.py b/scripts/bravado-validate.py new file mode 100644 index 0000000..733d1b9 --- /dev/null +++ b/scripts/bravado-validate.py @@ -0,0 +1,6 @@ +from bravado.client import SwaggerClient +from bravado.swagger_model import load_file + +# Merely generating a Bravado client is enough to validate the spec. +# Actually using the client is unnecessary. +client = SwaggerClient.from_spec(load_file('./targets/openapi.yaml')) diff --git a/spec/info.yaml b/spec/info.yaml index 3b68b37..06a37ba 100644 --- a/spec/info.yaml +++ b/spec/info.yaml @@ -8,4 +8,4 @@ contact: license: name: Apache 2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html -version: 2.0.21 +version: 2.0.22 diff --git a/spec/parameters.yaml b/spec/parameters.yaml index 9f4300d..c4d52cb 100644 --- a/spec/parameters.yaml +++ b/spec/parameters.yaml @@ -223,6 +223,18 @@ EnvironmentKeyQuery: required: false description: By default, each feature will include configurations for each environment. You can filter environments with the env query parameter. For example, setting env=production will restrict the returned configurations to just your production environment. type: string +SummaryQuery: + name: summary + in: query + required: false + description: By default in api version >= 1, flags will _not_ include their list of prerequisites, targets or rules. Set summary=0 to include these fields for each flag returned. + type: string +ArchivedQuery: + name: archived + in: query + required: false + description: When set to 1, archived flags will be included in the list of flags returned. By default, archived flags are not included in the list of flags. + type: string FeatureFlagKey: name: featureFlagKey in: path diff --git a/spec/paths/flags.yaml b/spec/paths/flags.yaml index ee4d32f..dddce61 100644 --- a/spec/paths/flags.yaml +++ b/spec/paths/flags.yaml @@ -5,6 +5,8 @@ Flags: parameters: - $ref: '#/parameters/ProjectKey' - $ref: '#/parameters/EnvironmentKeyQuery' + - $ref: '#/parameters/SummaryQuery' + - $ref: '#/parameters/ArchivedQuery' - $ref: '#/parameters/Tag' responses: '200':