diff --git a/.gitgnore b/.gitgnore new file mode 100644 index 0000000..45611c8 --- /dev/null +++ b/.gitgnore @@ -0,0 +1,25 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Text editor settings +.idea/ + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace files +go.work +go.work.sum diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..d1e3698 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,75 @@ +name: Unit tests + +on: + pull_request: + push: + paths: + - "**.go" + - "go.mod" + - "go.sum" + - ".github/workflows/*.yaml" + - "example/**" + +jobs: + test-go: + name: Run Go lint and unit tests + runs-on: ubuntu-20.04 + permissions: + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.21" + - uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Install dependencies + run: | + go get -t -v ./... + go install ./... + - name: Format + run: diff -u <(echo -n) <(gofmt -d -s .) + - name: Vet + run: go vet ./... + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + only-new-issues: true + skip-cache: true + - name: Run Go unit tests + run: go test -v -coverpkg=./... -race -timeout 3m -coverprofile=coverage.out ./... + - name: Go coverage format + if: ${{ github.event_name == 'pull_request' }} + run: | + go get github.com/boumenot/gocover-cobertura + go install github.com/boumenot/gocover-cobertura + gocover-cobertura < coverage.out > coverage.xml + - name: Code Coverage Summary Report + uses: irongut/CodeCoverageSummary@v1.3.0 + if: ${{ github.event_name == 'pull_request' }} + with: + filename: coverage.xml + badge: true + fail_below_min: true + format: markdown + hide_branch_rate: false + hide_complexity: true + indicators: true + output: both + thresholds: "50 70" + - name: Add Coverage PR Comment + uses: marocchino/sticky-pull-request-comment@v2 + if: ${{ github.event_name == 'pull_request' }} + with: + path: code-coverage-results.md + - name: Dump docker logs on failure + if: failure() + uses: jwalton/gh-docker-logs@v2 diff --git a/.hasura-connector/.dockerignore b/.hasura-connector/.dockerignore new file mode 100644 index 0000000..4672f19 --- /dev/null +++ b/.hasura-connector/.dockerignore @@ -0,0 +1,4 @@ +.hasura-connector/ +*.hml +.github/ +assets/ \ No newline at end of file diff --git a/.hasura-connector/Dockerfile b/.hasura-connector/Dockerfile new file mode 100644 index 0000000..2ad4b90 --- /dev/null +++ b/.hasura-connector/Dockerfile @@ -0,0 +1,17 @@ +# build context at repo root: docker build -f Dockerfile . +FROM golang:1.22 AS builder + +WORKDIR /app +COPY . . +RUN CGO_ENABLED=0 go build -v -o ndc-cli . + +# stage 2: production image +FROM gcr.io/distroless/base-debian12:nonroot + +# Copy the binary to the production image from the builder stage. +COPY --from=builder /app/ndc-cli /ndc-cli + +ENV CONFIGURATION /config + +# Run the web service on container startup. +CMD ["/ndc-cli", "serve"] \ No newline at end of file diff --git a/.hasura-connector/connector-metadata.yaml b/.hasura-connector/connector-metadata.yaml new file mode 100644 index 0000000..acf7e0e --- /dev/null +++ b/.hasura-connector/connector-metadata.yaml @@ -0,0 +1,9 @@ +packagingDefinition: + type: ManagedDockerBuild +supportedEnvironmentVariables: [] +commands: {} +dockerComposeWatch: + # copy config files into the existing container and restart it + - path: ./config + target: /config + action: sync+restart diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ed67f5c --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# NDC REST Connector + +NDC REST Connector allows you to quickly convert REST APIs to NDC schema and proxy requests from GraphQL Engine v3 to remote services. +The connector can automatically transform OpenAPI 2.0 and 3.0 definitions to NDC schema. + +## Quick start + +Start the connector server at http://localhost:8080 using the [JSON Placeholder](https://jsonplaceholder.typicode.com/) APIs. + +```go +go run . serve --configuration ./rest/testdata/jsonplaceholder +``` + +## How it works + +![REST connector](./assets/rest_connector.png) + +REST connector uses the [NDC REST extension](https://github.com/hasura/ndc-rest-schema#ndc-rest-schema-extension) that includes request information. +The connector has request context to transform the NDC request body to REST request and versa. + +### Configuration + +The connector reads `config.{json,yaml}` file in the configuration folder. The file contains information about the schema file path and its specification: + +```yaml +files: + - path: swagger.json + spec: openapi2 + - path: openapi.yaml + spec: openapi3 + - path: schema.json + spec: ndc +``` + +**Supported specs** + +- `openapi3`: OpenAPI 3.0/3.1. +- `openapi2`: OpenAPI 2.0. +- `ndc`: NDC REST schema. + +The connector can convert OpenAPI to REST NDC schema in runtime. However, it's more flexible and performance-wise to pre-convert them, for example, change better function or procedure names. The connector supports a convert command to do it. + +```sh +ndc-rest convert -f ./rest/testdata/jsonplaceholder/swagger.json -o ./rest/testdata/jsonplaceholder/schema.json --spec openapi2 +``` + +> The `convert` command is imported from the [NDC REST Schema](https://github.com/hasura/ndc-rest-schema#quick-start) CLI tool. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..f21d6b1 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,28 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| -------- | ------------------ | +| >= 0.1.0 | :white_check_mark: | + +## Reporting a Vulnerability + +We’re extremely grateful for security researchers and users who report vulnerabilities to the community. +All reports are thoroughly investigated by a set of community volunteers. + +### When Should I Report a Vulnerability? + +- You think you have discovered a potential security vulnerability in the NDC Go SDK or related components. +- You are unsure how a vulnerability affects the SDK. +- You think you discovered a vulnerability in another project that SDK depends on (e.g. Docker, etc). +- You want to report any other security risk that could potentially harm SDK users. + +### When Should I NOT Report a Vulnerability? + +- You need help applying security-related updates. +- Your issue is not security-related. + +### Security Vulnerability Response + +Each report is acknowledged and analyzed by the project's maintainers. New pull requests are welcome too. diff --git a/assets/rest_connector.png b/assets/rest_connector.png new file mode 100644 index 0000000..1c68763 Binary files /dev/null and b/assets/rest_connector.png differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9ea4ae8 --- /dev/null +++ b/go.mod @@ -0,0 +1,57 @@ +module github.com/hasura/ndc-rest + +go 1.21 + +toolchain go1.22.0 + +require ( + github.com/hasura/ndc-rest-schema v0.0.0-20240312024503-345ae7cb6078 + github.com/hasura/ndc-sdk-go v0.1.1-0.20240312092535-8e480ed1490d + github.com/lmittmann/tint v1.0.4 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/alecthomas/kong v0.9.0 // indirect + github.com/bahlo/generic-list-go v0.2.0 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/buger/jsonparser v1.1.1 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/pb33f/libopenapi v0.15.14 // indirect + github.com/prometheus/client_golang v1.19.0 // indirect + github.com/prometheus/client_model v0.6.0 // indirect + github.com/prometheus/common v0.49.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + github.com/sergi/go-diff v1.3.1 // indirect + github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect + github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect + go.opentelemetry.io/otel v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect + go.opentelemetry.io/otel/exporters/prometheus v0.46.0 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/otel/sdk v1.24.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.24.0 // indirect + go.opentelemetry.io/otel/trace v1.24.0 // indirect + go.opentelemetry.io/proto/otlp v1.1.0 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/net v0.22.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 // indirect + google.golang.org/grpc v1.62.1 // indirect + google.golang.org/protobuf v1.33.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..cacc068 --- /dev/null +++ b/go.sum @@ -0,0 +1,230 @@ +github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU= +github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= +github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA= +github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os= +github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= +github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58= +github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 h1:PRxIJD8XjimM5aTknUK9w6DHLDox2r2M3DI4i2pnd3w= +github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936/go.mod h1:ttYvX5qlB+mlV1okblJqcSMtR4c52UKxDiX9GRBS8+Q= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c= +github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= +github.com/hasura/ndc-rest-schema v0.0.0-20240312024503-345ae7cb6078 h1:5lV4lnOfzP+U+yykgaqWESm6L3fTdSmDEVkzY0NDf8s= +github.com/hasura/ndc-rest-schema v0.0.0-20240312024503-345ae7cb6078/go.mod h1:sa89qdTWWNQUHgHx3FST6oBdTcaW9CBbvW2TFne3oQE= +github.com/hasura/ndc-sdk-go v0.1.1-0.20240312081636-37f5f535293c h1:x9VzFBUG5xKz50CYiOtIZTDy3jByRcolIHGi+CcpJBY= +github.com/hasura/ndc-sdk-go v0.1.1-0.20240312081636-37f5f535293c/go.mod h1:u4+Xp/6icjMUQMGil6tgD05y5ZH1eXZ8gX2OCM/kgcU= +github.com/hasura/ndc-sdk-go v0.1.1-0.20240312092535-8e480ed1490d h1:EhmMj8kWlrxxd0gf4naCsUeX0bIjCjGXF9QdBKndn5w= +github.com/hasura/ndc-sdk-go v0.1.1-0.20240312092535-8e480ed1490d/go.mod h1:u4+Xp/6icjMUQMGil6tgD05y5ZH1eXZ8gX2OCM/kgcU= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lmittmann/tint v1.0.4 h1:LeYihpJ9hyGvE0w+K2okPTGUdVLfng1+nDNVR4vWISc= +github.com/lmittmann/tint v1.0.4/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= +github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= +github.com/pb33f/libopenapi v0.15.14 h1:A0fn45jbthDyFGXfu5bYIZVsWyPI6hJYm3wG143MT8o= +github.com/pb33f/libopenapi v0.15.14/go.mod h1:PEXNwvtT4KNdjrwudp5OYnD1ryqK6uJ68aMNyWvoMuc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= +github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= +github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= +github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= +github.com/prometheus/common v0.49.0 h1:ToNTdK4zSnPVJmh698mGFkDor9wBI/iGaJy5dbH1EgI= +github.com/prometheus/common v0.49.0/go.mod h1:Kxm+EULxRbUkjGU6WFsQqo3ORzB4tyKvlWFOE9mB2sE= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk= +github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ= +github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= +github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.24.0 h1:f2jriWfOdldanBwS9jNBdeOKAQN7b4ugAMaNu1/1k9g= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.24.0/go.mod h1:B+bcQI1yTY+N0vqMpoZbEN7+XU4tNM0DmUiOwebFJWI= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.24.0 h1:mM8nKi6/iFQ0iqst80wDHU2ge198Ye/TfN0WBS5U24Y= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.24.0/go.mod h1:0PrIIzDteLSmNyxqcGYRL4mDIo8OTuBAOI/Bn1URxac= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0/go.mod h1:iSDOcsnSA5INXzZtwaBPrKp/lWu/V14Dd+llD0oI2EA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 h1:Mw5xcxMwlqoJd97vwPxA8isEaIoxsta9/Q51+TTJLGE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0/go.mod h1:CQNu9bj7o7mC6U7+CA/schKEYakYXWr79ucDHTMGhCM= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 h1:Xw8U6u2f8DK2XAkGRFV7BBLENgnTGX9i4rQRxJf+/vs= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0/go.mod h1:6KW1Fm6R/s6Z3PGXwSJN2K4eT6wQB3vXX6CVnYX9NmM= +go.opentelemetry.io/otel/exporters/prometheus v0.46.0 h1:I8WIFXR351FoLJYuloU4EgXbtNX2URfU/85pUPheIEQ= +go.opentelemetry.io/otel/exporters/prometheus v0.46.0/go.mod h1:ztwVUHe5DTR/1v7PeuGRnU5Bbd4QKYwApWmuutKsJSs= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= +go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= +go.opentelemetry.io/otel/sdk/metric v1.24.0 h1:yyMQrPzF+k88/DbH7o4FMAs80puqd+9osbiBrJrz/w8= +go.opentelemetry.io/otel/sdk/metric v1.24.0/go.mod h1:I6Y5FjH6rvEnTTAYQz3Mmv2kl6Ek5IIrmwTLqMrrOE0= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/proto/otlp v1.1.0 h1:2Di21piLrCqJ3U3eXGCTPHE9R8Nh+0uglSnOyxikMeI= +go.opentelemetry.io/proto/otlp v1.1.0/go.mod h1:GpBHCBWiqvVLDqmHZsoMM3C5ySeKTC7ej/RNTae6MdY= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8 h1:8eadJkXbwDEMNwcB5O0s5Y5eCfyuCLdvaiOIaGTrWmQ= +google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 h1:IR+hp6ypxjH24bkMfEJ0yHR21+gwPWdV+/IBrPQyn3k= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8/go.mod h1:UCOku4NytXMJuLQE5VuqA5lX3PcHCBo8pxNyvkf4xBs= +google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= +google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..e54a45a --- /dev/null +++ b/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "github.com/hasura/ndc-rest/rest" + "github.com/hasura/ndc-sdk-go/connector" +) + +// Start the connector server at http://localhost:8080 +// +// go run . serve +// +// See [NDC Go SDK] for more information. +// +// [NDC Go SDK]: https://github.com/hasura/ndc-sdk-go +func main() { + if err := rest.Start[rest.Configuration, rest.State]( + rest.NewRESTConnector(), + connector.WithMetricsPrefix("ndc_rest"), + connector.WithDefaultServiceName("ndc_rest"), + ); err != nil { + panic(err) + } +} diff --git a/rest/cli.go b/rest/cli.go new file mode 100644 index 0000000..d9591cb --- /dev/null +++ b/rest/cli.go @@ -0,0 +1,44 @@ +package rest + +import ( + "context" + "log/slog" + "os" + "strings" + + "github.com/hasura/ndc-rest-schema/command" + "github.com/hasura/ndc-sdk-go/connector" + "github.com/lmittmann/tint" +) + +// CLI extends the NDC SDK with custom commands +type CLI struct { + connector.ServeCLI + Convert command.ConvertCommandArguments `cmd:"" help:"Convert API spec to NDC schema. For example:\n ndc-rest-schema convert -f petstore.yaml -o petstore.json"` +} + +// Execute executes custom commands +func (c CLI) Execute(ctx context.Context, cmd string) error { + switch cmd { + case "convert": + var logLevel slog.Level + err := logLevel.UnmarshalText([]byte(strings.ToUpper(c.LogLevel))) + if err != nil { + return err + } + logger := slog.New(tint.NewHandler(os.Stderr, &tint.Options{ + Level: logLevel, + TimeFormat: "15:04", + })) + command.ConvertToNDCSchema(&c.Convert, logger) + return nil + default: + return c.ServeCLI.Execute(ctx, cmd) + } +} + +// Start wrap the connector.Start function with custom CLI +func Start[Configuration, State any](restConnector connector.Connector[Configuration, State], options ...connector.ServeOption) error { + var cli CLI + return connector.StartCustom[Configuration, State](&cli, restConnector, options...) +} diff --git a/rest/client.go b/rest/client.go new file mode 100644 index 0000000..532cd07 --- /dev/null +++ b/rest/client.go @@ -0,0 +1,168 @@ +package rest + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "log/slog" + "net/http" + "strings" + "time" + + rest "github.com/hasura/ndc-rest-schema/schema" + "github.com/hasura/ndc-sdk-go/connector" + "github.com/hasura/ndc-sdk-go/schema" + "github.com/hasura/ndc-sdk-go/utils" +) + +// Doer abstracts a HTTP client with Do method +type Doer interface { + Do(req *http.Request) (*http.Response, error) +} + +type httpClient struct { + Client Doer +} + +func createHTTPClient(client Doer) *httpClient { + return &httpClient{ + Client: client, + } +} + +// Send creates and executes the request and evaluate response selection +func (client *httpClient) Send(ctx context.Context, rawRequest *rest.Request, headers http.Header, data any, selection schema.NestedField) (any, error) { + timeout := defaultTimeout + if rawRequest.Timeout > 0 { + timeout = rawRequest.Timeout + } + + ctxR, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second) + defer cancel() + + logger := connector.GetLogger(ctx) + request, err := createRequest(ctxR, rawRequest, headers, data) + if err != nil { + return nil, err + } + + resp, err := client.Client.Do(request) + if err != nil { + return nil, schema.NewConnectorError(http.StatusInternalServerError, err.Error(), nil) + } + if logger.Enabled(ctx, slog.LevelDebug) { + logAttrs := []any{ + slog.String("request_url", request.URL.String()), + slog.String("request_method", request.Method), + slog.Any("request_headers", request.Header), + slog.Any("request_body", data), + slog.Int("http_status", resp.StatusCode), + slog.Any("response_headers", resp.Header), + } + if resp.Body != nil { + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, schema.NewConnectorError(http.StatusInternalServerError, err.Error(), nil) + } + logAttrs = append(logAttrs, slog.String("response_body", string(respBody))) + resp.Body = io.NopCloser(bytes.NewBuffer(respBody)) + } + logger.Debug("sent request to remote server", logAttrs...) + } + + return evalHTTPResponse(resp, selection) +} + +func createRequest(ctx context.Context, rawRequest *rest.Request, headers http.Header, data any) (*http.Request, error) { + contentType := headers.Get(contentTypeHeader) + if contentType == "" { + contentType = contentTypeJSON + } + + var body io.Reader + if data != nil { + switch contentType { + case contentTypeJSON: + bodyBytes, err := json.Marshal(data) + if err != nil { + return nil, err + } + body = bytes.NewBuffer(bodyBytes) + default: + return nil, fmt.Errorf("unsupported content type %s", contentType) + } + } + + request, err := http.NewRequestWithContext(ctx, strings.ToUpper(rawRequest.Method), rawRequest.URL, body) + if err != nil { + return nil, err + } + for key, header := range headers { + request.Header[key] = header + } + if request.Header.Get("accept") == "" { + request.Header.Set("Accept", contentTypeJSON) + } + + return request, nil +} + +func evalHTTPResponse(resp *http.Response, selection schema.NestedField) (any, error) { + contentType := parseContentType(resp.Header.Get(contentTypeHeader)) + if resp.StatusCode >= 400 { + var respBody []byte + if resp.Body != nil { + var err error + respBody, err = io.ReadAll(resp.Body) + + if err != nil { + return nil, schema.NewConnectorError(http.StatusInternalServerError, resp.Status, map[string]any{ + "error": err, + }) + } + } + + return nil, schema.NewConnectorError(resp.StatusCode, resp.Status, map[string]any{ + "error": string(respBody), + }) + } + + if resp.StatusCode == http.StatusNoContent { + return true, nil + } + + if resp.Body == nil { + return nil, nil + } + + switch contentType { + case "text/plain", "text/html": + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, schema.NewConnectorError(http.StatusInternalServerError, err.Error(), nil) + } + return string(respBody), nil + case contentTypeJSON: + var result any + if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { + return nil, schema.NewConnectorError(http.StatusInternalServerError, err.Error(), nil) + } + if selection == nil { + return result, nil + } + + return utils.EvalNestedColumnFields(selection, result) + default: + return nil, fmt.Errorf("unsupported content type %s", contentType) + } +} + +func parseContentType(input string) string { + if input == "" { + return "" + } + parts := strings.Split(input, ";") + return strings.TrimSpace(parts[0]) +} diff --git a/rest/connector.go b/rest/connector.go new file mode 100644 index 0000000..f2763a2 --- /dev/null +++ b/rest/connector.go @@ -0,0 +1,147 @@ +package rest + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "os" + + rest "github.com/hasura/ndc-rest-schema/schema" + "github.com/hasura/ndc-sdk-go/connector" + "github.com/hasura/ndc-sdk-go/schema" + "gopkg.in/yaml.v3" +) + +// RESTConnector implements the SDK interface of NDC specification +type RESTConnector struct { + capabilities *schema.RawCapabilitiesResponse + schema *schema.RawSchemaResponse + functions map[string]rest.RESTFunctionInfo + procedures map[string]rest.RESTProcedureInfo + client *httpClient +} + +// NewRESTConnector creates a REST connector instance +func NewRESTConnector(opts ...Option) *RESTConnector { + for _, opt := range opts { + opt(&defaultOptions) + } + + return &RESTConnector{ + client: createHTTPClient(defaultOptions.client), + } +} + +// ParseConfiguration validates the configuration files provided by the user, returning a validated 'Configuration', +// or throwing an error to prevents Connector startup. +func (c *RESTConnector) ParseConfiguration(ctx context.Context, configurationDir string) (*Configuration, error) { + + restCapabilities := schema.CapabilitiesResponse{ + Version: "0.1.0", + Capabilities: schema.Capabilities{ + Query: schema.QueryCapabilities{ + Variables: schema.LeafCapability{}, + }, + Mutation: schema.MutationCapabilities{}, + }, + } + rawCapabilities, err := json.Marshal(restCapabilities) + if err != nil { + return nil, fmt.Errorf("failed to encode capabilities: %s", err) + } + c.capabilities = schema.NewRawCapabilitiesResponseUnsafe(rawCapabilities) + + config, err := parseConfiguration(configurationDir) + if err != nil { + return nil, err + } + + logger := connector.GetLogger(ctx) + schemas, errs := buildSchemaFiles(configurationDir, config.Files, logger) + if len(errs) > 0 { + printSchemaValidationError(logger, errs) + return nil, errors.New("failed to build NDC REST schema") + } + + if errs := c.applyNDCRestSchemas(schemas); len(errs) > 0 { + printSchemaValidationError(logger, errs) + return nil, errors.New("failed to validate NDC REST schema") + } + + return config, nil +} + +// TryInitState initializes the connector's in-memory state. +// +// For example, any connection pools, prepared queries, +// or other managed resources would be allocated here. +// +// In addition, this function should register any +// connector-specific metrics with the metrics registry. +func (c *RESTConnector) TryInitState(ctx context.Context, configuration *Configuration, metrics *connector.TelemetryState) (*State, error) { + return &State{}, nil +} + +// HealthCheck checks the health of the connector. +// +// For example, this function should check that the connector +// is able to reach its data source over the network. +// +// Should throw if the check fails, else resolve. +func (c *RESTConnector) HealthCheck(ctx context.Context, configuration *Configuration, state *State) error { + return nil +} + +// GetCapabilities get the connector's capabilities. +func (c *RESTConnector) GetCapabilities(configuration *Configuration) schema.CapabilitiesResponseMarshaler { + return c.capabilities +} + +// QueryExplain explains a query by creating an execution plan. +func (c *RESTConnector) QueryExplain(ctx context.Context, configuration *Configuration, state *State, request *schema.QueryRequest) (*schema.ExplainResponse, error) { + return nil, schema.NotSupportedError("query explain has not been supported yet", nil) +} + +// MutationExplain explains a mutation by creating an execution plan. +func (c *RESTConnector) MutationExplain(ctx context.Context, configuration *Configuration, state *State, request *schema.MutationRequest) (*schema.ExplainResponse, error) { + return nil, schema.NotSupportedError("mutation explain has not been supported yet", nil) +} + +func parseConfiguration(configurationDir string) (*Configuration, error) { + var config Configuration + jsonBytes, err := os.ReadFile(fmt.Sprintf("%s/config.json", configurationDir)) + if err == nil { + if err = json.Unmarshal(jsonBytes, &config); err != nil { + return nil, err + } + return &config, nil + } + + if !os.IsNotExist(err) { + return nil, err + } + + // try to read and parse yaml file + yamlBytes, err := os.ReadFile(fmt.Sprintf("%s/config.yaml", configurationDir)) + if err != nil { + if !os.IsNotExist(err) { + return nil, err + } + yamlBytes, err = os.ReadFile(fmt.Sprintf("%s/config.yml", configurationDir)) + } + + if err != nil { + if os.IsNotExist(err) { + return nil, fmt.Errorf("the config.{json,yaml,yml} file does not exist at %s", configurationDir) + } else { + return nil, err + } + } + + if err = yaml.Unmarshal(yamlBytes, &config); err != nil { + return nil, err + } + + return &config, nil +} diff --git a/rest/connector_test.go b/rest/connector_test.go new file mode 100644 index 0000000..d576c2b --- /dev/null +++ b/rest/connector_test.go @@ -0,0 +1,183 @@ +package rest + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "path" + "reflect" + "strings" + "testing" + + "github.com/hasura/ndc-sdk-go/connector" + "github.com/hasura/ndc-sdk-go/schema" +) + +func TestRESTConnector(t *testing.T) { + testCases := []struct { + Name string + Dir string + }{ + { + Name: "jsonplaceholder", + Dir: "testdata/jsonplaceholder", + }, + { + Name: "jsonplaceholder", + Dir: "testdata/petstore3", + }, + } + + for _, tc := range testCases { + t.Run(tc.Name, func(t *testing.T) { + server := test_createServer(t, tc.Dir) + testServer := server.BuildTestServer() + + t.Run("capabilities", func(t *testing.T) { + filePath := path.Join(tc.Dir, "snapshots/capabilities") + rawBytes, err := os.ReadFile(filePath) + if err != nil { + if !os.IsNotExist(err) { + t.Errorf("failed to read %s: %s", filePath, err) + t.FailNow() + } + return + } + + var capabilities schema.CapabilitiesResponse + assertNoError(t, json.Unmarshal(rawBytes, &capabilities)) + resp, err := http.Get(fmt.Sprintf("%s/capabilities", testServer.URL)) + assertNoError(t, err) + assertHTTPResponse(t, resp, http.StatusOK, capabilities) + }) + + t.Run("schema", func(t *testing.T) { + filePath := path.Join(tc.Dir, "snapshots/schema") + rawBytes, err := os.ReadFile(filePath) + if err != nil { + if !os.IsNotExist(err) { + t.Errorf("failed to read %s: %s", filePath, err) + t.FailNow() + } + return + } + + var expected schema.SchemaResponse + assertNoError(t, json.Unmarshal(rawBytes, &expected)) + resp, err := http.Get(fmt.Sprintf("%s/schema", testServer.URL)) + assertNoError(t, err) + assertHTTPResponse(t, resp, http.StatusOK, expected) + }) + + assertNdcOperations(t, path.Join(tc.Dir, "query"), fmt.Sprintf("%s/query", testServer.URL)) + assertNdcOperations(t, path.Join(tc.Dir, "mutation"), fmt.Sprintf("%s/mutation", testServer.URL)) + }) + } +} + +func TestRESTConnector_configurationFailure(t *testing.T) { + c := NewRESTConnector() + _, err := c.ParseConfiguration(context.Background(), "") + assertError(t, err, "the config.{json,yaml,yml} file does not exist at") +} + +func assertNdcOperations(t *testing.T, dir string, targetURL string) { + queryFiles, err := os.ReadDir(dir) + if err != nil { + if !os.IsNotExist(err) { + t.Errorf("failed to read %s: %s", dir, err) + t.FailNow() + } + return + } + for _, entry := range queryFiles { + if !entry.IsDir() { + continue + } + t.Run(entry.Name(), func(t *testing.T) { + requestBytes, err := os.ReadFile(path.Join(dir, entry.Name(), "request.json")) + assertNoError(t, err) + expectedBytes, err := os.ReadFile(path.Join(dir, entry.Name(), "expected.json")) + assertNoError(t, err) + + var expected any + assertNoError(t, json.Unmarshal(expectedBytes, &expected)) + resp, err := http.Post(targetURL, "application/json", bytes.NewBuffer(requestBytes)) + assertNoError(t, err) + assertHTTPResponse(t, resp, http.StatusOK, expected) + }) + } +} + +func test_createServer(t *testing.T, dir string) *connector.Server[Configuration, State] { + c := NewRESTConnector() + server, err := connector.NewServer(c, &connector.ServerOptions{ + Configuration: dir, + }) + if err != nil { + t.Errorf("failed to start server: %s", err) + t.FailNow() + } + + return server +} + +func assertNoError(t *testing.T, err error) { + if err != nil { + t.Errorf("expected no error, got: %s", err) + t.FailNow() + } +} + +func assertError(t *testing.T, err error, message string) { + if err == nil { + t.Error("expected error, got nil") + t.FailNow() + } else if !strings.Contains(err.Error(), message) { + t.Errorf("expected error with content: %s, got: %s", err.Error(), message) + t.FailNow() + } +} + +func assertDeepEqual(t *testing.T, expected any, reality any, msgs ...string) { + if reflect.DeepEqual(expected, reality) { + return + } + + expectedJson, _ := json.Marshal(expected) + realityJson, _ := json.Marshal(reality) + + var expected1, reality1 any + assertNoError(t, json.Unmarshal(expectedJson, &expected1)) + assertNoError(t, json.Unmarshal(realityJson, &reality1)) + + if !reflect.DeepEqual(expected1, reality1) { + t.Errorf("%s: not equal.\nexpected: %s\ngot : %s", strings.Join(msgs, " "), string(expectedJson), string(realityJson)) + t.FailNow() + } +} + +func assertHTTPResponse[B any](t *testing.T, res *http.Response, statusCode int, expectedBody B) { + bodyBytes, err := io.ReadAll(res.Body) + if err != nil { + t.Error("failed to read response body") + t.FailNow() + } + + if res.StatusCode != statusCode { + t.Errorf("expected status %d, got %d. Body: %s", statusCode, res.StatusCode, string(bodyBytes)) + t.FailNow() + } + + var body B + if err = json.Unmarshal(bodyBytes, &body); err != nil { + t.Errorf("failed to decode json body, got error: %s; body: %s", err, string(bodyBytes)) + t.FailNow() + } + + assertDeepEqual(t, body, expectedBody) +} diff --git a/rest/mutation.go b/rest/mutation.go new file mode 100644 index 0000000..6312161 --- /dev/null +++ b/rest/mutation.go @@ -0,0 +1,72 @@ +package rest + +import ( + "context" + "encoding/json" + "fmt" + + rest "github.com/hasura/ndc-rest-schema/schema" + "github.com/hasura/ndc-sdk-go/schema" +) + +// Mutation executes a mutation. +func (c *RESTConnector) Mutation(ctx context.Context, configuration *Configuration, state *State, request *schema.MutationRequest) (*schema.MutationResponse, error) { + operationResults := make([]schema.MutationOperationResults, len(request.Operations)) + + for i, operation := range request.Operations { + switch operation.Type { + case schema.MutationOperationProcedure: + result, err := c.execProcedure(ctx, &operation) + if err != nil { + return nil, err + } + operationResults[i] = result + default: + return nil, schema.BadRequestError(fmt.Sprintf("invalid operation type: %s", operation.Type), nil) + } + } + + return &schema.MutationResponse{ + OperationResults: operationResults, + }, nil +} + +func (c *RESTConnector) execProcedure(ctx context.Context, operation *schema.MutationOperation) (schema.MutationOperationResults, error) { + + procedure := c.getProcedure(operation.Name) + if procedure == nil { + return nil, schema.BadRequestError(fmt.Sprintf("unsupported procedure operation: %s", operation.Name), nil) + } + + // 1. resolve arguments, evaluate URL and query parameters + var rawArgs map[string]any + if err := json.Unmarshal(operation.Arguments, &rawArgs); err != nil { + return nil, schema.BadRequestError("failed to decode arguments", map[string]any{ + "cause": err.Error(), + }) + } + + endpoint, headers, err := evalURLAndHeaderParameters(procedure.Request, procedure.Arguments, rawArgs) + if err != nil { + return nil, schema.BadRequestError("failed to evaluate URL and Headers from parameters", map[string]any{ + "cause": err.Error(), + }) + } + + // 2. create and execute request + // 3. evaluate response selection + rawRequest := procedure.Request.Clone() + rawRequest.URL = endpoint + result, err := c.client.Send(ctx, rawRequest, headers, rawArgs["body"], operation.Fields) + if err != nil { + return nil, err + } + return schema.NewProcedureResult(result).Encode(), nil +} + +func (c *RESTConnector) getProcedure(key string) *rest.RESTProcedureInfo { + if item, ok := c.procedures[key]; ok { + return &item + } + return nil +} diff --git a/rest/query.go b/rest/query.go new file mode 100644 index 0000000..aad5db8 --- /dev/null +++ b/rest/query.go @@ -0,0 +1,154 @@ +package rest + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "net/url" + "slices" + "strings" + + rest "github.com/hasura/ndc-rest-schema/schema" + "github.com/hasura/ndc-sdk-go/schema" + "github.com/hasura/ndc-sdk-go/utils" +) + +// Query executes a query. +func (c *RESTConnector) Query(ctx context.Context, configuration *Configuration, state *State, request *schema.QueryRequest) (schema.QueryResponse, error) { + valueField, err := utils.EvalFunctionSelectionFieldValue(request) + if err != nil { + return nil, schema.BadRequestError(err.Error(), nil) + } + requestVars := request.Variables + if len(requestVars) == 0 { + requestVars = []schema.QueryRequestVariablesElem{make(schema.QueryRequestVariablesElem)} + } + + rowSets := make([]schema.RowSet, len(requestVars)) + for i, requestVar := range requestVars { + result, err := c.execQuery(ctx, request, valueField, requestVar) + if err != nil { + return nil, err + } + rowSets[i] = schema.RowSet{ + Aggregates: schema.RowSetAggregates{}, + Rows: []map[string]any{ + { + "__value": result, + }, + }, + } + } + + return rowSets, nil +} + +func (c *RESTConnector) execQuery(ctx context.Context, request *schema.QueryRequest, queryFields schema.NestedField, variables map[string]any) (any, error) { + + function := c.getFunction(request.Collection) + if function == nil { + return nil, schema.BadRequestError(fmt.Sprintf("unsupported query: %s", request.Collection), nil) + } + + // 1. resolve arguments, evaluate URL and query parameters + rawArgs, err := utils.ResolveArgumentVariables(request.Arguments, variables) + if err != nil { + return nil, schema.BadRequestError("failed to resolve argument variables", map[string]any{ + "cause": err.Error(), + }) + } + + endpoint, headers, err := evalURLAndHeaderParameters(function.Request, function.Arguments, rawArgs) + if err != nil { + return nil, schema.BadRequestError("failed to evaluate URL and Headers from parameters", map[string]any{ + "cause": err.Error(), + }) + } + // 2. create and execute request + // 3. evaluate response selection + rawRequest := function.Request.Clone() + rawRequest.URL = endpoint + + return c.client.Send(ctx, rawRequest, headers, nil, queryFields) +} + +func (c *RESTConnector) getFunction(key string) *rest.RESTFunctionInfo { + if item, ok := c.functions[key]; ok { + return &item + } + return nil +} + +func evalURLAndHeaderParameters(request *rest.Request, argumentsSchema map[string]schema.ArgumentInfo, arguments map[string]any) (string, http.Header, error) { + endpoint, err := url.Parse(request.URL) + if err != nil { + return "", nil, err + } + headers := http.Header{} + for k, h := range request.Headers { + headers.Add(k, h) + } + + for _, param := range request.Parameters { + argSchema, schemaOk := argumentsSchema[param.Name] + value, ok := arguments[param.Name] + + if !schemaOk || !ok || utils.IsNil(value) { + if param.Required { + return "", nil, fmt.Errorf("parameter %s is required", param.Name) + } + } else if err := evalURLAndHeaderParameterBySchema(endpoint, &headers, ¶m, argSchema.Type, value); err != nil { + return "", nil, err + } + } + return endpoint.String(), headers, nil +} + +func evalURLAndHeaderParameterBySchema(endpoint *url.URL, header *http.Header, param *rest.RequestParameter, argumentType schema.Type, value any) error { + if utils.IsNil(value) { + return nil + } + + var valueStr string + switch arg := argumentType.Interface().(type) { + case *schema.NamedType: + switch arg.Name { + case "Boolean": + valueStr = fmt.Sprintf("%t", value) + case "Int", "Float", "String": + valueStr = fmt.Sprint(value) + default: + b, err := json.Marshal(value) + if err != nil { + return err + } + valueStr = string(b) + } + case *schema.NullableType: + return evalURLAndHeaderParameterBySchema(endpoint, header, param, arg.UnderlyingType, value) + case *schema.ArrayType: + if !slices.Contains([]rest.ParameterLocation{rest.InHeader, rest.InQuery}, param.In) { + return fmt.Errorf("cannot evaluate array parameter to %s", param.In) + } + + // TODO: evaluate array with reflection + b, err := json.Marshal(value) + if err != nil { + return err + } + valueStr = string(b) + } + + switch param.In { + case rest.InHeader: + // TODO: set header + case rest.InQuery: + q := endpoint.Query() + q.Add(param.Name, valueStr) + endpoint.RawQuery = q.Encode() + case rest.InPath: + endpoint.Path = strings.ReplaceAll(endpoint.Path, fmt.Sprintf("{%s}", param.Name), valueStr) + } + return nil +} diff --git a/rest/schema.go b/rest/schema.go new file mode 100644 index 0000000..0cfef09 --- /dev/null +++ b/rest/schema.go @@ -0,0 +1,232 @@ +package rest + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "log/slog" + "path" + "strings" + + "github.com/hasura/ndc-rest-schema/openapi" + rest "github.com/hasura/ndc-rest-schema/schema" + "github.com/hasura/ndc-rest-schema/utils" + "github.com/hasura/ndc-sdk-go/schema" + "gopkg.in/yaml.v3" +) + +// GetSchema gets the connector's schema. +func (c *RESTConnector) GetSchema(ctx context.Context, configuration *Configuration, _ *State) (schema.SchemaResponseMarshaler, error) { + return c.schema, nil +} + +// build NDC REST schema from file list +func buildSchemaFiles(configDir string, files []SchemaFile, logger *slog.Logger) (map[string]*rest.NDCRestSchema, map[string][]string) { + schemas := make(map[string]*rest.NDCRestSchema) + errors := make(map[string][]string) + for _, file := range files { + var errs []string + schemaOutput, err := buildSchemaFile(configDir, &file, logger) + if err != nil { + errs = append(errs, err.Error()) + } + if schemaOutput != nil { + schemas[file.Path] = schemaOutput + } + if len(errs) > 0 { + errors[file.Path] = errs + } + } + + return schemas, errors +} + +func buildSchemaFile(configDir string, conf *SchemaFile, logger *slog.Logger) (*rest.NDCRestSchema, error) { + if conf.Path == "" { + return nil, errors.New("file path is empty") + } + + filePath := conf.Path + if !strings.HasPrefix(conf.Path, "/") && !strings.HasPrefix(conf.Path, "http") { + filePath = path.Join(configDir, conf.Path) + } + rawBytes, err := utils.ReadFileFromPath(filePath) + if err != nil { + return nil, err + } + switch conf.Spec { + case rest.NDCSpec: + var result rest.NDCRestSchema + fileFormat, err := rest.ParseSchemaFileFormat(conf.Path) + if err != nil { + return nil, err + } + switch fileFormat { + case rest.SchemaFileJSON: + if err := json.Unmarshal(rawBytes, &result); err != nil { + return nil, err + } + return &result, nil + case rest.SchemaFileYAML: + if err := yaml.Unmarshal(rawBytes, &result); err != nil { + return nil, err + } + return &result, nil + default: + return nil, fmt.Errorf("invalid file format: %s", fileFormat) + } + case rest.OpenAPIv2Spec: + result, errs := openapi.OpenAPIv2ToNDCSchema(rawBytes, &openapi.ConvertOptions{ + MethodAlias: conf.MethodAlias, + TrimPrefix: conf.TrimPrefix, + }) + if result != nil { + if len(errs) > 0 { + logger.Warn("some errors happened when parsing OpenAPI", slog.Any("errors", errs)) + } + return result, nil + } + return nil, errors.Join(errs...) + case rest.OpenAPIv3Spec: + result, errs := openapi.OpenAPIv3ToNDCSchema(rawBytes, &openapi.ConvertOptions{ + MethodAlias: conf.MethodAlias, + TrimPrefix: conf.TrimPrefix, + }) + if result != nil { + if len(errs) > 0 { + logger.Warn("some errors happened when parsing OpenAPI", slog.Any("errors", errs)) + } + return result, nil + } + return nil, errors.Join(errs...) + default: + return nil, fmt.Errorf("invalid configuration spec: %s", conf.Spec) + } +} + +func (c *RESTConnector) applyNDCRestSchemas(schemas map[string]*rest.NDCRestSchema) map[string][]string { + ndcSchema := &schema.SchemaResponse{ + Collections: []schema.CollectionInfo{}, + ScalarTypes: make(schema.SchemaResponseScalarTypes), + ObjectTypes: make(schema.SchemaResponseObjectTypes), + } + functions := map[string]rest.RESTFunctionInfo{} + procedures := map[string]rest.RESTProcedureInfo{} + errors := make(map[string][]string) + + for key, item := range schemas { + var host string + var errs []string + timeout := defaultTimeout + + if item.Settings != nil { + if item.Settings.Timeout > 0 { + timeout = item.Settings.Timeout + } + host = item.Settings.URL + } + + for name, scalar := range item.ScalarTypes { + ndcSchema.ScalarTypes[name] = scalar + } + for name, object := range item.ObjectTypes { + ndcSchema.ObjectTypes[name] = object + } + ndcSchema.Collections = append(ndcSchema.Collections, item.Collections...) + + var functionSchemas []schema.FunctionInfo + var procedureSchemas []schema.ProcedureInfo + for _, fnItem := range item.Functions { + if fnItem.Request == nil || fnItem.Request.URL == "" { + continue + } + req, err := validateRequestSchema(fnItem.Request, host, "get", timeout) + if err != nil { + errs = append(errs, fmt.Sprintf("function %s: %s", fnItem.Name, err)) + continue + } + fn := rest.RESTFunctionInfo{ + Request: req, + FunctionInfo: fnItem.FunctionInfo, + } + functions[fnItem.Name] = fn + functionSchemas = append(functionSchemas, fn.FunctionInfo) + } + + for _, procItem := range item.Procedures { + if procItem.Request == nil || procItem.Request.URL == "" { + continue + } + req, err := validateRequestSchema(procItem.Request, host, "", timeout) + if err != nil { + errs = append(errs, fmt.Sprintf("procedure %s: %s", procItem.Name, err)) + continue + } + procedures[procItem.Name] = rest.RESTProcedureInfo{ + Request: req, + ProcedureInfo: procItem.ProcedureInfo, + } + procedureSchemas = append(procedureSchemas, procItem.ProcedureInfo) + } + + if len(errs) > 0 { + errors[key] = errs + continue + } + ndcSchema.Functions = append(ndcSchema.Functions, functionSchemas...) + ndcSchema.Procedures = append(ndcSchema.Procedures, procedureSchemas...) + } + + schemaBytes, err := json.Marshal(ndcSchema) + if err != nil { + errors["schema"] = []string{err.Error()} + } + + if len(errors) > 0 { + return errors + } + + c.schema = schema.NewRawSchemaResponseUnsafe(schemaBytes) + c.functions = functions + c.procedures = procedures + return nil +} + +func validateRequestSchema(req *rest.Request, host string, defaultMethod string, defTimeout uint) (*rest.Request, error) { + endpoint := req.URL + if !strings.HasPrefix(endpoint, "http") && host != "" { + endpoint = fmt.Sprintf("%s%s", host, req.URL) + } + if !strings.HasPrefix(endpoint, "http") { + return nil, fmt.Errorf("the URL is invalid: %s", endpoint) + } + + if req.Method == "" { + if defaultMethod == "" { + return nil, fmt.Errorf("the HTTP method is required") + } + req.Method = defaultMethod + } + + if req.Type == "" { + req.Type = rest.RequestTypeREST + } + timeout := req.Timeout + if timeout == 0 { + timeout = defTimeout + } + + return &rest.Request{ + URL: endpoint, + Method: req.Method, + Type: req.Type, + Headers: req.Headers, + Parameters: req.Parameters, + Timeout: timeout, + }, nil +} + +func printSchemaValidationError(logger *slog.Logger, errors map[string][]string) { + logger.Error("errors happen when validating NDC REST schemas", slog.Any("errors", errors)) +} diff --git a/rest/testdata/jsonplaceholder/config.yaml b/rest/testdata/jsonplaceholder/config.yaml new file mode 100644 index 0000000..e1f048d --- /dev/null +++ b/rest/testdata/jsonplaceholder/config.yaml @@ -0,0 +1,3 @@ +files: + - path: swagger.json + spec: openapi2 diff --git a/rest/testdata/jsonplaceholder/mutation/create_post/expected.json b/rest/testdata/jsonplaceholder/mutation/create_post/expected.json new file mode 100644 index 0000000..76ad85d --- /dev/null +++ b/rest/testdata/jsonplaceholder/mutation/create_post/expected.json @@ -0,0 +1,13 @@ +{ + "operation_results": [ + { + "result": { + "id": 101, + "title": "Hello world", + "userId": 10, + "body": "A test post" + }, + "type": "procedure" + } + ] +} diff --git a/rest/testdata/jsonplaceholder/mutation/create_post/request.json b/rest/testdata/jsonplaceholder/mutation/create_post/request.json new file mode 100644 index 0000000..137f7f4 --- /dev/null +++ b/rest/testdata/jsonplaceholder/mutation/create_post/request.json @@ -0,0 +1,26 @@ +{ + "operations": [ + { + "type": "procedure", + "name": "createPost", + "arguments": { + "body": { + "id": 101, + "title": "Hello world", + "userId": 10, + "body": "A test post" + } + }, + "fields": { + "type": "object", + "fields": { + "id": { "type": "column", "column": "id", "fields": null }, + "title": { "type": "column", "column": "title", "fields": null }, + "userId": { "type": "column", "column": "userId", "fields": null }, + "body": { "type": "column", "column": "body", "fields": null } + } + } + } + ], + "collection_relationships": {} +} diff --git a/rest/testdata/jsonplaceholder/mutation/delete_post/expected.json b/rest/testdata/jsonplaceholder/mutation/delete_post/expected.json new file mode 100644 index 0000000..4832daf --- /dev/null +++ b/rest/testdata/jsonplaceholder/mutation/delete_post/expected.json @@ -0,0 +1 @@ +{ "operation_results": [{ "result": {}, "type": "procedure" }] } diff --git a/rest/testdata/jsonplaceholder/mutation/delete_post/request.json b/rest/testdata/jsonplaceholder/mutation/delete_post/request.json new file mode 100644 index 0000000..c99b562 --- /dev/null +++ b/rest/testdata/jsonplaceholder/mutation/delete_post/request.json @@ -0,0 +1,6 @@ +{ + "operations": [ + { "type": "procedure", "name": "deletePostById", "arguments": { "id": 10 } } + ], + "collection_relationships": {} +} diff --git a/rest/testdata/jsonplaceholder/query/get_albums/expected.json b/rest/testdata/jsonplaceholder/query/get_albums/expected.json new file mode 100644 index 0000000..837fdb9 --- /dev/null +++ b/rest/testdata/jsonplaceholder/query/get_albums/expected.json @@ -0,0 +1,9 @@ +[ + { + "rows": [ + { + "__value": [{ "id": 1, "userId": 1 }] + } + ] + } +] diff --git a/rest/testdata/jsonplaceholder/query/get_albums/request.json b/rest/testdata/jsonplaceholder/query/get_albums/request.json new file mode 100644 index 0000000..f3a5e21 --- /dev/null +++ b/rest/testdata/jsonplaceholder/query/get_albums/request.json @@ -0,0 +1,26 @@ +{ + "collection": "getAlbums", + "query": { + "fields": { + "__value": { + "type": "column", + "column": "__value", + "fields": { + "type": "array", + "fields": { + "type": "object", + "fields": { + "id": { "type": "column", "column": "id", "fields": null }, + "userId": { "type": "column", "column": "userId", "fields": null } + } + } + } + } + } + }, + "arguments": { + "id": { "type": "literal", "value": 1 }, + "userId": { "type": "literal", "value": 1 } + }, + "collection_relationships": {} +} diff --git a/rest/testdata/jsonplaceholder/query/get_user/expected.json b/rest/testdata/jsonplaceholder/query/get_user/expected.json new file mode 100644 index 0000000..478c3fa --- /dev/null +++ b/rest/testdata/jsonplaceholder/query/get_user/expected.json @@ -0,0 +1,28 @@ +[ + { + "rows": [ + { + "__value": { + "address": { + "city": "Gwenborough", + "geo": { "lat": "-37.3159", "lng": "81.1496" }, + "street": "Kulas Light", + "suite": "Apt. 556", + "zipcode": "92998-3874" + }, + "company": { + "bs": "harness real-time e-markets", + "catchPhrase": "Multi-layered client-server neural-net", + "name": "Romaguera-Crona" + }, + "email": "Sincere@april.biz", + "id": 1, + "name": "Leanne Graham", + "phone": "1-770-736-8031 x56442", + "username": "Bret", + "website": "hildegard.org" + } + } + ] + } +] diff --git a/rest/testdata/jsonplaceholder/query/get_user/request.json b/rest/testdata/jsonplaceholder/query/get_user/request.json new file mode 100644 index 0000000..79f26a6 --- /dev/null +++ b/rest/testdata/jsonplaceholder/query/get_user/request.json @@ -0,0 +1,96 @@ +{ + "collection": "getUser", + "query": { + "fields": { + "__value": { + "type": "column", + "column": "__value", + "fields": { + "type": "object", + "fields": { + "id": { "type": "column", "column": "id", "fields": null }, + "website": { + "type": "column", + "column": "website", + "fields": null + }, + "username": { + "type": "column", + "column": "username", + "fields": null + }, + "phone": { "type": "column", "column": "phone", "fields": null }, + "name": { "type": "column", "column": "name", "fields": null }, + "email": { "type": "column", "column": "email", "fields": null }, + "address": { + "type": "column", + "column": "address", + "fields": { + "type": "object", + "fields": { + "city": { + "type": "column", + "column": "city", + "fields": null + }, + "geo": { + "type": "column", + "column": "geo", + "fields": { + "type": "object", + "fields": { + "lat": { + "type": "column", + "column": "lat", + "fields": null + }, + "lng": { + "type": "column", + "column": "lng", + "fields": null + } + } + } + }, + "suite": { + "type": "column", + "column": "suite", + "fields": null + }, + "street": { + "type": "column", + "column": "street", + "fields": null + }, + "zipcode": { + "type": "column", + "column": "zipcode", + "fields": null + } + } + } + }, + "company": { + "type": "column", + "column": "company", + "fields": { + "type": "object", + "fields": { + "bs": { "type": "column", "column": "bs", "fields": null }, + "catchPhrase": { + "type": "column", + "column": "catchPhrase", + "fields": null + }, + "name": { "type": "column", "column": "name", "fields": null } + } + } + } + } + } + } + } + }, + "arguments": { "id": { "type": "literal", "value": 1 } }, + "collection_relationships": {} +} diff --git a/rest/testdata/jsonplaceholder/snapshots/capabilities b/rest/testdata/jsonplaceholder/snapshots/capabilities new file mode 100644 index 0000000..70961cd --- /dev/null +++ b/rest/testdata/jsonplaceholder/snapshots/capabilities @@ -0,0 +1,9 @@ +{ + "version": "0.1.0", + "capabilities": { + "query": { + "variables": {} + }, + "mutation": {} + } +} \ No newline at end of file diff --git a/rest/testdata/jsonplaceholder/snapshots/schema b/rest/testdata/jsonplaceholder/snapshots/schema new file mode 100644 index 0000000..f94fd62 --- /dev/null +++ b/rest/testdata/jsonplaceholder/snapshots/schema @@ -0,0 +1,839 @@ +{ + "scalar_types": { + "Boolean": { + "aggregate_functions": {}, + "comparison_operators": {} + }, + "Int": { + "aggregate_functions": {}, + "comparison_operators": {} + }, + "NotFoundError": { + "aggregate_functions": {}, + "comparison_operators": {} + }, + "String": { + "aggregate_functions": {}, + "comparison_operators": {} + } + }, + "object_types": { + "Album": { + "fields": { + "id": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "title": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "userId": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + } + }, + "Comment": { + "fields": { + "body": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "email": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "id": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "name": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "postId": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + } + }, + "Photo": { + "fields": { + "albumId": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "id": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "thumbnailUrl": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "title": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "url": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + } + } + }, + "Post": { + "fields": { + "body": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "id": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "title": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "userId": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + } + }, + "Todo": { + "fields": { + "completed": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Boolean" + } + } + }, + "id": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "title": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "userId": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + } + }, + "User": { + "fields": { + "address": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "UserAddress" + } + } + }, + "company": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "UserCompany" + } + } + }, + "email": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "id": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "name": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "phone": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "username": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "website": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + } + } + }, + "UserAddress": { + "fields": { + "city": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "geo": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "UserAddressGeo" + } + } + }, + "street": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "suite": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "zipcode": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + } + } + }, + "UserAddressGeo": { + "fields": { + "lat": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "lng": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + } + } + }, + "UserCompany": { + "fields": { + "bs": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "catchPhrase": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + }, + "name": { + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "String" + } + } + } + } + } + }, + "collections": [], + "functions": [ + { + "name": "getPosts", + "description": "Get all available posts", + "arguments": { + "id": { + "description": "Filter by post ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "userId": { + "description": "Filter by user ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "Post" + } + } + }, + { + "name": "getPostById", + "description": "Get specific post", + "arguments": { + "id": { + "description": "The ID of the post to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "Post" + } + }, + { + "name": "getPostsIdComments", + "description": "Get comments for a specific post", + "arguments": { + "id": { + "description": "post id", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "Comment" + } + } + }, + { + "name": "getComments", + "description": "Get all available comments", + "arguments": { + "id": { + "description": "Filter by comment ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "postId": { + "description": "Filter by post ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "Comment" + } + } + }, + { + "name": "getComment", + "description": "Get specific comment", + "arguments": { + "id": { + "description": "The ID of the comment to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "Comment" + } + }, + { + "name": "getAlbums", + "description": "Get all available albums", + "arguments": { + "id": { + "description": "Filter by album ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "userId": { + "description": "Filter by user ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "Album" + } + } + }, + { + "name": "getAlbumsId", + "description": "Get specific album", + "arguments": { + "id": { + "description": "The ID of the album to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "Album" + } + }, + { + "name": "getAlbumsIdPhotos", + "description": "Get photos for a specific album", + "arguments": { + "id": { + "description": "post id", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "Photo" + } + } + }, + { + "name": "getPhotos", + "description": "Get all available photos", + "arguments": { + "albumId": { + "description": "Filter by album ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "id": { + "description": "Filter by photo ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "Photo" + } + } + }, + { + "name": "getPhoto", + "description": "Get specific photo", + "arguments": { + "id": { + "description": "The ID of the photo to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "Photo" + } + }, + { + "name": "getTodos", + "description": "Get all available todos", + "arguments": { + "id": { + "description": "Filter by todo ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "userId": { + "description": "Filter by user ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "Todo" + } + } + }, + { + "name": "getTodo", + "description": "Get specific todo", + "arguments": { + "id": { + "description": "The ID of the todo to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "Todo" + } + }, + { + "name": "getUsers", + "description": "Get all available users", + "arguments": { + "email": { + "description": "Filter by user email address", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + }, + "id": { + "description": "Filter by user ID", + "type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Int" + } + } + } + }, + "result_type": { + "type": "array", + "element_type": { + "type": "named", + "name": "User" + } + } + }, + { + "name": "getUser", + "description": "Get specific user", + "arguments": { + "id": { + "description": "The ID of the user to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "User" + } + } + ], + "procedures": [ + { + "name": "createPost", + "description": "Create a post", + "arguments": { + "body": { + "description": "Post object that needs to be added", + "type": { + "type": "named", + "name": "Post" + } + } + }, + "result_type": { + "type": "named", + "name": "Post" + } + }, + { + "name": "updatePostById", + "description": "Update specific post", + "arguments": { + "body": { + "description": "Post object that needs to be updated", + "type": { + "type": "named", + "name": "Post" + } + }, + "id": { + "description": "The ID of the post to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "Post" + } + }, + { + "name": "patchPostById", + "description": "patch specific post", + "arguments": { + "body": { + "description": "Post object that needs to be updated", + "type": { + "type": "named", + "name": "Post" + } + }, + "id": { + "description": "The ID of the post to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "named", + "name": "Post" + } + }, + { + "name": "deletePostById", + "description": "Delete specific post", + "arguments": { + "id": { + "description": "The ID of the post to retrieve", + "type": { + "type": "named", + "name": "Int" + } + } + }, + "result_type": { + "type": "nullable", + "underlying_type": { + "type": "named", + "name": "Boolean" + } + } + } + ] +} \ No newline at end of file diff --git a/rest/testdata/jsonplaceholder/swagger.json b/rest/testdata/jsonplaceholder/swagger.json new file mode 100644 index 0000000..a1179c4 --- /dev/null +++ b/rest/testdata/jsonplaceholder/swagger.json @@ -0,0 +1,777 @@ +{ + "swagger": "2.0", + "info": { + "description": "Fake Online REST API for Testing and Prototyping", + "version": "1.0.0", + "title": "JSON Placeholder" + }, + "host": "jsonplaceholder.typicode.com", + "tags": [ + { + "name": "posts" + }, + { + "name": "comments" + }, + { + "name": "albums" + }, + { + "name": "photos" + }, + { + "name": "todos" + }, + { + "name": "users" + } + ], + "schemes": ["https"], + "paths": { + "/posts": { + "get": { + "tags": ["posts"], + "operationId": "getPosts", + "summary": "Get all available posts", + "parameters": [ + { + "name": "id", + "in": "query", + "type": "integer", + "description": "Filter by post ID", + "required": false + }, + { + "name": "userId", + "in": "query", + "type": "integer", + "description": "Filter by user ID", + "required": false + } + ], + "produces": ["application/json"], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Post" + } + } + } + } + }, + "post": { + "tags": ["posts"], + "operationId": "createPost", + "summary": "Create a post", + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Post object that needs to be added", + "required": true, + "schema": { "$ref": "#/definitions/Post" } + } + ], + "consumes": ["application/json"], + "produces": ["application/json"], + "responses": { + "200": { + "description": "successful operation", + "schema": { "$ref": "#/definitions/Post" } + } + } + } + }, + "/posts/{id}": { + "get": { + "tags": ["posts"], + "operationId": "getPostById", + "summary": "Get specific post", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the post to retrieve", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Post" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + }, + + "put": { + "tags": ["posts"], + "operationId": "updatePostById", + "summary": "Update specific post", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the post to retrieve", + "required": true, + "type": "integer" + }, + { + "in": "body", + "name": "body", + "description": "Post object that needs to be updated", + "required": true, + "schema": { "$ref": "#/definitions/Post" } + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Post" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + }, + + "patch": { + "tags": ["posts"], + "operationId": "patchPostById", + "summary": "patch specific post", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the post to retrieve", + "required": true, + "type": "integer" + }, + { + "in": "body", + "name": "body", + "description": "Post object that needs to be updated", + "required": true, + "schema": { "$ref": "#/definitions/Post" } + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Post" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + }, + "delete": { + "tags": ["posts"], + "operationId": "deletePostById", + "summary": "Delete specific post", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the post to retrieve", + "required": true, + "type": "integer" + } + ], + "responses": { + "204": { + "description": "successful operation" + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + }, + "/posts/{id}/comments": { + "get": { + "tags": ["posts"], + "summary": "Get comments for a specific post", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "post id", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Comment" + } + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + }, + "/comments": { + "get": { + "tags": ["comments"], + "operationId": "getComments", + "summary": "Get all available comments", + "parameters": [ + { + "name": "id", + "in": "query", + "type": "integer", + "description": "Filter by comment ID", + "required": false + }, + { + "name": "postId", + "in": "query", + "type": "integer", + "description": "Filter by post ID", + "required": false + } + ], + "produces": ["application/json"], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Comment" + } + } + } + } + } + }, + "/comments/{id}": { + "get": { + "tags": ["comments"], + "operationId": "getComment", + "summary": "Get specific comment", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the comment to retrieve", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Comment" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + }, + "/albums": { + "get": { + "tags": ["albums"], + "operationId": "getAlbums", + "summary": "Get all available albums", + "parameters": [ + { + "name": "id", + "in": "query", + "type": "integer", + "description": "Filter by album ID", + "required": false + }, + { + "name": "userId", + "in": "query", + "type": "integer", + "description": "Filter by user ID", + "required": false + } + ], + "produces": ["application/json"], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Album" + } + } + } + } + } + }, + "/albums/{id}": { + "get": { + "tags": ["albums"], + "summary": "Get specific album", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the album to retrieve", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Album" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + }, + "/albums/{id}/photos": { + "get": { + "tags": ["albums"], + "summary": "Get photos for a specific album", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "post id", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Photo" + } + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + }, + "/photos": { + "get": { + "tags": ["photos"], + "operationId": "getPhotos", + "summary": "Get all available photos", + "parameters": [ + { + "name": "id", + "in": "query", + "type": "integer", + "description": "Filter by photo ID", + "required": false + }, + { + "name": "albumId", + "in": "query", + "type": "integer", + "description": "Filter by album ID", + "required": false + } + ], + "produces": ["application/json"], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Photo" + } + } + } + } + } + }, + "/photos/{id}": { + "get": { + "tags": ["photos"], + "operationId": "getPhoto", + "summary": "Get specific photo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the photo to retrieve", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Photo" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + }, + "/todos": { + "get": { + "tags": ["todos"], + "operationId": "getTodos", + "summary": "Get all available todos", + "parameters": [ + { + "name": "id", + "in": "query", + "type": "integer", + "description": "Filter by todo ID", + "required": false + }, + { + "name": "userId", + "in": "query", + "type": "integer", + "description": "Filter by user ID", + "required": false + } + ], + "produces": ["application/json"], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Todo" + } + } + } + } + } + }, + "/todos/{id}": { + "get": { + "tags": ["todos"], + "operationId": "getTodo", + "summary": "Get specific todo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the todo to retrieve", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Todo" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + }, + "/users": { + "get": { + "tags": ["users"], + "operationId": "getUsers", + "summary": "Get all available users", + "parameters": [ + { + "name": "id", + "in": "query", + "type": "integer", + "description": "Filter by user ID", + "required": false + }, + { + "name": "email", + "in": "query", + "type": "integer", + "description": "Filter by user email address", + "required": false + } + ], + "produces": ["application/json"], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } + } + } + } + }, + "/users/{id}": { + "get": { + "tags": ["users"], + "operationId": "getUser", + "summary": "Get specific user", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The ID of the user to retrieve", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/User" + } + }, + "404": { + "description": "not found", + "schema": { + "$ref": "#/definitions/NotFoundError" + } + } + } + } + } + }, + "definitions": { + "Post": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "userId": { + "type": "integer", + "format": "int64" + }, + "title": { + "type": "string" + }, + "body": { + "type": "string" + } + } + }, + "Comment": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "postId": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "email": { + "type": "string", + "format": "email" + }, + "body": { + "type": "string" + } + } + }, + "Album": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "userId": { + "type": "integer", + "format": "int64" + }, + "title": { + "type": "string" + } + } + }, + "Photo": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "albumId": { + "type": "integer", + "format": "int64" + }, + "title": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri" + }, + "thumbnailUrl": { + "type": "string", + "format": "uri" + } + } + }, + "Todo": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "userId": { + "type": "integer", + "format": "int64" + }, + "title": { + "type": "string" + }, + "completed": { + "type": "boolean" + } + } + }, + "User": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "username": { + "type": "string" + }, + "email": { + "type": "string", + "format": "email" + }, + "phone": { + "type": "string" + }, + "website": { + "type": "string" + }, + "company": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "catchPhrase": { + "type": "string" + }, + "bs": { + "type": "string" + } + } + }, + "address": { + "type": "object", + "properties": { + "street": { + "type": "string" + }, + "suite": { + "type": "string" + }, + "city": { + "type": "string" + }, + "zipcode": { + "type": "string" + }, + "geo": { + "type": "object", + "properties": { + "lat": { + "type": "string" + }, + "lng": { + "type": "string" + } + } + } + } + } + } + }, + "NotFoundError": { + "type": "object" + } + } +} diff --git a/rest/testdata/petstore3/config.yaml b/rest/testdata/petstore3/config.yaml new file mode 100644 index 0000000..6935280 --- /dev/null +++ b/rest/testdata/petstore3/config.yaml @@ -0,0 +1,3 @@ +files: + - path: openapi.json + spec: openapi3 diff --git a/rest/testdata/petstore3/openapi.json b/rest/testdata/petstore3/openapi.json new file mode 100644 index 0000000..4d61c5e --- /dev/null +++ b/rest/testdata/petstore3/openapi.json @@ -0,0 +1,1321 @@ +{ + "openapi": "3.0.2", + "info": { + "title": "Swagger Petstore - OpenAPI 3.0", + "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)", + "termsOfService": "http://swagger.io/terms/", + "contact": { "email": "apiteam@swagger.io" }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0.18" + }, + "externalDocs": { + "description": "Find out more about Swagger", + "url": "http://swagger.io" + }, + "servers": [{ "url": "https://petstore3.swagger.io/api/v3" }], + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + }, + { "name": "user", "description": "Operations about user" } + ], + "paths": { + "/pet": { + "put": { + "tags": ["pet"], + "summary": "Update an existing pet", + "description": "Update an existing pet by Id", + "operationId": "updatePet", + "requestBody": { + "description": "Update an existent pet in the store", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/xml": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/x-www-form-urlencoded": { + "schema": { "$ref": "#/components/schemas/Pet" } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/xml": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/json": { + "schema": { "$ref": "#/components/schemas/Pet" } + } + } + }, + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Pet not found" }, + "405": { "description": "Validation exception" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + }, + "post": { + "tags": ["pet"], + "summary": "Add a new pet to the store", + "description": "Add a new pet to the store", + "operationId": "addPet", + "requestBody": { + "description": "Create a new pet in the store", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/xml": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/x-www-form-urlencoded": { + "schema": { "$ref": "#/components/schemas/Pet" } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/xml": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/json": { + "schema": { "$ref": "#/components/schemas/Pet" } + } + } + }, + "405": { "description": "Invalid input" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/pet/findByStatus": { + "get": { + "tags": ["pet"], + "summary": "Finds Pets by status", + "description": "Multiple status values can be provided with comma separated strings", + "operationId": "findPetsByStatus", + "parameters": [ + { + "name": "status", + "in": "query", + "description": "Status values that need to be considered for filter", + "required": false, + "explode": true, + "schema": { + "type": "string", + "default": "available", + "enum": ["available", "pending", "sold"] + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/Pet" } + } + }, + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/Pet" } + } + } + } + }, + "400": { "description": "Invalid status value" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/pet/findByTags": { + "get": { + "tags": ["pet"], + "summary": "Finds Pets by tags", + "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId": "findPetsByTags", + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "Tags to filter by", + "required": false, + "explode": true, + "schema": { "type": "array", "items": { "type": "string" } } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/Pet" } + } + }, + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/Pet" } + } + } + } + }, + "400": { "description": "Invalid tag value" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/pet/{petId}": { + "get": { + "tags": ["pet"], + "summary": "Find pet by ID", + "description": "Returns a single pet", + "operationId": "getPetById", + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet to return", + "required": true, + "schema": { "type": "integer", "format": "int64" } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/json": { + "schema": { "$ref": "#/components/schemas/Pet" } + } + } + }, + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Pet not found" } + }, + "security": [ + { "api_key": [] }, + { "petstore_auth": ["write:pets", "read:pets"] } + ] + }, + "post": { + "tags": ["pet"], + "summary": "Updates a pet in the store with form data", + "description": "", + "operationId": "updatePetWithForm", + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet that needs to be updated", + "required": true, + "schema": { "type": "integer", "format": "int64" } + }, + { + "name": "name", + "in": "query", + "description": "Name of pet that needs to be updated", + "schema": { "type": "string" } + }, + { + "name": "status", + "in": "query", + "description": "Status of pet that needs to be updated", + "schema": { "type": "string" } + } + ], + "responses": { "405": { "description": "Invalid input" } }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + }, + "delete": { + "tags": ["pet"], + "summary": "Deletes a pet", + "description": "", + "operationId": "deletePet", + "parameters": [ + { + "name": "api_key", + "in": "header", + "description": "", + "required": false, + "schema": { "type": "string" } + }, + { + "name": "petId", + "in": "path", + "description": "Pet id to delete", + "required": true, + "schema": { "type": "integer", "format": "int64" } + } + ], + "responses": { "400": { "description": "Invalid pet value" } }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/pet/{petId}/uploadImage": { + "post": { + "tags": ["pet"], + "summary": "uploads an image", + "description": "", + "operationId": "uploadFile", + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet to update", + "required": true, + "schema": { "type": "integer", "format": "int64" } + }, + { + "name": "additionalMetadata", + "in": "query", + "description": "Additional Metadata", + "required": false, + "schema": { "type": "string" } + } + ], + "requestBody": { + "content": { + "application/octet-stream": { + "schema": { "type": "string", "format": "binary" } + } + } + }, + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ApiResponse" } + } + } + } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/store/inventory": { + "get": { + "tags": ["store"], + "summary": "Returns pet inventories by status", + "description": "Returns a map of status codes to quantities", + "operationId": "getInventory", + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "type": "object", + "additionalProperties": { + "type": "integer", + "format": "int32" + } + } + } + } + } + }, + "security": [{ "api_key": [] }] + } + }, + "/store/order": { + "post": { + "tags": ["store"], + "summary": "Place an order for a pet", + "description": "Place a new order in the store", + "operationId": "placeOrder", + "requestBody": { + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Order" } + }, + "application/xml": { + "schema": { "$ref": "#/components/schemas/Order" } + }, + "application/x-www-form-urlencoded": { + "schema": { "$ref": "#/components/schemas/Order" } + } + } + }, + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Order" } + } + } + }, + "405": { "description": "Invalid input" } + } + } + }, + "/store/order/{orderId}": { + "get": { + "tags": ["store"], + "summary": "Find purchase order by ID", + "description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.", + "operationId": "getOrderById", + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of order that needs to be fetched", + "required": true, + "schema": { "type": "integer", "format": "int64" } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { "$ref": "#/components/schemas/Order" } + }, + "application/json": { + "schema": { "$ref": "#/components/schemas/Order" } + } + } + }, + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Order not found" } + } + }, + "delete": { + "tags": ["store"], + "summary": "Delete purchase order by ID", + "description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId": "deleteOrder", + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of the order that needs to be deleted", + "required": true, + "schema": { "type": "integer", "format": "int64" } + } + ], + "responses": { + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Order not found" } + } + } + }, + "/user": { + "post": { + "tags": ["user"], + "summary": "Create user", + "description": "This can only be done by the logged in user.", + "operationId": "createUser", + "requestBody": { + "description": "Created user object", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + }, + "application/xml": { + "schema": { "$ref": "#/components/schemas/User" } + }, + "application/x-www-form-urlencoded": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "responses": { + "default": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + }, + "application/xml": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + } + } + } + }, + "/user/createWithList": { + "post": { + "tags": ["user"], + "summary": "Creates list of users with given input array", + "description": "Creates list of users with given input array", + "operationId": "createUsersWithListInput", + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/User" } + } + } + } + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/xml": { + "schema": { "$ref": "#/components/schemas/User" } + }, + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "default": { "description": "successful operation" } + } + } + }, + "/user/login": { + "get": { + "tags": ["user"], + "summary": "Logs user into the system", + "description": "", + "operationId": "loginUser", + "parameters": [ + { + "name": "username", + "in": "query", + "description": "The user name for login", + "required": false, + "schema": { "type": "string" } + }, + { + "name": "password", + "in": "query", + "description": "The password for login in clear text", + "required": false, + "schema": { "type": "string" } + } + ], + "responses": { + "200": { + "description": "successful operation", + "headers": { + "X-Rate-Limit": { + "description": "calls per hour allowed by the user", + "schema": { "type": "integer", "format": "int32" } + }, + "X-Expires-After": { + "description": "date in UTC when token expires", + "schema": { "type": "string", "format": "date-time" } + } + }, + "content": { + "application/xml": { "schema": { "type": "string" } }, + "application/json": { "schema": { "type": "string" } } + } + }, + "400": { "description": "Invalid username/password supplied" } + } + } + }, + "/user/logout": { + "get": { + "tags": ["user"], + "summary": "Logs out current logged in user session", + "description": "", + "operationId": "logoutUser", + "parameters": [], + "responses": { "default": { "description": "successful operation" } } + } + }, + "/user/{username}": { + "get": { + "tags": ["user"], + "summary": "Get user by user name", + "description": "", + "operationId": "getUserByName", + "parameters": [ + { + "name": "username", + "in": "path", + "description": "The name that needs to be fetched. Use user1 for testing. ", + "required": true, + "schema": { "type": "string" } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { "$ref": "#/components/schemas/User" } + }, + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "400": { "description": "Invalid username supplied" }, + "404": { "description": "User not found" } + } + }, + "put": { + "tags": ["user"], + "summary": "Update user", + "description": "This can only be done by the logged in user.", + "operationId": "updateUser", + "parameters": [ + { + "name": "username", + "in": "path", + "description": "name that needs to be updated", + "required": true, + "schema": { "type": "string" } + } + ], + "requestBody": { + "description": "Update an existent user in the store", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + }, + "application/xml": { + "schema": { "$ref": "#/components/schemas/User" } + }, + "application/x-www-form-urlencoded": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "responses": { "default": { "description": "successful operation" } } + }, + "delete": { + "tags": ["user"], + "summary": "Delete user", + "description": "This can only be done by the logged in user.", + "operationId": "deleteUser", + "parameters": [ + { + "name": "username", + "in": "path", + "description": "The name that needs to be deleted", + "required": true, + "schema": { "type": "string" } + } + ], + "responses": { + "400": { "description": "Invalid username supplied" }, + "404": { "description": "User not found" } + } + } + } + }, + "components": { + "schemas": { + "Order": { + "type": "object", + "properties": { + "id": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "petId": { + "type": "integer", + "format": "int64", + "example": 198772 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 7 + }, + "shipDate": { "type": "string", "format": "date-time" }, + "status": { + "type": "string", + "description": "Order Status", + "example": "approved", + "enum": ["placed", "approved", "delivered"] + }, + "complete": { "type": "boolean" } + }, + "xml": { "name": "order" } + }, + "petId": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "petId": { + "type": "integer", + "format": "int64", + "example": 198772 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 7 + }, + "shipDate": { "type": "string", "format": "date-time" }, + "status": { + "type": "string", + "description": "Order Status", + "example": "approved", + "enum": ["placed", "approved", "delivered"] + }, + "complete": { "type": "boolean" } + }, + "xml": { "name": "order" } + }, + "quantity": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "petId": { + "type": "integer", + "format": "int64", + "example": 198772 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 7 + }, + "shipDate": { "type": "string", "format": "date-time" }, + "status": { + "type": "string", + "description": "Order Status", + "example": "approved", + "enum": ["placed", "approved", "delivered"] + }, + "complete": { "type": "boolean" } + }, + "xml": { "name": "order" } + }, + "shipDate": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "petId": { + "type": "integer", + "format": "int64", + "example": 198772 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 7 + }, + "shipDate": { "type": "string", "format": "date-time" }, + "status": { + "type": "string", + "description": "Order Status", + "example": "approved", + "enum": ["placed", "approved", "delivered"] + }, + "complete": { "type": "boolean" } + }, + "xml": { "name": "order" } + }, + "status": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "petId": { + "type": "integer", + "format": "int64", + "example": 198772 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 7 + }, + "shipDate": { "type": "string", "format": "date-time" }, + "status": { + "type": "string", + "description": "Order Status", + "example": "approved", + "enum": ["placed", "approved", "delivered"] + }, + "complete": { "type": "boolean" } + }, + "xml": { "name": "order" } + }, + "complete": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "petId": { + "type": "integer", + "format": "int64", + "example": 198772 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 7 + }, + "shipDate": { "type": "string", "format": "date-time" }, + "status": { + "type": "string", + "description": "Order Status", + "example": "approved", + "enum": ["placed", "approved", "delivered"] + }, + "complete": { "type": "boolean" } + }, + "xml": { "name": "order" } + } + }, + "xml": { "name": "order" } + }, + "Customer": { + "type": "object", + "properties": { + "id": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 100000 }, + "username": { "type": "string", "example": "fehguy" }, + "address": { + "type": "array", + "xml": { "name": "addresses", "wrapped": true }, + "items": { "$ref": "#/components/schemas/Address" } + } + }, + "xml": { "name": "customer" } + }, + "username": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 100000 }, + "username": { "type": "string", "example": "fehguy" }, + "address": { + "type": "array", + "xml": { "name": "addresses", "wrapped": true }, + "items": { "$ref": "#/components/schemas/Address" } + } + }, + "xml": { "name": "customer" } + }, + "address": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 100000 }, + "username": { "type": "string", "example": "fehguy" }, + "address": { + "type": "array", + "xml": { "name": "addresses", "wrapped": true }, + "items": { "$ref": "#/components/schemas/Address" } + } + }, + "xml": { "name": "customer" } + } + }, + "xml": { "name": "customer" } + }, + "Address": { + "type": "object", + "properties": { + "street": { + "type": "object", + "properties": { + "street": { "type": "string", "example": "437 Lytton" }, + "city": { "type": "string", "example": "Palo Alto" }, + "state": { "type": "string", "example": "CA" }, + "zip": { "type": "string", "example": "94301" } + }, + "xml": { "name": "address" } + }, + "city": { + "type": "object", + "properties": { + "street": { "type": "string", "example": "437 Lytton" }, + "city": { "type": "string", "example": "Palo Alto" }, + "state": { "type": "string", "example": "CA" }, + "zip": { "type": "string", "example": "94301" } + }, + "xml": { "name": "address" } + }, + "state": { + "type": "object", + "properties": { + "street": { "type": "string", "example": "437 Lytton" }, + "city": { "type": "string", "example": "Palo Alto" }, + "state": { "type": "string", "example": "CA" }, + "zip": { "type": "string", "example": "94301" } + }, + "xml": { "name": "address" } + }, + "zip": { + "type": "object", + "properties": { + "street": { "type": "string", "example": "437 Lytton" }, + "city": { "type": "string", "example": "Palo Alto" }, + "state": { "type": "string", "example": "CA" }, + "zip": { "type": "string", "example": "94301" } + }, + "xml": { "name": "address" } + } + }, + "xml": { "name": "address" } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 1 }, + "name": { "type": "string", "example": "Dogs" } + }, + "xml": { "name": "category" } + }, + "name": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 1 }, + "name": { "type": "string", "example": "Dogs" } + }, + "xml": { "name": "category" } + } + }, + "xml": { "name": "category" } + }, + "User": { + "type": "object", + "properties": { + "id": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + }, + "username": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + }, + "firstName": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + }, + "lastName": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + }, + "email": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + }, + "password": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + }, + "phone": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + }, + "userStatus": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "username": { "type": "string", "example": "theUser" }, + "firstName": { "type": "string", "example": "John" }, + "lastName": { "type": "string", "example": "James" }, + "email": { "type": "string", "example": "john@email.com" }, + "password": { "type": "string", "example": "12345" }, + "phone": { "type": "string", "example": "12345" }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { "name": "user" } + } + }, + "xml": { "name": "user" } + }, + "Tag": { + "type": "object", + "properties": { + "id": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64" }, + "name": { "type": "string" } + }, + "xml": { "name": "tag" } + }, + "name": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64" }, + "name": { "type": "string" } + }, + "xml": { "name": "tag" } + } + }, + "xml": { "name": "tag" } + }, + "Pet": { + "required": ["name", "photoUrls"], + "type": "object", + "properties": { + "id": { + "required": ["name", "photoUrls"], + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "name": { "type": "string", "example": "doggie" }, + "category": { "$ref": "#/components/schemas/Category" }, + "photoUrls": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "type": "string", "xml": { "name": "photoUrl" } } + }, + "tags": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "$ref": "#/components/schemas/Tag" } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": ["available", "pending", "sold"] + } + }, + "xml": { "name": "pet" } + }, + "name": { + "required": ["name", "photoUrls"], + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "name": { "type": "string", "example": "doggie" }, + "category": { "$ref": "#/components/schemas/Category" }, + "photoUrls": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "type": "string", "xml": { "name": "photoUrl" } } + }, + "tags": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "$ref": "#/components/schemas/Tag" } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": ["available", "pending", "sold"] + } + }, + "xml": { "name": "pet" } + }, + "category": { + "required": ["name", "photoUrls"], + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "name": { "type": "string", "example": "doggie" }, + "category": { "$ref": "#/components/schemas/Category" }, + "photoUrls": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "type": "string", "xml": { "name": "photoUrl" } } + }, + "tags": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "$ref": "#/components/schemas/Tag" } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": ["available", "pending", "sold"] + } + }, + "xml": { "name": "pet" } + }, + "photoUrls": { + "required": ["name", "photoUrls"], + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "name": { "type": "string", "example": "doggie" }, + "category": { "$ref": "#/components/schemas/Category" }, + "photoUrls": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "type": "string", "xml": { "name": "photoUrl" } } + }, + "tags": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "$ref": "#/components/schemas/Tag" } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": ["available", "pending", "sold"] + } + }, + "xml": { "name": "pet" } + }, + "tags": { + "required": ["name", "photoUrls"], + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "name": { "type": "string", "example": "doggie" }, + "category": { "$ref": "#/components/schemas/Category" }, + "photoUrls": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "type": "string", "xml": { "name": "photoUrl" } } + }, + "tags": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "$ref": "#/components/schemas/Tag" } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": ["available", "pending", "sold"] + } + }, + "xml": { "name": "pet" } + }, + "status": { + "required": ["name", "photoUrls"], + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64", "example": 10 }, + "name": { "type": "string", "example": "doggie" }, + "category": { "$ref": "#/components/schemas/Category" }, + "photoUrls": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "type": "string", "xml": { "name": "photoUrl" } } + }, + "tags": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "$ref": "#/components/schemas/Tag" } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": ["available", "pending", "sold"] + } + }, + "xml": { "name": "pet" } + } + }, + "xml": { "name": "pet" } + }, + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "object", + "properties": { + "code": { "type": "integer", "format": "int32" }, + "type": { "type": "string" }, + "message": { "type": "string" } + }, + "xml": { "name": "##default" } + }, + "type": { + "type": "object", + "properties": { + "code": { "type": "integer", "format": "int32" }, + "type": { "type": "string" }, + "message": { "type": "string" } + }, + "xml": { "name": "##default" } + }, + "message": { + "type": "object", + "properties": { + "code": { "type": "integer", "format": "int32" }, + "type": { "type": "string" }, + "message": { "type": "string" } + }, + "xml": { "name": "##default" } + } + }, + "xml": { "name": "##default" } + } + }, + "requestBodies": { + "Pet": { + "description": "Pet object that needs to be added to the store", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Pet" } + }, + "application/xml": { + "schema": { "$ref": "#/components/schemas/Pet" } + } + } + }, + "UserArray": { + "description": "List of user object", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/User" } + } + } + } + } + }, + "securitySchemes": { + "petstore_auth": { + "type": "oauth2", + "flows": { + "implicit": { + "authorizationUrl": "https://petstore3.swagger.io/oauth/authorize", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + } + } + }, + "api_key": { "type": "apiKey", "name": "api_key", "in": "header" } + } + } +} diff --git a/rest/types.go b/rest/types.go new file mode 100644 index 0000000..7c4b824 --- /dev/null +++ b/rest/types.go @@ -0,0 +1,52 @@ +package rest + +import ( + "net/http" + + "github.com/hasura/ndc-rest-schema/schema" +) + +const ( + defaultTimeout uint = 30 + + contentTypeHeader = "Content-Type" + contentTypeJSON = "application/json" +) + +// SchemaFile represents a schema file +type SchemaFile struct { + Path string `json:"path" yaml:"path"` + Spec schema.SchemaSpecType `json:"spec" yaml:"spec"` + MethodAlias map[string]string `json:"methodAlias" yaml:"methodAlias"` + TrimPrefix string `json:"trimPrefix" yaml:"trimPrefix"` +} + +// Configuration contains required settings for the connector. +type Configuration struct { + Files []SchemaFile `json:"files" yaml:"files"` +} + +// State is the global state which is shared for every connector request. +type State struct { + Schema *schema.NDCRestSchema +} + +type options struct { + client Doer +} + +var defaultOptions options = options{ + client: &http.Client{ + Transport: http.DefaultTransport, + }, +} + +// Option is an interface to set custom REST connector options +type Option (func(*options)) + +// WithClient sets the custom HTTP client that satisfy the Doer interface +func WithClient(client Doer) Option { + return func(opts *options) { + opts.client = client + } +}