From 6795d42a5952510c99e3167d27a639075d3e63ce Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Thu, 5 Oct 2023 17:19:03 -0700 Subject: [PATCH] feat(esm): flipping on our ESM ESLint config in all packages (#814) * feat: enabling our esm eslint config on `oas` * feat: enabling our esm eslint config on `oas-extensions` * feat: enabling our esm eslint config on `oas-normalize` * fix: cleaning up the oas-to-har eslint config --- .eslintrc | 4 +++ packages/oas-extensions/.eslintrc | 2 -- packages/oas-extensions/test/index.test.ts | 2 +- packages/oas-extensions/tsup.config.ts | 2 +- packages/oas-normalize/.eslintrc | 6 +--- packages/oas-normalize/src/index.ts | 4 +-- packages/oas-normalize/test/index.test.ts | 5 ++-- packages/oas-normalize/tsup.config.ts | 2 +- packages/oas-to-har/.eslintrc | 2 -- packages/oas/.eslintrc | 14 ++++++++-- packages/oas/src/analyzer/index.ts | 6 ++-- packages/oas/src/analyzer/queries/openapi.ts | 6 ++-- packages/oas/src/analyzer/queries/readme.ts | 4 +-- packages/oas/src/index.ts | 12 ++++---- .../oas/src/lib/dedupe-common-parameters.ts | 2 +- packages/oas/src/lib/get-auth.ts | 2 +- .../oas/src/lib/get-mediatype-examples.ts | 6 ++-- packages/oas/src/lib/get-user-variable.ts | 2 +- packages/oas/src/lib/helpers.ts | 2 +- .../oas/src/lib/openapi-to-json-schema.ts | 6 ++-- packages/oas/src/lib/reducer.ts | 4 +-- packages/oas/src/operation.ts | 28 +++++++++---------- .../src/operation/get-callback-examples.ts | 4 +-- .../get-parameters-as-json-schema.ts | 14 +++++----- .../src/operation/get-requestbody-examples.ts | 4 +-- .../operation/get-response-as-json-schema.ts | 12 ++++---- .../src/operation/get-response-examples.ts | 8 +++--- packages/oas/src/samples/index.ts | 4 +-- packages/oas/src/samples/utils.ts | 4 +-- packages/oas/src/utils.ts | 6 ++-- packages/oas/test/__fixtures__/create-oas.ts | 4 +-- packages/oas/test/__fixtures__/json-schema.ts | 2 +- .../test/__fixtures__/json-stringify-clean.js | 3 -- .../test/__fixtures__/json-stringify-clean.ts | 3 ++ packages/oas/test/analyzer/index.test.ts | 4 +-- .../oas/test/analyzer/queries/openapi.test.ts | 4 +-- .../oas/test/analyzer/queries/readme.test.ts | 4 +-- packages/oas/test/index.test.ts | 8 +++--- .../test/lib/find-schema-definition.test.ts | 2 +- packages/oas/test/lib/get-auth.test.ts | 4 +-- .../oas/test/lib/get-user-variable.test.ts | 2 +- .../oas/test/lib/matches-mimetype.test.ts | 2 +- .../test/lib/openapi-to-json-schema.test.ts | 10 +++---- .../openapi-to-json-schema/default.test.ts | 6 ++-- .../openapi-to-json-schema/required.test.ts | 6 ++-- packages/oas/test/lib/reducer.test.ts | 2 +- packages/oas/test/operation.test.ts | 6 ++-- .../operation/get-callback-examples.test.ts | 4 +-- .../get-parameters-as-json-schema.test.ts | 6 ++-- .../get-requestbody-examples.test.ts | 4 +-- .../get-response-as-json-schema.test.ts | 8 +++--- .../operation/get-response-examples.test.ts | 8 +++--- packages/oas/test/samples/index.test.ts | 4 +-- packages/oas/test/ts-quirks.test.js | 2 +- packages/oas/test/utils.test.ts | 2 +- packages/oas/tsup.config.ts | 2 +- 56 files changed, 149 insertions(+), 142 deletions(-) create mode 100644 .eslintrc delete mode 100644 packages/oas/test/__fixtures__/json-stringify-clean.js create mode 100644 packages/oas/test/__fixtures__/json-stringify-clean.ts diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..586e6d31 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,4 @@ +{ + "extends": ["@readme/eslint-config", "@readme/eslint-config/typescript", "@readme/eslint-config/esm"], + "root": true +} diff --git a/packages/oas-extensions/.eslintrc b/packages/oas-extensions/.eslintrc index 2b9eec70..3d8dbf2e 100644 --- a/packages/oas-extensions/.eslintrc +++ b/packages/oas-extensions/.eslintrc @@ -1,6 +1,4 @@ { - "extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"], - "root": true, "rules": { "@typescript-eslint/consistent-type-imports": "error", "@typescript-eslint/explicit-module-boundary-types": "off" diff --git a/packages/oas-extensions/test/index.test.ts b/packages/oas-extensions/test/index.test.ts index d34924df..ceb4f800 100644 --- a/packages/oas-extensions/test/index.test.ts +++ b/packages/oas-extensions/test/index.test.ts @@ -2,7 +2,7 @@ import petstore from '@readme/oas-examples/3.0/json/petstore.json'; import Oas from 'oas'; import { describe, beforeEach, it, expect } from 'vitest'; -import * as extensions from '../src'; +import * as extensions from '../src/index.js'; describe('oas-extensions', () => { it.each([ diff --git a/packages/oas-extensions/tsup.config.ts b/packages/oas-extensions/tsup.config.ts index 4e236b9f..6412d76a 100644 --- a/packages/oas-extensions/tsup.config.ts +++ b/packages/oas-extensions/tsup.config.ts @@ -3,7 +3,7 @@ import type { Options } from 'tsup'; // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig } from 'tsup'; -import config from '../../tsup.config'; +import config from '../../tsup.config.js'; export default defineConfig((options: Options) => ({ ...options, diff --git a/packages/oas-normalize/.eslintrc b/packages/oas-normalize/.eslintrc index a035c5fb..5b14e9b7 100644 --- a/packages/oas-normalize/.eslintrc +++ b/packages/oas-normalize/.eslintrc @@ -1,13 +1,9 @@ { - "extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"], - "root": true, "rules": { "@typescript-eslint/no-explicit-any": "off", "camelcase": ["error", { "allow": ["OpenAPIV3_1"] }], - "no-case-declarations": "off", - - "unicorn/prefer-node-protocol": "error" + "no-case-declarations": "off" } } diff --git a/packages/oas-normalize/src/index.ts b/packages/oas-normalize/src/index.ts index 844b5e1a..5a4c80f0 100644 --- a/packages/oas-normalize/src/index.ts +++ b/packages/oas-normalize/src/index.ts @@ -1,4 +1,4 @@ -import type { Options } from './lib/types'; +import type { Options } from './lib/types.js'; import type { OpenAPI } from 'openapi-types'; import fs from 'node:fs'; @@ -7,7 +7,7 @@ import openapiParser from '@readme/openapi-parser'; import postmanToOpenAPI from '@readme/postman-to-openapi'; import converter from 'swagger2openapi'; -import * as utils from './lib/utils'; +import * as utils from './lib/utils.js'; export default class OASNormalize { cache: { diff --git a/packages/oas-normalize/test/index.test.ts b/packages/oas-normalize/test/index.test.ts index 9478663b..34510e17 100644 --- a/packages/oas-normalize/test/index.test.ts +++ b/packages/oas-normalize/test/index.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable unicorn/prefer-module -- We use `require.resolve` for reading YAML fixtures. */ import type { OpenAPIV3 } from 'openapi-types'; import fs from 'node:fs'; @@ -6,8 +7,8 @@ import path from 'node:path'; import fetchMock from 'fetch-mock'; import { describe, afterEach, beforeAll, beforeEach, it, expect } from 'vitest'; -import OASNormalize from '../src'; -import { getAPIDefinitionType, isAPIDefinition, isOpenAPI, isPostman, isSwagger } from '../src/lib/utils'; +import OASNormalize from '../src/index.js'; +import { getAPIDefinitionType, isAPIDefinition, isOpenAPI, isPostman, isSwagger } from '../src/lib/utils.js'; function cloneObject(obj) { return JSON.parse(JSON.stringify(obj)); diff --git a/packages/oas-normalize/tsup.config.ts b/packages/oas-normalize/tsup.config.ts index bf70088c..c373de38 100644 --- a/packages/oas-normalize/tsup.config.ts +++ b/packages/oas-normalize/tsup.config.ts @@ -3,7 +3,7 @@ import type { Options } from 'tsup'; // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig } from 'tsup'; -import config from '../../tsup.config'; +import config from '../../tsup.config.js'; export default defineConfig((options: Options) => ({ ...options, diff --git a/packages/oas-to-har/.eslintrc b/packages/oas-to-har/.eslintrc index fd63b5c7..fcc4ae55 100644 --- a/packages/oas-to-har/.eslintrc +++ b/packages/oas-to-har/.eslintrc @@ -1,6 +1,4 @@ { - "extends": ["@readme/eslint-config", "@readme/eslint-config/typescript", "@readme/eslint-config/esm"], - "root": true, "rules": { // `any` types are fine because we're dealing with a lot of unknown data. "@typescript-eslint/no-explicit-any": "off", diff --git a/packages/oas/.eslintrc b/packages/oas/.eslintrc index dc5cf598..a4801045 100644 --- a/packages/oas/.eslintrc +++ b/packages/oas/.eslintrc @@ -1,6 +1,4 @@ { - "extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"], - "root": true, "rules": { "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-use-before-define": ["error", { "classes": false }], @@ -8,6 +6,18 @@ "camelcase": "off", "max-classes-per-file": "off", + + "node/no-extraneous-import": [ + "error", + { + "allowModules": [ + // When we use this module we only load TS types which come from our `@types/json-schema` + // dependency. + "json-schema" + ] + } + ], + "no-param-reassign": "off", "no-underscore-dangle": [ diff --git a/packages/oas/src/analyzer/index.ts b/packages/oas/src/analyzer/index.ts index f147cca2..a02a40c1 100644 --- a/packages/oas/src/analyzer/index.ts +++ b/packages/oas/src/analyzer/index.ts @@ -1,7 +1,7 @@ -import type { OASDocument } from '../rmoas.types'; +import type { OASDocument } from '../rmoas.types.js'; -import * as OPENAPI_QUERIES from './queries/openapi'; -import * as README_QUERIES from './queries/readme'; +import * as OPENAPI_QUERIES from './queries/openapi.js'; +import * as README_QUERIES from './queries/readme.js'; export interface OASAnalysisFeature { locations: string[]; diff --git a/packages/oas/src/analyzer/queries/openapi.ts b/packages/oas/src/analyzer/queries/openapi.ts index a6444ce6..e382e135 100644 --- a/packages/oas/src/analyzer/queries/openapi.ts +++ b/packages/oas/src/analyzer/queries/openapi.ts @@ -1,7 +1,7 @@ -import type { OASDocument } from '../../rmoas.types'; +import type { OASDocument } from '../../rmoas.types.js'; -import Oas from '../..'; -import { query, refizePointer } from '../util'; +import Oas from '../../index.js'; +import { query, refizePointer } from '../util.js'; /** * Determine if a given API definition uses the `additionalProperties` schema property. diff --git a/packages/oas/src/analyzer/queries/readme.ts b/packages/oas/src/analyzer/queries/readme.ts index 676bf3e7..9ee2ec8a 100644 --- a/packages/oas/src/analyzer/queries/readme.ts +++ b/packages/oas/src/analyzer/queries/readme.ts @@ -1,6 +1,6 @@ -import type { OASDocument } from '../../rmoas.types'; +import type { OASDocument } from '../../rmoas.types.js'; -import { query, refizePointer } from '../util'; +import { query, refizePointer } from '../util.js'; /** * Determine if a given API definition is using our `x-default` extension for defining auth diff --git a/packages/oas/src/index.ts b/packages/oas/src/index.ts index b953727a..6438f899 100644 --- a/packages/oas/src/index.ts +++ b/packages/oas/src/index.ts @@ -1,15 +1,15 @@ -import type * as RMOAS from './rmoas.types'; +import type * as RMOAS from './rmoas.types.js'; import type { OpenAPIV3_1 } from 'openapi-types'; import type { MatchResult } from 'path-to-regexp'; import $RefParser from '@readme/json-schema-ref-parser'; import { pathToRegexp, match } from 'path-to-regexp'; -import getAuth from './lib/get-auth'; -import getUserVariable from './lib/get-user-variable'; -import { isPrimitive } from './lib/helpers'; -import Operation, { Webhook } from './operation'; -import utils from './utils'; +import getAuth from './lib/get-auth.js'; +import getUserVariable from './lib/get-user-variable.js'; +import { isPrimitive } from './lib/helpers.js'; +import Operation, { Webhook } from './operation.js'; +import utils from './utils.js'; interface PathMatch { match?: MatchResult; diff --git a/packages/oas/src/lib/dedupe-common-parameters.ts b/packages/oas/src/lib/dedupe-common-parameters.ts index 94a2ff0f..1d87b638 100644 --- a/packages/oas/src/lib/dedupe-common-parameters.ts +++ b/packages/oas/src/lib/dedupe-common-parameters.ts @@ -1,4 +1,4 @@ -import * as RMOAS from '../rmoas.types'; +import * as RMOAS from '../rmoas.types.js'; /** * With an array of common parameters filter down them to what isn't already present in a list of diff --git a/packages/oas/src/lib/get-auth.ts b/packages/oas/src/lib/get-auth.ts index 1048b55f..67fc114d 100644 --- a/packages/oas/src/lib/get-auth.ts +++ b/packages/oas/src/lib/get-auth.ts @@ -1,4 +1,4 @@ -import type * as RMOAS from '../rmoas.types'; +import type * as RMOAS from '../rmoas.types.js'; import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'; type authKey = null | unknown | { password: string | number; user: string | number }; diff --git a/packages/oas/src/lib/get-mediatype-examples.ts b/packages/oas/src/lib/get-mediatype-examples.ts index 3082ca88..7ff26508 100644 --- a/packages/oas/src/lib/get-mediatype-examples.ts +++ b/packages/oas/src/lib/get-mediatype-examples.ts @@ -1,8 +1,8 @@ -import type * as RMOAS from '../rmoas.types'; +import type * as RMOAS from '../rmoas.types.js'; -import sampleFromSchema from '../samples'; +import sampleFromSchema from '../samples/index.js'; -import matchesMimeType from './matches-mimetype'; +import matchesMimeType from './matches-mimetype.js'; export interface MediaTypeExample { description?: string; diff --git a/packages/oas/src/lib/get-user-variable.ts b/packages/oas/src/lib/get-user-variable.ts index 3de7e839..92a48404 100644 --- a/packages/oas/src/lib/get-user-variable.ts +++ b/packages/oas/src/lib/get-user-variable.ts @@ -1,4 +1,4 @@ -import type * as RMOAS from '../rmoas.types'; +import type * as RMOAS from '../rmoas.types.js'; /** * Retrieve a user variable off of a given user. diff --git a/packages/oas/src/lib/helpers.ts b/packages/oas/src/lib/helpers.ts index e679c118..81154ed2 100644 --- a/packages/oas/src/lib/helpers.ts +++ b/packages/oas/src/lib/helpers.ts @@ -1,4 +1,4 @@ -import type { SchemaObject } from '../rmoas.types'; +import type { SchemaObject } from '../rmoas.types.js'; export function hasSchemaType(schema: SchemaObject, discriminator: 'array' | 'object') { if (Array.isArray(schema.type)) { diff --git a/packages/oas/src/lib/openapi-to-json-schema.ts b/packages/oas/src/lib/openapi-to-json-schema.ts index 2f52ecad..2a8d4ce8 100644 --- a/packages/oas/src/lib/openapi-to-json-schema.ts +++ b/packages/oas/src/lib/openapi-to-json-schema.ts @@ -1,5 +1,5 @@ /* eslint-disable no-continue */ -import type { SchemaObject } from '../rmoas.types'; +import type { SchemaObject } from '../rmoas.types.js'; import type { JSONSchema7TypeName } from 'json-schema'; import type { OpenAPIV3_1 } from 'openapi-types'; @@ -7,9 +7,9 @@ import mergeJSONSchemaAllOf from 'json-schema-merge-allof'; import jsonpointer from 'jsonpointer'; import removeUndefinedObjects from 'remove-undefined-objects'; -import * as RMOAS from '../rmoas.types'; +import * as RMOAS from '../rmoas.types.js'; -import { hasSchemaType, isObject, isPrimitive } from './helpers'; +import { hasSchemaType, isObject, isPrimitive } from './helpers.js'; /** * This list has been pulled from `openapi-schema-to-json-schema` but been slightly modified to fit diff --git a/packages/oas/src/lib/reducer.ts b/packages/oas/src/lib/reducer.ts index da042e5e..4b0a98c4 100644 --- a/packages/oas/src/lib/reducer.ts +++ b/packages/oas/src/lib/reducer.ts @@ -1,9 +1,9 @@ -import type { ComponentsObject, HttpMethods, OASDocument, TagObject } from '../rmoas.types'; +import type { ComponentsObject, HttpMethods, OASDocument, TagObject } from '../rmoas.types.js'; import jsonPointer from 'jsonpointer'; import { getAPIDefinitionType } from 'oas-normalize/lib/utils'; -import { query } from '../analyzer/util'; +import { query } from '../analyzer/util.js'; export interface ReducerOptions { /** A key-value object of path + method combinations to reduce by. */ diff --git a/packages/oas/src/operation.ts b/packages/oas/src/operation.ts index 093a7409..2e1be2a9 100644 --- a/packages/oas/src/operation.ts +++ b/packages/oas/src/operation.ts @@ -1,19 +1,19 @@ -import type { CallbackExamples } from './operation/get-callback-examples'; -import type { getParametersAsJSONSchemaOptions } from './operation/get-parameters-as-json-schema'; -import type { RequestBodyExamples } from './operation/get-requestbody-examples'; -import type { ResponseExamples } from './operation/get-response-examples'; +import type { CallbackExamples } from './operation/get-callback-examples.js'; +import type { getParametersAsJSONSchemaOptions } from './operation/get-parameters-as-json-schema.js'; +import type { RequestBodyExamples } from './operation/get-requestbody-examples.js'; +import type { ResponseExamples } from './operation/get-response-examples.js'; import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'; -import dedupeCommonParameters from './lib/dedupe-common-parameters'; -import findSchemaDefinition from './lib/find-schema-definition'; -import matchesMimeType from './lib/matches-mimetype'; -import getCallbackExamples from './operation/get-callback-examples'; -import getParametersAsJSONSchema from './operation/get-parameters-as-json-schema'; -import getRequestBodyExamples from './operation/get-requestbody-examples'; -import getResponseAsJSONSchema from './operation/get-response-as-json-schema'; -import getResponseExamples from './operation/get-response-examples'; -import * as RMOAS from './rmoas.types'; -import utils from './utils'; +import dedupeCommonParameters from './lib/dedupe-common-parameters.js'; +import findSchemaDefinition from './lib/find-schema-definition.js'; +import matchesMimeType from './lib/matches-mimetype.js'; +import getCallbackExamples from './operation/get-callback-examples.js'; +import getParametersAsJSONSchema from './operation/get-parameters-as-json-schema.js'; +import getRequestBodyExamples from './operation/get-requestbody-examples.js'; +import getResponseAsJSONSchema from './operation/get-response-as-json-schema.js'; +import getResponseExamples from './operation/get-response-examples.js'; +import * as RMOAS from './rmoas.types.js'; +import utils from './utils.js'; type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey'; diff --git a/packages/oas/src/operation/get-callback-examples.ts b/packages/oas/src/operation/get-callback-examples.ts index 6953e4e9..5d67e79b 100644 --- a/packages/oas/src/operation/get-callback-examples.ts +++ b/packages/oas/src/operation/get-callback-examples.ts @@ -1,6 +1,6 @@ -import type * as RMOAS from '../rmoas.types'; +import type * as RMOAS from '../rmoas.types.js'; -import getResponseExamples from './get-response-examples'; +import getResponseExamples from './get-response-examples.js'; export type CallbackExamples = { example: unknown; diff --git a/packages/oas/src/operation/get-parameters-as-json-schema.ts b/packages/oas/src/operation/get-parameters-as-json-schema.ts index 9536bd7a..ae5671b7 100644 --- a/packages/oas/src/operation/get-parameters-as-json-schema.ts +++ b/packages/oas/src/operation/get-parameters-as-json-schema.ts @@ -1,12 +1,12 @@ -import type { toJSONSchemaOptions } from '../lib/openapi-to-json-schema'; -import type Operation from '../operation'; -import type { ComponentsObject, ExampleObject, OASDocument, ParameterObject, SchemaObject } from '../rmoas.types'; +import type { toJSONSchemaOptions } from '../lib/openapi-to-json-schema.js'; +import type Operation from '../operation.js'; +import type { ComponentsObject, ExampleObject, OASDocument, ParameterObject, SchemaObject } from '../rmoas.types.js'; import type { OpenAPIV3_1 } from 'openapi-types'; -import cloneObject from '../lib/clone-object'; -import { isPrimitive } from '../lib/helpers'; -import matchesMimetype from '../lib/matches-mimetype'; -import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema'; +import cloneObject from '../lib/clone-object.js'; +import { isPrimitive } from '../lib/helpers.js'; +import matchesMimetype from '../lib/matches-mimetype.js'; +import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema.js'; export interface SchemaWrapper { $schema?: string; diff --git a/packages/oas/src/operation/get-requestbody-examples.ts b/packages/oas/src/operation/get-requestbody-examples.ts index 548b8bf4..eb6bccc7 100644 --- a/packages/oas/src/operation/get-requestbody-examples.ts +++ b/packages/oas/src/operation/get-requestbody-examples.ts @@ -1,6 +1,6 @@ -import type * as RMOAS from '../rmoas.types'; +import type * as RMOAS from '../rmoas.types.js'; -import getMediaTypeExamples from '../lib/get-mediatype-examples'; +import getMediaTypeExamples from '../lib/get-mediatype-examples.js'; export type RequestBodyExamples = { examples: any; diff --git a/packages/oas/src/operation/get-response-as-json-schema.ts b/packages/oas/src/operation/get-response-as-json-schema.ts index 934818e5..8382ea94 100644 --- a/packages/oas/src/operation/get-response-as-json-schema.ts +++ b/packages/oas/src/operation/get-response-as-json-schema.ts @@ -1,4 +1,4 @@ -import type Operation from '../operation'; +import type Operation from '../operation.js'; import type { ComponentsObject, MediaTypeObject, @@ -6,12 +6,12 @@ import type { ResponseObject, SchemaObject, HeaderObject, -} from '../rmoas.types'; +} from '../rmoas.types.js'; -import cloneObject from '../lib/clone-object'; -import { isPrimitive } from '../lib/helpers'; -import matches from '../lib/matches-mimetype'; -import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema'; +import cloneObject from '../lib/clone-object.js'; +import { isPrimitive } from '../lib/helpers.js'; +import matches from '../lib/matches-mimetype.js'; +import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema.js'; const isJSON = matches.json; diff --git a/packages/oas/src/operation/get-response-examples.ts b/packages/oas/src/operation/get-response-examples.ts index b0a2b70e..ab33de8a 100644 --- a/packages/oas/src/operation/get-response-examples.ts +++ b/packages/oas/src/operation/get-response-examples.ts @@ -1,8 +1,8 @@ -import type { MediaTypeExample } from '../lib/get-mediatype-examples'; -import type * as RMOAS from '../rmoas.types'; +import type { MediaTypeExample } from '../lib/get-mediatype-examples.js'; +import type * as RMOAS from '../rmoas.types.js'; -import getMediaTypeExamples from '../lib/get-mediatype-examples'; -import { isRef } from '../rmoas.types'; +import getMediaTypeExamples from '../lib/get-mediatype-examples.js'; +import { isRef } from '../rmoas.types.js'; export type ResponseExamples = { mediaTypes: Record; diff --git a/packages/oas/src/samples/index.ts b/packages/oas/src/samples/index.ts index d68836db..e79ad50a 100644 --- a/packages/oas/src/samples/index.ts +++ b/packages/oas/src/samples/index.ts @@ -4,12 +4,12 @@ * @license Apache-2.0 * @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/samples/fn.js} */ -import type * as RMOAS from '../rmoas.types'; +import type * as RMOAS from '../rmoas.types.js'; import mergeJSONSchemaAllOf from 'json-schema-merge-allof'; import memoize from 'memoizee'; -import { objectify, usesPolymorphism, isFunc, normalizeArray, deeplyStripKey } from './utils'; +import { objectify, usesPolymorphism, isFunc, normalizeArray, deeplyStripKey } from './utils.js'; const sampleDefaults = (genericSample: string | number | boolean) => { return (schema: RMOAS.SchemaObject): typeof genericSample => diff --git a/packages/oas/src/samples/utils.ts b/packages/oas/src/samples/utils.ts index d91a556b..2d760f5a 100644 --- a/packages/oas/src/samples/utils.ts +++ b/packages/oas/src/samples/utils.ts @@ -4,9 +4,9 @@ * @license Apache-2.0 * @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/utils.js} */ -import type * as RMOAS from '../rmoas.types'; +import type * as RMOAS from '../rmoas.types.js'; -import { isObject } from '../lib/helpers'; +import { isObject } from '../lib/helpers.js'; export function usesPolymorphism(schema: RMOAS.SchemaObject) { if (schema.oneOf) { diff --git a/packages/oas/src/utils.ts b/packages/oas/src/utils.ts index f157a27c..06d99a22 100644 --- a/packages/oas/src/utils.ts +++ b/packages/oas/src/utils.ts @@ -1,6 +1,6 @@ -import findSchemaDefinition from './lib/find-schema-definition'; -import matchesMimeType from './lib/matches-mimetype'; -import { types as jsonSchemaTypes } from './operation/get-parameters-as-json-schema'; +import findSchemaDefinition from './lib/find-schema-definition.js'; +import matchesMimeType from './lib/matches-mimetype.js'; +import { types as jsonSchemaTypes } from './operation/get-parameters-as-json-schema.js'; const supportedMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']); diff --git a/packages/oas/test/__fixtures__/create-oas.ts b/packages/oas/test/__fixtures__/create-oas.ts index eff22610..a95621d5 100644 --- a/packages/oas/test/__fixtures__/create-oas.ts +++ b/packages/oas/test/__fixtures__/create-oas.ts @@ -1,6 +1,6 @@ -import type * as RMOAS from '../../src/rmoas.types'; +import type * as RMOAS from '../../src/rmoas.types.js'; -import Oas from '../../src'; +import Oas from '../../src/index.js'; /** * @param operation Operation to create a fake API definition and Oas instance for. diff --git a/packages/oas/test/__fixtures__/json-schema.ts b/packages/oas/test/__fixtures__/json-schema.ts index 6003475d..5cc6ce64 100644 --- a/packages/oas/test/__fixtures__/json-schema.ts +++ b/packages/oas/test/__fixtures__/json-schema.ts @@ -1,4 +1,4 @@ -import type { SchemaObject } from '../../src/rmoas.types'; +import type { SchemaObject } from '../../src/rmoas.types.js'; const SCHEMA_SCENARIOS = { 'array of primitives': (props, allowEmptyValue) => { diff --git a/packages/oas/test/__fixtures__/json-stringify-clean.js b/packages/oas/test/__fixtures__/json-stringify-clean.js deleted file mode 100644 index 24c8bd6a..00000000 --- a/packages/oas/test/__fixtures__/json-stringify-clean.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function jsonStringifyClean(obj) { - return JSON.stringify(obj, undefined, 2); -} diff --git a/packages/oas/test/__fixtures__/json-stringify-clean.ts b/packages/oas/test/__fixtures__/json-stringify-clean.ts new file mode 100644 index 00000000..4916a9c4 --- /dev/null +++ b/packages/oas/test/__fixtures__/json-stringify-clean.ts @@ -0,0 +1,3 @@ +export default function jsonStringifyClean(obj: any) { + return JSON.stringify(obj, undefined, 2); +} diff --git a/packages/oas/test/analyzer/index.test.ts b/packages/oas/test/analyzer/index.test.ts index 5608bed8..21e130c5 100644 --- a/packages/oas/test/analyzer/index.test.ts +++ b/packages/oas/test/analyzer/index.test.ts @@ -1,8 +1,8 @@ -import type { OASDocument } from '../../src/rmoas.types'; +import type { OASDocument } from '../../src/rmoas.types.js'; import { describe, beforeAll, it, expect } from 'vitest'; -import analyzer from '../../src/analyzer'; +import analyzer from '../../src/analyzer/index.js'; let petstore: OASDocument; diff --git a/packages/oas/test/analyzer/queries/openapi.test.ts b/packages/oas/test/analyzer/queries/openapi.test.ts index 4a5bca02..f9cc95b9 100644 --- a/packages/oas/test/analyzer/queries/openapi.test.ts +++ b/packages/oas/test/analyzer/queries/openapi.test.ts @@ -1,8 +1,8 @@ -import type { OASDocument } from '../../../src/rmoas.types'; +import type { OASDocument } from '../../../src/rmoas.types.js'; import { describe, beforeAll, expect, it } from 'vitest'; -import * as QUERIES from '../../../src/analyzer/queries/openapi'; +import * as QUERIES from '../../../src/analyzer/queries/openapi.js'; function loadSpec(r: any) { return r.default as unknown as OASDocument; diff --git a/packages/oas/test/analyzer/queries/readme.test.ts b/packages/oas/test/analyzer/queries/readme.test.ts index 98934a89..5e71d4ee 100644 --- a/packages/oas/test/analyzer/queries/readme.test.ts +++ b/packages/oas/test/analyzer/queries/readme.test.ts @@ -1,8 +1,8 @@ -import type { OASDocument } from '../../../src/rmoas.types'; +import type { OASDocument } from '../../../src/rmoas.types.js'; import { describe, beforeAll, expect, it } from 'vitest'; -import * as QUERIES from '../../../src/analyzer/queries/readme'; +import * as QUERIES from '../../../src/analyzer/queries/readme.js'; function loadSpec(r: any) { return r.default as unknown as OASDocument; diff --git a/packages/oas/test/index.test.ts b/packages/oas/test/index.test.ts index f3726923..a9d3d5b9 100644 --- a/packages/oas/test/index.test.ts +++ b/packages/oas/test/index.test.ts @@ -1,11 +1,11 @@ -import type * as RMOAS from '../src/rmoas.types'; +import type * as RMOAS from '../src/rmoas.types.js'; import petstoreSpec from '@readme/oas-examples/3.0/json/petstore.json'; import { beforeAll, describe, test, it, expect, vi } from 'vitest'; -import Oas from '../src'; -import Operation, { Webhook } from '../src/operation'; -import utils from '../src/utils'; +import Oas from '../src/index.js'; +import Operation, { Webhook } from '../src/operation.js'; +import utils from '../src/utils.js'; let petstore: Oas; let webhooks: Oas; diff --git a/packages/oas/test/lib/find-schema-definition.test.ts b/packages/oas/test/lib/find-schema-definition.test.ts index b1edaf51..3261c74a 100644 --- a/packages/oas/test/lib/find-schema-definition.test.ts +++ b/packages/oas/test/lib/find-schema-definition.test.ts @@ -1,7 +1,7 @@ import petstore from '@readme/oas-examples/3.0/json/petstore.json'; import { test, expect } from 'vitest'; -import findSchemaDefinition from '../../src/lib/find-schema-definition'; +import findSchemaDefinition from '../../src/lib/find-schema-definition.js'; test('should return a definition for a given ref', () => { expect(findSchemaDefinition('#/components/schemas/Pet', petstore)).toStrictEqual(petstore.components.schemas.Pet); diff --git a/packages/oas/test/lib/get-auth.test.ts b/packages/oas/test/lib/get-auth.test.ts index 4bb19103..a2cc64e7 100644 --- a/packages/oas/test/lib/get-auth.test.ts +++ b/packages/oas/test/lib/get-auth.test.ts @@ -1,7 +1,7 @@ import { test, describe, it, expect } from 'vitest'; -import Oas from '../../src'; -import getAuth, { getByScheme } from '../../src/lib/get-auth'; +import Oas from '../../src/index.js'; +import getAuth, { getByScheme } from '../../src/lib/get-auth.js'; import multipleSecurities from '../__datasets__/multiple-securities.json'; // We need to forcetype this definition to an OASDocument because it's got weird use cases in it diff --git a/packages/oas/test/lib/get-user-variable.test.ts b/packages/oas/test/lib/get-user-variable.test.ts index 904e4695..085233bf 100644 --- a/packages/oas/test/lib/get-user-variable.test.ts +++ b/packages/oas/test/lib/get-user-variable.test.ts @@ -1,6 +1,6 @@ import { test, expect } from 'vitest'; -import getUserVariable from '../../src/lib/get-user-variable'; +import getUserVariable from '../../src/lib/get-user-variable.js'; const topLevelUser = { apiKey: '123456', user: 'user', pass: 'pass' }; const keysUser = { diff --git a/packages/oas/test/lib/matches-mimetype.test.ts b/packages/oas/test/lib/matches-mimetype.test.ts index 4bd8fde6..406d5a71 100644 --- a/packages/oas/test/lib/matches-mimetype.test.ts +++ b/packages/oas/test/lib/matches-mimetype.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; -import matchesMimeType from '../../src/lib/matches-mimetype'; +import matchesMimeType from '../../src/lib/matches-mimetype.js'; describe('#formUrlEncoded', () => { it('should recognize `application/x-www-form-urlencoded`', () => { diff --git a/packages/oas/test/lib/openapi-to-json-schema.test.ts b/packages/oas/test/lib/openapi-to-json-schema.test.ts index 3b601f67..a49f2703 100644 --- a/packages/oas/test/lib/openapi-to-json-schema.test.ts +++ b/packages/oas/test/lib/openapi-to-json-schema.test.ts @@ -1,12 +1,12 @@ -import type { SchemaObject } from '../../src/rmoas.types'; +import type { SchemaObject } from '../../src/rmoas.types.js'; import type { JSONSchema4, JSONSchema7, JSONSchema7Definition, JSONSchema7TypeName } from 'json-schema'; import { beforeAll, expect, describe, it } from 'vitest'; -import Oas from '../../src'; -import toJSONSchema from '../../src/lib/openapi-to-json-schema'; -import createOas from '../__fixtures__/create-oas'; -import generateJSONSchemaFixture from '../__fixtures__/json-schema'; +import Oas from '../../src/index.js'; +import toJSONSchema from '../../src/lib/openapi-to-json-schema.js'; +import createOas from '../__fixtures__/create-oas.js'; +import generateJSONSchemaFixture from '../__fixtures__/json-schema.js'; let petstore: Oas; diff --git a/packages/oas/test/lib/openapi-to-json-schema/default.test.ts b/packages/oas/test/lib/openapi-to-json-schema/default.test.ts index bcb1be94..baaa3368 100644 --- a/packages/oas/test/lib/openapi-to-json-schema/default.test.ts +++ b/packages/oas/test/lib/openapi-to-json-schema/default.test.ts @@ -1,9 +1,9 @@ -import type { SchemaObject } from '../../../src/rmoas.types'; +import type { SchemaObject } from '../../../src/rmoas.types.js'; import { describe, it, expect } from 'vitest'; -import toJSONSchema from '../../../src/lib/openapi-to-json-schema'; -import generateJSONSchemaFixture from '../../__fixtures__/json-schema'; +import toJSONSchema from '../../../src/lib/openapi-to-json-schema.js'; +import generateJSONSchemaFixture from '../../__fixtures__/json-schema.js'; describe('`default` support in `openapi-to-json-schema`', () => { it('should support default', () => { diff --git a/packages/oas/test/lib/openapi-to-json-schema/required.test.ts b/packages/oas/test/lib/openapi-to-json-schema/required.test.ts index 013c96e1..b53d2091 100644 --- a/packages/oas/test/lib/openapi-to-json-schema/required.test.ts +++ b/packages/oas/test/lib/openapi-to-json-schema/required.test.ts @@ -1,9 +1,9 @@ -import type { SchemaObject } from '../../../src/rmoas.types'; +import type { SchemaObject } from '../../../src/rmoas.types.js'; import { describe, it, expect } from 'vitest'; -import toJSONSchema from '../../../src/lib/openapi-to-json-schema'; -import generateJSONSchemaFixture from '../../__fixtures__/json-schema'; +import toJSONSchema from '../../../src/lib/openapi-to-json-schema.js'; +import generateJSONSchemaFixture from '../../__fixtures__/json-schema.js'; describe('`required` support in `openapi-to-json-schema`', () => { it('should support required', () => { diff --git a/packages/oas/test/lib/reducer.test.ts b/packages/oas/test/lib/reducer.test.ts index 1973bccd..6b6db7db 100644 --- a/packages/oas/test/lib/reducer.test.ts +++ b/packages/oas/test/lib/reducer.test.ts @@ -4,7 +4,7 @@ import petstore from '@readme/oas-examples/3.0/json/petstore.json'; import uspto from '@readme/oas-examples/3.0/json/uspto.json'; import { expect, describe, it } from 'vitest'; -import reducer from '../../src/lib/reducer'; +import reducer from '../../src/lib/reducer.js'; import complexNesting from '../__datasets__/complex-nesting.json'; import petstoreRefQuirks from '../__datasets__/petstore-ref-quirks.json'; import securityRootLevel from '../__datasets__/security-root-level.json'; diff --git a/packages/oas/test/operation.test.ts b/packages/oas/test/operation.test.ts index 9a73160f..013d4611 100644 --- a/packages/oas/test/operation.test.ts +++ b/packages/oas/test/operation.test.ts @@ -1,11 +1,11 @@ -import type * as RMOAS from '../src/rmoas.types'; +import type * as RMOAS from '../src/rmoas.types.js'; import petstoreSpec from '@readme/oas-examples/3.0/json/petstore.json'; import openapiParser from '@readme/openapi-parser'; import { beforeAll, describe, it, expect } from 'vitest'; -import Oas from '../src'; -import Operation, { Callback } from '../src/operation'; +import Oas from '../src/index.js'; +import Operation, { Callback } from '../src/operation.js'; let petstore: Oas; let callbackSchema: Oas; diff --git a/packages/oas/test/operation/get-callback-examples.test.ts b/packages/oas/test/operation/get-callback-examples.test.ts index f8fa6b4f..ab85f93f 100644 --- a/packages/oas/test/operation/get-callback-examples.test.ts +++ b/packages/oas/test/operation/get-callback-examples.test.ts @@ -1,8 +1,8 @@ -import type { HttpMethods } from '../../src/rmoas.types'; +import type { HttpMethods } from '../../src/rmoas.types.js'; import { beforeAll, test, expect, describe, it } from 'vitest'; -import Oas from '../../src'; +import Oas from '../../src/index.js'; let operationExamples: Oas; let callbacks: Oas; diff --git a/packages/oas/test/operation/get-parameters-as-json-schema.test.ts b/packages/oas/test/operation/get-parameters-as-json-schema.test.ts index 9b1f80cb..ebd774a8 100644 --- a/packages/oas/test/operation/get-parameters-as-json-schema.test.ts +++ b/packages/oas/test/operation/get-parameters-as-json-schema.test.ts @@ -1,9 +1,9 @@ -import type { OperationObject, RequestBodyObject, SchemaObject } from '../../src/rmoas.types'; +import type { OperationObject, RequestBodyObject, SchemaObject } from '../../src/rmoas.types.js'; import { beforeAll, test, expect, it, describe } from 'vitest'; -import Oas from '../../src'; -import createOas from '../__fixtures__/create-oas'; +import Oas from '../../src/index.js'; +import createOas from '../__fixtures__/create-oas.js'; let ably: Oas; let circular: Oas; diff --git a/packages/oas/test/operation/get-requestbody-examples.test.ts b/packages/oas/test/operation/get-requestbody-examples.test.ts index 1e0e687c..5799974d 100644 --- a/packages/oas/test/operation/get-requestbody-examples.test.ts +++ b/packages/oas/test/operation/get-requestbody-examples.test.ts @@ -1,7 +1,7 @@ import { beforeAll, test, expect, it, describe } from 'vitest'; -import Oas from '../../src'; -import cleanStringify from '../__fixtures__/json-stringify-clean'; +import Oas from '../../src/index.js'; +import cleanStringify from '../__fixtures__/json-stringify-clean.js'; let operationExamples: Oas; let petstore: Oas; diff --git a/packages/oas/test/operation/get-response-as-json-schema.test.ts b/packages/oas/test/operation/get-response-as-json-schema.test.ts index a337d4be..7f681f6a 100644 --- a/packages/oas/test/operation/get-response-as-json-schema.test.ts +++ b/packages/oas/test/operation/get-response-as-json-schema.test.ts @@ -1,11 +1,11 @@ -import type { HttpMethods, ResponseObject, SchemaObject } from '../../src/rmoas.types'; +import type { HttpMethods, ResponseObject, SchemaObject } from '../../src/rmoas.types.js'; import openapiParser from '@readme/openapi-parser'; import { beforeAll, describe, test, expect, it } from 'vitest'; -import Oas from '../../src'; -import cloneObject from '../../src/lib/clone-object'; -import createOas from '../__fixtures__/create-oas'; +import Oas from '../../src/index.js'; +import cloneObject from '../../src/lib/clone-object.js'; +import createOas from '../__fixtures__/create-oas.js'; let circular: Oas; let petstore: Oas; diff --git a/packages/oas/test/operation/get-response-examples.test.ts b/packages/oas/test/operation/get-response-examples.test.ts index 8ad1e04d..acc86b46 100644 --- a/packages/oas/test/operation/get-response-examples.test.ts +++ b/packages/oas/test/operation/get-response-examples.test.ts @@ -1,10 +1,10 @@ -import type { MediaTypeExample } from '../../src/lib/get-mediatype-examples'; -import type * as RMOAS from '../../src/rmoas.types'; +import type { MediaTypeExample } from '../../src/lib/get-mediatype-examples.js'; +import type * as RMOAS from '../../src/rmoas.types.js'; import { beforeAll, describe, test, expect, it } from 'vitest'; -import Oas from '../../src'; -import cleanStringify from '../__fixtures__/json-stringify-clean'; +import Oas from '../../src/index.js'; +import cleanStringify from '../__fixtures__/json-stringify-clean.js'; let operationExamples: Oas; let petstore: Oas; diff --git a/packages/oas/test/samples/index.test.ts b/packages/oas/test/samples/index.test.ts index 1b1ca64d..bcb320d7 100644 --- a/packages/oas/test/samples/index.test.ts +++ b/packages/oas/test/samples/index.test.ts @@ -4,11 +4,11 @@ * @license Apache-2.0 * @see {@link https://github.com/swagger-api/swagger-ui/blob/master/test/unit/core/plugins/samples/fn.js} */ -import type * as RMOAS from '../../src/rmoas.types'; +import type * as RMOAS from '../../src/rmoas.types.js'; import { describe, it, expect } from 'vitest'; -import sampleFromSchema from '../../src/samples'; +import sampleFromSchema from '../../src/samples/index.js'; describe('sampleFromSchema', () => { it('should be memoized', async () => { diff --git a/packages/oas/test/ts-quirks.test.js b/packages/oas/test/ts-quirks.test.js index 694acf07..4a6fc388 100644 --- a/packages/oas/test/ts-quirks.test.js +++ b/packages/oas/test/ts-quirks.test.js @@ -1,6 +1,6 @@ import { test, expect } from 'vitest'; -// eslint-disable-next-line import/extensions +// eslint-disable-next-line import/extensions, require-extensions/require-index import Oas from '..'; /** diff --git a/packages/oas/test/utils.test.ts b/packages/oas/test/utils.test.ts index 0d77b83b..6db841f0 100644 --- a/packages/oas/test/utils.test.ts +++ b/packages/oas/test/utils.test.ts @@ -1,6 +1,6 @@ import { test, expect } from 'vitest'; -import utils from '../src/utils'; +import utils from '../src/utils.js'; test('should expose `jsonSchemaTypes`', () => { expect(utils.jsonSchemaTypes).toStrictEqual({ diff --git a/packages/oas/tsup.config.ts b/packages/oas/tsup.config.ts index dc6178b8..0bf5ce13 100644 --- a/packages/oas/tsup.config.ts +++ b/packages/oas/tsup.config.ts @@ -3,7 +3,7 @@ import type { Options } from 'tsup'; // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig } from 'tsup'; -import config from '../../tsup.config'; +import config from '../../tsup.config.js'; export default defineConfig((options: Options) => ({ ...options,