JSON_FILES = $(wildcard *.json) $(wildcard examples/*.json)
test-jsonlint:
	@for json_file in $(JSON_FILES); do \
		/usr/bin/jsonlint-php $$json_file || exit 1; \
	done

SWAGGER_SCHEMA := tmp/swagger_schema.json
SWAGGER_SCHEMA_URL := https://raw.githubusercontent.com/swagger-api/swagger-spec/master/schemas/v1.2/apiDeclaration.json
$(SWAGGER_SCHEMA):
	mkdir -p tmp
	curl -o $@ $(SWAGGER_SCHEMA_URL)

SWAGGER_FILES := $(wildcard *.api.*.json)
test-swagger: $(SWAGGER_SCHEMA)
	#@for swagger_file in $(SWAGGER_FILES); do \
	#	echo 'Validating' $$swagger_file 'against' $(SWAGGER_SCHEMA); \
	#	json-validator -i $$swagger_file -s $(SWAGGER_SCHEMA) > /dev/null || exit 1; \
	#done

EXAMPLE_FILES = $(wildcard examples/*.example.json)
test-examples:
	cd ../../../../tools/json-validator && ya make -r && cd -;
	@for example_file in $(EXAMPLE_FILES); do \
		schema=`basename $$example_file .example.json`.schema.json; \
		if [ -f $$schema ]; then \
			echo 'Validating' $$example_file 'against' $$schema; \
			../../../../tools/json-validator/json-validator -i $$example_file -s $$schema > /dev/null || exit 1; \
		fi; \
	done

clean:
	rm -rf tmp

test: test-jsonlint test-swagger test-examples
