diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a1043f0..cdd9b7e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,24 +12,21 @@ jobs: contents: write steps: - - name: checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: get release - id: get_release + - id: get_release uses: joutvhu/get-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: build - run: docker compose run --env RELEASE=${{ steps.get_release.outputs.tag_name }} spec + - run: docker compose run --env RELEASE=${{ steps.get_release.outputs.tag_name }} spec - - name: release - uses: softprops/action-gh-release@v2 + - uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/v') with: files: | tmp/rst-api-spec.yaml tmp/rst-api-spec.json + tmp/rst-api-spec-unannotated.json diff --git a/Makefile b/Makefile index 614a04a..0eb9dd0 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ spec: tmpdir includes @echo Generating JSON file... @yq -o=json eval tmp/rst-api-spec.yaml > tmp/rst-api-spec.json + @echo Generating unannotated JSON file... + @bin/unannotate.pl tmp/rst-api-spec.json > tmp/rst-api-spec-unannotated.json + static-html: @echo Generating static HTML file... @openapi-generator generate -g html -i tmp/rst-api-spec.yaml >/dev/null diff --git a/bin/unannotate.pl b/bin/unannotate.pl new file mode 100755 index 0000000..a3fa0f3 --- /dev/null +++ b/bin/unannotate.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +use File::Slurp; +use JSON::XS; +use constant ANNOTATION_KEY => q{x-field-extra-annotation}; +use vars qw($JSON $VALUE); +use common::sense; + +$JSON = JSON::XS->new->utf8->canonical->pretty; + +$VALUE = $JSON->decode(join('', read_file($ARGV[0]))); + +unannotate($VALUE); + +print $JSON->encode($VALUE); + +sub unannotate { + my $value = shift; + + if (q{HASH} eq ref($value)) { + foreach my $key (keys(%{$value})) { + if (lc($key) eq ANNOTATION_KEY) { + delete($value->{$key}); + } else { + unannotate($value->{$key}); + } + } + + } elsif (q{ARRAY} eq ref($value)) { + for (my $i = 0 ; $i < scalar(@{$value}) ; $i++) { + unannotate($value->[$i]); + } + } +}