-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
206 changed files
with
9,490 additions
and
796 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["src/lib/generated/marble-api.ts"], | ||
"rules": { | ||
"@typescript-eslint/ban-types": "off", // oazapfts generate {} instead of Record<string,empy> | ||
"@typescript-eslint/no-explicit-any": "error" // you should change OAS spec to generate non any types | ||
} | ||
} | ||
] | ||
} |
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,37 @@ | ||
# api-marble | ||
|
||
This library generates Marble API client based on `src/scripts/openapi.yaml`. | ||
|
||
## Getting started | ||
|
||
The generated code can be found in `src/lib/generated/marble-api.ts` | ||
|
||
1. Make sure to have `scripts/openapi.yaml` up to date | ||
2. Run `npm run generate-api -w marble-api` to generate the client | ||
3. Review generated code and commit changes | ||
|
||
> NB: in case update introduced breaking changes, you may need to resolve TS issues in places the client is used | ||
## Development | ||
|
||
### Edit ECMAScript generation process | ||
|
||
Change the generation script by editing `scripts/generate.ts` | ||
|
||
### Expose some usefull helpers | ||
|
||
Change or add files in `src/helpers` | ||
|
||
> don't forget to explicitly expose public interface in `src/index.ts` | ||
### Get updated regex to easilly find new operators in backend code | ||
|
||
> May be deprcated soon with the new AST based approach | ||
1. Run `npm run operator-regex -w marble-api` to generate the regexp | ||
2. Copy the regexp | ||
3. Use the "Find All" VS Code tab from the backend | ||
|
||
 | ||
|
||
> NB: make sure to check the regexp box in the VS Code UI |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,12 @@ | ||
{ | ||
"name": "marble-api", | ||
"version": "1.0.0", | ||
"description": "", | ||
"devDependencies": {}, | ||
"scripts": { | ||
"generate-api": "node -r esbuild-register scripts/generate.ts", | ||
"operator-regex": "node -r esbuild-register scripts/operator-regexp.ts" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
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,13 @@ | ||
import { type Opts } from 'oazapfts/lib/codegen/index'; | ||
import { join } from 'path'; | ||
|
||
export const OPENAPI_SPEC = join('scripts', 'openapi.yaml'); | ||
|
||
export const GENERATED_FOLDER = join('src', 'generated'); | ||
export const GENERATED_API = join(GENERATED_FOLDER, 'marble-api.ts'); | ||
|
||
export const OPENAPI_OPTIONS: Opts = { | ||
optimistic: true, | ||
useEnumType: false, | ||
unionUndefined: false, | ||
}; |
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,38 @@ | ||
import { mkdir, rm, writeFile } from 'fs/promises'; | ||
import { generateSource } from 'oazapfts/lib/codegen/index'; | ||
import ora from 'ora'; | ||
|
||
import { | ||
GENERATED_API, | ||
GENERATED_FOLDER, | ||
OPENAPI_OPTIONS, | ||
OPENAPI_SPEC, | ||
} from './config'; | ||
|
||
async function openapiGenerator() { | ||
const spinner = ora('Start to generate OpenAPI client...').start(); | ||
try { | ||
const code = await generateSource(OPENAPI_SPEC, OPENAPI_OPTIONS); | ||
|
||
await writeFile(GENERATED_API, code); | ||
|
||
spinner.succeed('Succesfully generated OpenAPI client'); | ||
} catch (error) { | ||
spinner.fail('Failed to generate OpenAPI client'); | ||
throw error; | ||
} | ||
} | ||
|
||
async function main() { | ||
try { | ||
await rm(GENERATED_FOLDER, { recursive: true, force: true }); | ||
await mkdir(GENERATED_FOLDER); | ||
|
||
await openapiGenerator(); | ||
} catch (error) { | ||
console.error('\n', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
Oops, something went wrong.