Skip to content

Commit 1ec70e7

Browse files
committed
feat: support doc and version export to html
1 parent 85ed0aa commit 1ec70e7

File tree

25 files changed

+680
-145
lines changed

25 files changed

+680
-145
lines changed

package-lock.json

Lines changed: 185 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"dependencies": {
3434
"@netcracker/qubership-apihub-api-diff": "feature-remove-oas-extensions",
3535
"@netcracker/qubership-apihub-api-unifier": "feature-remove-oas-extensions",
36-
"@netcracker/qubership-apihub-json-crawl": "1.0.4",
3736
"@netcracker/qubership-apihub-graphapi": "1.0.8",
37+
"@netcracker/qubership-apihub-json-crawl": "1.0.4",
3838
"adm-zip": "0.5.10",
3939
"ajv": "^8.12.0",
4040
"ajv-formats": "^2.1.1",
@@ -50,9 +50,11 @@
5050
},
5151
"devDependencies": {
5252
"@netcracker/qubership-apihub-npm-gitflow": "3.0.1",
53+
"@rollup/plugin-url": "^8.0.2",
5354
"@types/adm-zip": "0.5.7",
5455
"@types/jest": "^29.5.12",
5556
"@types/js-yaml": "^4.0.5",
57+
"@types/mime-types": "^3.0.0",
5658
"@types/node": "^18.0.0",
5759
"@types/object-hash": "^3.0.2",
5860
"@types/slug": "^5.0.3",
@@ -64,7 +66,9 @@
6466
"eslint-plugin-sort-exports": "^0.8.0",
6567
"jest": "^29.7.0",
6668
"jest-extended": "^4.0.2",
69+
"mime-types": "^3.0.1",
6770
"openapi-types": "^12.1.0",
71+
"rollup-plugin-copy": "^3.5.0",
6872
"ts-jest": "29.1.2",
6973
"ts-node": "^10.9.1",
7074
"tslint": "^6.1.3",

src/apitypes/rest/rest.consts.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { FILE_FORMAT_JSON, FILE_FORMAT_YAML, FILE_FORMAT_YML } from '../../consts'
18+
import { KeyOfConstType, ResolvedVersionDocument } from '../../types'
1819

1920
export const REST_API_TYPE = 'rest' as const
2021

@@ -33,6 +34,8 @@ export const REST_DOCUMENT_TYPE = {
3334
SWAGGER: 'openapi-2-0',
3435
} as const
3536

37+
export type RestDocumentType = KeyOfConstType<typeof REST_DOCUMENT_TYPE>
38+
3639
export const REST_FILE_FORMAT = {
3740
YAML: FILE_FORMAT_YAML,
3841
YML: FILE_FORMAT_YML,
@@ -42,3 +45,7 @@ export const REST_FILE_FORMAT = {
4245
export const REST_KIND_KEY = 'x-api-kind'
4346

4447
export const DEPRECATED_META_KEY = 'x-deprecated-meta'
48+
49+
export function isRestDocument(document: ResolvedVersionDocument): boolean {
50+
return Object.values(REST_DOCUMENT_TYPE).includes(document.type as RestDocumentType)
51+
}

src/builder.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import {
3030
ResolvedGroupDocuments,
3131
ResolvedOperations,
3232
ResolvedVersionDocuments,
33-
ResolvedVersionOperationsHashMap,
3433
VersionId,
3534
VersionsComparison,
35+
ZippableDocument,
3636
} from './types'
3737
import {
3838
ApiBuilder,
@@ -74,7 +74,7 @@ import { BuildStrategy, ChangelogStrategy, DocumentGroupStrategy, PrefixGroupsCh
7474
import { BuilderStrategyContext } from './builder-strategy'
7575
import { MergedDocumentGroupStrategy } from './strategies/merged-document-group.strategy'
7676
import { asyncDebugPerformance } from './utils/logs'
77-
import { ExportRestOperationsGroupStrategy } from './strategies/rest-operations-group.strategy'
77+
// import { ExportRestOperationsGroupStrategy } from './strategies/rest-operations-group.strategy'
7878
import { ExportVersionStrategy } from './strategies/export-version.strategy'
7979
import { ExportRestDocumentStrategy } from './strategies/export-rest-document.strategy'
8080

@@ -85,7 +85,7 @@ export const DEFAULT_RUN_OPTIONS: BuilderRunOptions = {
8585
export class PackageVersionBuilder implements IPackageVersionBuilder {
8686
apiBuilders: ApiBuilder[] = []
8787
documents = new Map<string, VersionDocument>()
88-
exportDocuments: VersionDocument[] = []
88+
exportDocuments: ZippableDocument[] = []
8989
exportFileName: string = ''
9090
operations = new Map<string, ApiOperation>()
9191
comparisons: VersionsComparison[] = []
@@ -263,6 +263,7 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
263263
// }
264264

265265
if (buildType === BUILD_TYPE.EXPORT_REST_OPERATIONS_GROUP) {
266+
const { ExportRestOperationsGroupStrategy } = await import('./strategies/rest-operations-group.strategy')
266267
builderStrategyContext.setStrategy(new ExportRestOperationsGroupStrategy())
267268
}
268269

@@ -294,17 +295,17 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
294295
version: VersionId,
295296
packageId: PackageId,
296297
slug: string,
297-
): Promise<File | null> {
298+
): Promise<File> {
298299
if (!this.params.resolvers.rawDocumentResolver) {
299-
return null
300+
throw new Error('rawDocumentResolver is not provided')
300301
}
301302

302-
const source = await this.params.resolvers.rawDocumentResolver(version, packageId, slug)
303-
if (!source) {
304-
return null
303+
const document = await this.params.resolvers.rawDocumentResolver(version, packageId, slug)
304+
if (!document) {
305+
throw new Error(`Raw document ${slug} is missing`)
305306
}
306307

307-
return source
308+
return document
308309
}
309310

310311
async versionComparisonResolver(

0 commit comments

Comments
 (0)