Skip to content
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
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: "Code scanning - action"
name: 'Code scanning - action'

on:
push:
branches: [main]
pull_request:
schedule:
- cron: "0 19 * * 0"
- cron: '0 19 * * 0'

jobs:
CodeQL-Build:
Expand Down
1 change: 1 addition & 0 deletions apps/SageAccountWeb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react-easy-crop": "^5.0.7",
"react-router-dom": "^5.3.4",
"sass": "^1.71.1",
"synapse-client": "workspace:*",
"synapse-react-client": "workspace:*",
"universal-cookie": "^4.0.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import {
useApplicationSessionContext,
useQuerySearchParam,
} from 'synapse-react-client'
import {
TwoFactorAuthErrorResponse,
TwoFactorAuthResetToken,
} from '@sage-bionetworks/synapse-types'
import { TwoFactorAuthResetToken } from '@sage-bionetworks/synapse-types'
import { TwoFactorAuthErrorResponse } from 'synapse-client'
import { hexDecodeAndDeserialize } from '../../URLUtils'
import { BackButton } from '../BackButton'
import { LeftRightPanel } from '../LeftRightPanel'
Expand Down
23 changes: 14 additions & 9 deletions apps/SageAccountWeb/vite.config.ts
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
23 changes: 14 additions & 9 deletions apps/synapse-oauth-signin/vite.config.ts
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
46 changes: 16 additions & 30 deletions apps/synapse-portal-framework/vite.config.ts
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
45 changes: 17 additions & 28 deletions packages/markdown-it-synapse-table/vite.config.ts
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()
1 change: 1 addition & 0 deletions packages/synapse-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/generated/
Copy link
Collaborator Author

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

35 changes: 35 additions & 0 deletions packages/synapse-client/README.md
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.
7 changes: 7 additions & 0 deletions packages/synapse-client/config.json
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"
}
7 changes: 7 additions & 0 deletions packages/synapse-client/openapitools.json
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"
}
}
Loading
Loading