-
Notifications
You must be signed in to change notification settings - Fork 23
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
SWC-6662 - OpenAPI Client Generation for Synapse REST API #689
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
557f54e
SWC-6662 - openapi client gen with openapi-generator
nickgros f373904
SWC-6662 - Initial work on using OpenAPI definition to generate model…
nickgros c5a7436
Merge branch 'main' of https://github.com/Sage-Bionetworks/synapse-we…
nickgros 631df05
SWC-6662 - Build sytnapse-client with vite, refactor vite-config to a…
nickgros bab9346
SWC-6662 - Upgrade OpenAPI Generator & spec
nickgros 98a0f65
SWC-6662 - Refactor & unravel some error issues
nickgros 72ca203
SWC-6662 - Fix type error
nickgros 03fe404
SWC-6662 - Fix tests
nickgros 8b4f3ee
SWC-6662 - Fix indentation in template
nickgros c2122f0
SWC-6662 - Fix missing dependent task
nickgros 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 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 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 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 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,10 +1,15 @@ | ||
import { vitestConfig } from 'vite-config' | ||
import { mergeConfig } from 'vitest/config' | ||
import { ConfigBuilder } from 'vite-config' | ||
|
||
export default mergeConfig(vitestConfig, { | ||
test: { | ||
include: ['src/**/*.test.[jt]s?(x)'], | ||
setupFiles: ['src/tests/setupTests.ts'], | ||
environment: 'jsdom', // introduced due to random "ReferenceError: window is not defined" during tests | ||
}, | ||
}) | ||
const config = new ConfigBuilder() | ||
.setIncludeReactConfig(true) | ||
.setIncludeVitestConfig(true) | ||
.setConfigOverrides({ | ||
test: { | ||
include: ['src/**/*.test.[jt]s?(x)'], | ||
setupFiles: ['src/tests/setupTests.ts'], | ||
environment: 'jsdom', // introduced due to random "ReferenceError: window is not defined" during tests | ||
}, | ||
}) | ||
.build() | ||
|
||
export default config |
This file contains 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,10 +1,15 @@ | ||
import { vitestConfig } from 'vite-config' | ||
import { mergeConfig } from 'vitest/config' | ||
import { ConfigBuilder } from 'vite-config' | ||
|
||
export default mergeConfig(vitestConfig, { | ||
test: { | ||
include: ['src/test/**/*.test.[jt]s?(x)'], | ||
setupFiles: ['src/test/setupTests.ts'], | ||
environment: 'jsdom', // introduced due to random "ReferenceError: window is not defined" during tests | ||
}, | ||
}) | ||
const config = new ConfigBuilder() | ||
.setIncludeReactConfig(true) | ||
.setIncludeVitestConfig(true) | ||
.setConfigOverrides({ | ||
test: { | ||
include: ['src/test/**/*.test.[jt]s?(x)'], | ||
setupFiles: ['src/test/setupTests.ts'], | ||
environment: 'jsdom', // introduced due to random "ReferenceError: window is not defined" during tests | ||
}, | ||
}) | ||
.build() | ||
|
||
export default config |
This file contains 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,32 +1,18 @@ | ||
import { vitestConfig } from 'vite-config' | ||
import { mergeConfig } from 'vitest/config' | ||
import { ConfigBuilder } from 'vite-config' | ||
import { resolve } from 'path' | ||
export default mergeConfig(vitestConfig, { | ||
build: { | ||
outDir: 'dist', | ||
lib: { | ||
// Could also be a dictionary or array of multiple entry points | ||
entry: resolve(__dirname, 'src/index.ts'), | ||
name: 'SynapsePortalFramework', | ||
// the proper extensions will be added | ||
fileName: 'synapse-portal-framework', | ||
|
||
const config = new ConfigBuilder() | ||
.setIncludeReactConfig(true) | ||
.setIncludeLibraryConfig(true) | ||
.setBuildLibEntry(resolve(__dirname, 'src/index.ts')) | ||
.setIncludeVitestConfig(true) | ||
.setConfigOverrides({ | ||
test: { | ||
include: ['src/**/*.test.[jt]s?(x)'], | ||
setupFiles: ['src/tests/setupTests.ts'], | ||
environment: 'jsdom', | ||
}, | ||
rollupOptions: { | ||
// make sure to externalize deps that shouldn't be bundled | ||
// into your library | ||
external: ['react'], | ||
output: { | ||
// Provide global variables to use in the UMD build | ||
// for externalized deps | ||
globals: { | ||
react: 'React', | ||
}, | ||
}, | ||
}, | ||
}, | ||
test: { | ||
include: ['src/**/*.test.[jt]s?(x)'], | ||
setupFiles: ['src/tests/setupTests.ts'], | ||
environment: 'jsdom', | ||
}, | ||
}) | ||
}) | ||
.build() | ||
|
||
export default config |
This file contains 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,31 +1,20 @@ | ||
import { vitestConfig } from 'vite-config' | ||
import { mergeConfig } from 'vitest/config' | ||
import { resolve } from 'path' | ||
import { externalizeDeps } from 'vite-plugin-externalize-deps' | ||
import dts from 'vite-plugin-dts' | ||
import { ConfigBuilder } from 'vite-config' | ||
|
||
export default mergeConfig(vitestConfig, { | ||
build: { | ||
sourcemap: true, | ||
emptyOutDir: true, | ||
outDir: './dist', | ||
lib: { | ||
entry: resolve(__dirname, 'src/index.ts'), | ||
name: 'markdownitSynapseTable', | ||
fileName: 'index', | ||
formats: ['es', 'cjs', 'umd'], | ||
export default new ConfigBuilder() | ||
.setIncludeLibraryConfig(true) | ||
.setBuildLibEntry(resolve(__dirname, 'src/index.ts')) | ||
.setIncludeVitestConfig(true) | ||
.setConfigOverrides({ | ||
build: { | ||
lib: { | ||
name: 'markdownitSynapseTable', | ||
formats: ['es', 'cjs', 'umd'], | ||
}, | ||
}, | ||
}, | ||
test: { | ||
globals: true, | ||
include: ['test/**/*.test.[jt]s?(x)'], | ||
}, | ||
plugins: [ | ||
// Do not bundle any dependencies; the consumer's bundler will resolve and link them. | ||
externalizeDeps(), | ||
// Generate a single type definition file for distribution. | ||
dts({ | ||
rollupTypes: true, | ||
}), | ||
], | ||
}) | ||
test: { | ||
globals: true, | ||
include: ['test/**/*.test.[jt]s?(x)'], | ||
}, | ||
}) | ||
.build() |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
src/generated/ | ||
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# synapse-client | ||
|
||
This package generates TypeScript/JavaScript models and API clients for [Synapse](https://www.synapse.org/), a collaborative, open-source research platform that allows teams to share data, track analyses, and collaborate. | ||
|
||
To generate code, we use the [Synapse REST Services](https://rest-docs.synapse.org/rest/index.html) OpenAPI Definition and the [OpenAPI Generator](https://openapi-generator.tech/). This package will also maintain wrappers, utility classes, and configuration used to improve developer experience. | ||
|
||
## Generating code | ||
|
||
To generate code for the models and services, simply run `pnpm build`. This will trigger the OpenAPI Generator CLI and also run any scripts that may be needed to improve code generation. | ||
|
||
## Upgrading the OpenAPI definition | ||
|
||
At this time, the only published versions of the Synapse OpenAPI definition are for the current production stack, and for the staging stack. The staging stack typically elevated to production the following week. | ||
We commit a stable copy of the OpenAPI definition to version control to ensure our generated code is consistent and does not cause unexpected regressions as the OpenAPI definition changes. | ||
|
||
To update the OpenAPI definition, run `pnpm get-spec` to get the latest production OpenAPI definition, which will be saved in `./src/spec/openapispecification.json`. | ||
You can also run `pnpm get-spec:staging` to get the OpenAPI definition associated with the current staging release. After retrieving the specification, you will once again need to run `pnpm build`. | ||
Once you have new models built, tests and type-checking on the full project should be run to ensure the new spec does not introduce errors. Our CI process will catch this automatically. | ||
|
||
## Upgrading the openapi-generator version and overriding templates | ||
|
||
The current version of openapi-generator can be set by changing the version number set in the `pnpm configure` script. | ||
When the version is changed, our template overrides should be updated. | ||
|
||
To copy all the base template files into the `./out` directory, run the following command: | ||
|
||
```shell | ||
npx openapi-generator-cli author template -g typescript-fetch | ||
``` | ||
|
||
Any template files that do not need to be modified or overridden can be deleted. | ||
Existing template customizations must then be re-implemented in the new templates. The complexity of this task depends on how drastically the templates have changed upstream. | ||
For this reason, we should limit the changes we make to templates, and clearly indicate the change and its impact. | ||
|
||
We also maintain tests that verify that any custom changes we make to the templates function as expected, which should pass after each upgrade. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"generatorName": "typescript-fetch", | ||
"outputDirectory": "src/generated", | ||
"legacyDiscriminatorBehavior": false, | ||
"modelPropertyNaming": "original", | ||
"enumPropertyNaming": "original" | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json", | ||
"spaces": 2, | ||
"generator-cli": { | ||
"version": "7.8.0" | ||
} | ||
} |
Oops, something went wrong.
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.
Don't commit the generated models to git