-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
68812ab
commit 9beb6bd
Showing
14 changed files
with
1,062 additions
and
3,720 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
env: { | ||
es6: true, | ||
jest: true, | ||
node: true, | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 7, | ||
sourceType: 'module', | ||
project: ['./tsconfig.eslint.json'] | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
extends: [ | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
], | ||
}; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI | ||
|
||
on: | ||
- pull_request | ||
- push | ||
|
||
jobs: | ||
ci: | ||
name: Continuous integration | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 'current' | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Check build | ||
run: yarn build | ||
- name: Check coding standards | ||
run: yarn lint |
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,29 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
release: | ||
name: Create and publish a release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 'current' | ||
registry-url: https://registry.npmjs.org | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Check build | ||
run: yarn build | ||
- name: Check coding standards | ||
run: yarn lint | ||
- name: Publish to npm | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file was deleted.
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env node | ||
|
||
import fs from 'fs'; | ||
import { program } from 'commander'; | ||
import chalk from 'chalk'; | ||
import { parseOpenApi3Documentation, parseHydraDocumentation } from '@api-platform/api-doc-parser'; | ||
import parsedJsonReplacer from "./parsedJsonReplacer.js"; | ||
|
||
type OptionValues = { | ||
format: string; | ||
dump: string; | ||
}; | ||
|
||
program | ||
.description('Check API Hydra documentation parsing') | ||
.argument('<entrypoint>', 'Entrypoint to the API documentation') | ||
.option( | ||
'-f, --format [hydra|openapi3]', | ||
'"hydra" or "openapi3"', | ||
'hydra' | ||
) | ||
.option('-d, --dump [filename]', 'Dump parsed API documentation') | ||
.showHelpAfterError() | ||
.parse(); | ||
|
||
const entrypoint = program.args[0]; | ||
const options = program.opts<OptionValues>(); | ||
|
||
const parse = options.format === 'openapi3' ? parseOpenApi3Documentation : parseHydraDocumentation; | ||
|
||
parse(entrypoint).then((api) => { | ||
let count = 0; | ||
const endpoints: string[] = []; | ||
console.log() | ||
console.log(`${chalk.green('Checking documentation parsing for API @')} ${entrypoint}`); | ||
for (const resource of api.api.resources || []) { | ||
count++; | ||
const nameLc = resource.name.toLowerCase(); | ||
endpoints.push(nameLc); | ||
} | ||
console.log(endpoints.sort()); | ||
console.log(`${chalk.green('Number of endpoints parsed:')} ${count}`); | ||
|
||
if (options.dump) { | ||
fs.writeFile(options.dump, JSON.stringify(api, parsedJsonReplacer, 2), (e) => { | ||
if (e) { | ||
throw e; | ||
} | ||
console.log(`Parsed API documentation dumped to file: ${options.dump}`); | ||
}); | ||
} | ||
}).catch((e) => { | ||
console.log(e); | ||
}); |
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,23 @@ | ||
interface ResourceValue { | ||
id?: string; | ||
title: string; | ||
} | ||
|
||
type ParsedJsonReplacerResult = ResourceValue | string | null; | ||
|
||
const parsedJsonReplacer = ( | ||
key: string, | ||
value: null | ResourceValue | ||
): ParsedJsonReplacerResult => { | ||
if ( | ||
["reference", "embedded"].includes(key) && | ||
typeof value === "object" && | ||
value !== null | ||
) { | ||
return `Object ${value.id || value.title}`; | ||
} | ||
|
||
return value; | ||
}; | ||
|
||
export default parsedJsonReplacer; |
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,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": [] | ||
} |
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,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "esnext", | ||
"sourceMap": true, | ||
"outDir": "./lib", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"rootDir": "./src", | ||
"importHelpers": true, | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true | ||
}, | ||
"exclude": [ | ||
"src/**/*.test.ts", | ||
], | ||
"include": ["./src"] | ||
} |
Oops, something went wrong.