Skip to content

Commit 73a46bd

Browse files
authored
feat: support option to remove OAS extension during export (#20)
1 parent 8d6816e commit 73a46bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2207
-216
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ temp
55
coverage
66
.idea
77
.DS_store
8-
export
98
dist/
109
*.iml
1110
test/versions/

package-lock.json

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

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"update-lock-file": "update-lock-file @netcracker"
3232
},
3333
"dependencies": {
34-
"@netcracker/qubership-apihub-api-diff": "2.0.1",
35-
"@netcracker/qubership-apihub-api-unifier": "2.0.0",
36-
"@netcracker/qubership-apihub-json-crawl": "1.0.4",
34+
"@netcracker/qubership-apihub-api-diff": "dev",
35+
"@netcracker/qubership-apihub-api-unifier": "dev",
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",
@@ -53,6 +53,7 @@
5353
"@types/adm-zip": "0.5.7",
5454
"@types/jest": "^29.5.12",
5555
"@types/js-yaml": "^4.0.5",
56+
"@types/mime-types": "^3.0.0",
5657
"@types/node": "^18.0.0",
5758
"@types/object-hash": "^3.0.2",
5859
"@types/slug": "^5.0.3",
@@ -64,7 +65,9 @@
6465
"eslint-plugin-sort-exports": "^0.8.0",
6566
"jest": "^29.7.0",
6667
"jest-extended": "^4.0.2",
68+
"mime-types": "^3.0.1",
6769
"openapi-types": "^12.1.0",
70+
"rollup-plugin-copy": "^3.5.0",
6871
"ts-jest": "29.1.2",
6972
"ts-node": "^10.9.1",
7073
"tslint": "^6.1.3",

src/apitypes/graphql/graphql.document.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ export const buildGraphQLDocument: DocumentBuilder<GraphApiSchema> = async (pars
5252
}
5353

5454
export const dumpGraphQLDocument: DocumentDumper<GraphApiSchema> = (document) => {
55-
return new Blob([printGraphApi(document.data)], { type: 'text/plain' })
55+
if (document.data) {
56+
return new Blob([printGraphApi(document.data)], { type: 'text/plain' })
57+
}
58+
if (document.source) {
59+
return document.source
60+
}
61+
throw new Error(`Document ${document.fileId} has neither data nor source`)
5662
}

src/apitypes/rest/rest.consts.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616

1717
import { FILE_FORMAT_JSON, FILE_FORMAT_YAML, FILE_FORMAT_YML } from '../../consts'
18+
import { KeyOfConstType, ResolvedVersionDocument, ZippableDocument } from '../../types'
19+
import { TEXT_DOCUMENT_TYPE, TextDocumentType } from '../text'
1820

1921
export const REST_API_TYPE = 'rest' as const
2022

@@ -33,12 +35,22 @@ export const REST_DOCUMENT_TYPE = {
3335
SWAGGER: 'openapi-2-0',
3436
} as const
3537

38+
export type RestDocumentType = KeyOfConstType<typeof REST_DOCUMENT_TYPE>
39+
3640
export const REST_FILE_FORMAT = {
3741
YAML: FILE_FORMAT_YAML,
3842
YML: FILE_FORMAT_YML,
3943
JSON: FILE_FORMAT_JSON,
40-
}
44+
} as const
4145

4246
export const REST_KIND_KEY = 'x-api-kind'
4347

4448
export const DEPRECATED_META_KEY = 'x-deprecated-meta'
49+
50+
export function isRestDocument(document: ZippableDocument | ResolvedVersionDocument): boolean {
51+
return Object.values(REST_DOCUMENT_TYPE).includes(document.type as RestDocumentType)
52+
}
53+
54+
export function isTextDocument(document: ResolvedVersionDocument): boolean {
55+
return Object.values(TEXT_DOCUMENT_TYPE).includes(document.type as TextDocumentType)
56+
}

src/apitypes/rest/rest.parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const parseRestFile = async (fileId: string, source: Blob): Promise<TextF
5656
kind: FILE_KIND.TEXT,
5757
}
5858
}
59-
} else if ([REST_FILE_FORMAT.YAML, REST_FILE_FORMAT.YML].includes(extension) || !extension) {
59+
} else if (([REST_FILE_FORMAT.YAML, REST_FILE_FORMAT.YML] as string[]).includes(extension) || !extension) {
6060
if (/\s*?'?"?openapi'?"?\s*?:\s*?\|?\s*'?"?3\.[01]\..+?'?"?/g.test(sourceString)) {
6161
const data = YAML.load(sourceString) as OpenAPIV3.Document
6262

src/apitypes/text/text.consts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { KeyOfConstType } from '../../types'
1617

1718
export const TEXT_API_TYPE = 'text' as const
1819

1920
export const TEXT_DOCUMENT_TYPE = {
2021
MARKDOWN: 'markdown',
2122
} as const
2223

24+
export type TextDocumentType = KeyOfConstType<typeof TEXT_DOCUMENT_TYPE>
25+
2326
export const TEXT_FILE_FORMAT = {
2427
MD: 'md',
2528
} as const

src/apitypes/unknown/unknown.document.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { BuildConfigFile, DocumentBuilder, DocumentDumper, File, VersionDocument } from '../../types'
17+
import { BuildConfigFile, DocumentBuilder, DocumentDumper, SourceFile, VersionDocument } from '../../types'
1818
import { createBundlingErrorHandler, getBundledFileDataWithDependencies, getDocumentTitle } from '../../utils'
1919
import { FILE_FORMAT } from '../../consts'
2020

@@ -57,7 +57,7 @@ export const buildUnknownDocument: DocumentBuilder<string> = async (parsedFile,
5757
}
5858
}
5959

60-
export const buildBinaryDocument: (parsedFile: File, file: BuildConfigFile) => Promise<VersionDocument> = async (parsedFile, file) => {
60+
export const buildBinaryDocument: (parsedFile: SourceFile, file: BuildConfigFile) => Promise<VersionDocument> = async (parsedFile, file) => {
6161
const { fileId, slug = '', publish, ...metadata } = file
6262
const { type, format, source } = parsedFile
6363

0 commit comments

Comments
 (0)