Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 697efab

Browse files
authored
Merge pull request #9 from onmax/alpha
Graph now is being exposed
2 parents a1f0591 + 57abbee commit 697efab

File tree

13 files changed

+46
-72
lines changed

13 files changed

+46
-72
lines changed

‎README.md‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Swagger-graph
1+
# OpenAPI-graph
22

33
A TS library to manage large API projects defined by OpenAPIv3 specification.
44

@@ -8,33 +8,19 @@ A TS library to manage large API projects defined by OpenAPIv3 specification.
88

99
Just run
1010

11-
> npm install openapi-graph
11+
> npm install openapi-graph-core
1212
1313
and you are good to go
1414

15-
## Functions
15+
## Creating an OpenAPI graph
1616

17-
For now, just one function is being exposed
18-
19-
### `getUnusedSchemas(path: string)`
20-
21-
It will create a OpenAPIGraph, and get the schemas that are not being used as a list.
22-
23-
#### Arguments
24-
25-
`path: string` - Abosolute, relative or url where the API has being defined
26-
27-
#### Returns
28-
29-
A list of `Schemas` that are not being used in the API.
30-
31-
#### Example
17+
The constructor needs to be a path of the root of the proyect where all your openAPI specifications are stored which will be fetched automatically.
3218

3319
```javascript
34-
const openApiGraph = require('openapi-graph');
20+
const OpenAPIGraphs = require('openapi-graph-core');
3521

3622
(async () => {
37-
const a = await openApiGraph.getUnusedSchemas('./')
38-
console.log(a)
23+
const graphs = await newOpenAPIGraphs('./').build()
24+
console.log(graphs)
3925
})();
4026
```

‎package.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"files": [
2323
"lib"
2424
],
25+
"publishConfig": {
26+
"registry": "https://npm.pkg.github.com"
27+
},
28+
"repository": {
29+
"url": "git://github.com/onmax/open-api-graph.git"
30+
},
2531
"devDependencies": {
2632
"@types/jest": "^26.0.20",
2733
"@types/js-yaml": "^4.0.0",
@@ -37,4 +43,4 @@
3743
"dependencies": {
3844
"@apidevtools/swagger-parser": "^10.0.2"
3945
}
40-
}
46+
}

‎src/graph/OpenAPIGraphsManager.ts‎ renamed to ‎src/graph/OpenAPIGraphs.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { OpenAPIContent } from '../../model';
1+
import { fetcher } from '../openapi/fetcher';
22
import { OpenAPIGraphsBuilder } from './builder/OpenAPIGraphsBuilder';
33
import { RefEdge } from './edges';
44
import { SchemaNode } from './nodes/SchemaNode';
55

6-
export class OpenAPIGraphsManager {
6+
export class OpenAPIGraphs {
77
builder!: OpenAPIGraphsBuilder;
8+
rootPath!: string;
89

9-
constructor(apis: OpenAPIContent[]) {
10+
constructor(rootPath: string) {
11+
this.rootPath = rootPath;
12+
}
13+
14+
async build() {
15+
const apis = await fetcher(this.rootPath)
1016
this.builder = new OpenAPIGraphsBuilder(apis);
1117
}
1218

‎src/graph/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { OpenAPIGraph } from './OpenAPIGraph';
22
export { OpenAPIGraphsBuilder } from './builder/OpenAPIGraphsBuilder';
3-
export { OpenAPIGraphsManager } from './OpenAPIGraphsManager';
3+
export { OpenAPIGraphs } from './OpenAPIGraphs';

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { getUnusedSchemas } from './swagger-graph';
1+
export { OpenAPIGraphs } from './graph';

‎src/fetcher.ts‎ renamed to ‎src/openapi/fetcher.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import { existsSync, readdirSync } from 'fs';
99
import { resolve } from 'path';
10-
import { OpenAPIContent } from '../model';
11-
import { getOpenApisContent } from './openapi';
10+
import { OpenAPIContent } from '../../model';
11+
import { getOpenApisContent } from '.';
1212

1313
export async function fetcher(path: string): Promise<OpenAPIContent[]> {
1414
// Converts path to absolute

‎src/swagger-graph.ts‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎tests/graph/GraphsManager.test.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import { fetcher } from '../../src/fetcher';
2-
import { OpenAPIGraphsManager } from '../../src/graph';
1+
import { fetcher } from '../../src/openapi/fetcher';
2+
import { OpenAPIGraphs } from '../../src/graph';
33

44

5+
// TODO
56
test('Creates a graph from the petstore specification', async () => {
6-
const petstoreApis = await fetcher("tests/resources/petstore");
7-
const petstoreGraphs = new OpenAPIGraphsManager(petstoreApis);
8-
const unusedSchemas = petstoreGraphs.checkForUnusedSchemas();
9-
expect(unusedSchemas).toHaveLength(1);
10-
expect(unusedSchemas[0]).toMatchSnapshot({
11-
content: expect.any(Object),
12-
name: 'SchemaNotBeingUsed'
13-
})
147
});
158

169
// TODO

‎tests/graph/__snapshots__/GraphsManager.test.ts.snap‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎tests/graph/builder/GraphsBuilder.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RefType } from '../../../model';
2-
import { fetcher } from '../../../src/fetcher';
2+
import { fetcher } from '../../../src/openapi/fetcher';
33
import { OpenAPIGraph, OpenAPIGraphsBuilder } from '../../../src/graph';
44
import { RefEdge } from '../../../src/graph/edges';
55
import { SchemaNode } from '../../../src/graph/nodes/SchemaNode';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /