forked from fabfuel/api-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: PEN-0000 Move api-deploy, remove redundant inline schemas #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
84d9077
move api-deploy, remove redundant inline schemas, align release with …
umaan1982 7e1fa9c
re order generated yml and update read me
umaan1982 fe998ba
use docker image deploy
umaan1982 f1d6801
update versions
umaan1982 7cebc58
use tech packmatic email
umaan1982 c411f37
add functional test for dedup
umaan1982 26baa30
build amd64 only
umaan1982 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,109 @@ | ||
| # API Deploy | ||
| # API Deploy | ||
|
|
||
| Compile an OpenAPI spec into an Amazon API Gateway definition and deploy it. | ||
|
|
||
| Packmatic fork of [fabfuel/api-deploy](https://github.com/fabfuel/api-deploy). Pushing to | ||
| `develop` publishes `ghcr.io/packmatic/api-deploy:develop`, which `packaging`'s API Gateway | ||
| deploy uses. | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| docker run --rm -v "$PWD":/workspace -w /workspace \ | ||
| ghcr.io/packmatic/api-deploy:develop \ | ||
| api compile <config> <source> <target> | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| api compile <config> <source> <target> # compile only | ||
| api deploy <config> <api-id> <stage> <source> | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ```yaml | ||
| gateway: | ||
| integrationHost: 'https://${stageVariables.host}' | ||
| connectionId: '${stageVariables.connectionId}' | ||
| removeScopes: true # strip OAuth scopes; API Gateway rejects them | ||
| removeDescriptions: true # strip `description` from components/schemas | ||
| removeExamples: true # strip `example` / `examples` | ||
| flatten: | ||
| dedupExternalRefs: true # share resolved external $refs instead of copying them | ||
| headers: | ||
| request: [Authorization, Content-Type] | ||
| cors: | ||
| origin: '*' | ||
| static: | ||
| files: [api.v1.yml] | ||
| strict: | ||
| enabled: true | ||
| overwriteRequired: true | ||
| blocklist: [_links, _meta] | ||
| generator: | ||
| languages: [typescript] | ||
| output: src/openapi/types | ||
| ``` | ||
|
|
||
| `removeExamples` and `dedupExternalRefs` both default to `false`, so existing configs | ||
| compile byte-for-byte as before. | ||
|
|
||
| ### `flatten.dedupExternalRefs` | ||
|
|
||
| API Gateway's `put-rest-api` / `import-rest-api` body limit is | ||
| [6 MiB](https://docs.aws.amazon.com/apigateway/latest/api/API_PutRestApi.html#API_PutRestApi_RequestBody). | ||
| By default every external `$ref` is resolved into a **full inline copy** at each use site, and | ||
| YAML anchors are disabled, so a spec that shares a handful of error responses across a few | ||
| hundred endpoints inflates enormously — Packmatic's spec inlined ~1,100 copies of the same | ||
| six error schemas. | ||
|
|
||
| With `dedupExternalRefs: true`, each resolved external schema is registered once under | ||
| `components/schemas` and every use site becomes an internal `$ref`. API Gateway resolves | ||
| internal `#/components/schemas/*` refs, so the result imports unchanged. | ||
|
|
||
| Scope: refs in a `schema:` position, and the payload schema of any resolved object carrying | ||
| `content` (responses, request bodies). The response *wrapper* stays inline — only the payload | ||
| schema is shared. Refs nested inside `properties` are still inlined, as are parameter refs, | ||
| which API Gateway requires inline. | ||
|
|
||
| Component names derive from the ref filename, forced to be alphanumeric and to start with a | ||
| letter (`responses/500-server-error.yml` → `Response500ServerError`), and are uniquified | ||
| against existing components. Schemas with identical bodies collapse into one component even | ||
| when reached through differently spelled refs. | ||
|
|
||
| Effect on Packmatic's packaging spec: **6,364,377 B → 4,214,757 B**, or 3,915,048 B with | ||
| `removeExamples` as well. API Gateway model count drops from ~1,214 to ~128, since identical | ||
| models are shared rather than duplicated per use site; per-method validation is unchanged. | ||
|
|
||
| ### `gateway.removeExamples` | ||
|
|
||
| Strips `example` and `examples`. A schema *property* literally named `example` is preserved — | ||
| only keyword positions are stripped — and `x-amazon-apigateway-integration` blocks are left | ||
| untouched. Note this runs before the CORS processor, so CORS response-header examples it | ||
| generates afterwards remain. | ||
|
|
||
| Do not enable it in a config that also has a `generator` section: the TypeScript generator | ||
| emits `Example:` JSDoc from these values, so the generated types would lose those comments. | ||
| Keep it in the API-Gateway-only config. | ||
|
|
||
| ## Releasing | ||
|
|
||
| Merging to `develop` builds and pushes `ghcr.io/packmatic/api-deploy:develop` (and `:latest`). | ||
| Pushing a `x.y.z` tag publishes that tag too. Nothing to run by hand. | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| pip install . -r requirements-test.txt | ||
| pytest | ||
| flake8 api_deploy | ||
| ``` | ||
|
|
||
| The functional tests resolve external `$ref`s against the live schemas at | ||
| `api.packmatic.io` / `api-staging.packmatic.io`, which are served from the | ||
| [api-types](https://github.com/Packmatic/api-types) repo. When api-types changes a shared | ||
| schema, `tests/openapi/*_target.yml` goes stale and must be regenerated — api-types 1.11.0 | ||
| widened the `urn.yml` pattern to support two ids and added fields to the error responses, | ||
| which is why those fixtures were refreshed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| VERSION = '0.17.0' | ||
| VERSION = '0.18.0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need any permissions setup for this?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It uses
packages:write