Skip to content

Commit

Permalink
fix(enum): append index number on duplicate name
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Apr 3, 2024
1 parent 3f195af commit 6132cf4
Show file tree
Hide file tree
Showing 75 changed files with 827 additions and 588 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-glasses-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix(enum): append index number on duplicate name
19 changes: 10 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@
"es6": true,
"node": true
},
"plugins": ["simple-import-sort"],
"plugins": ["simple-import-sort", "sort-keys-fix"],
"rules": {
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"arrow-body-style": "error",
"import/order": "off",
"object-shorthand": "error",
"prettier/prettier": ["error"],
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
"sort-imports": "off"
"sort-imports": "off",
"sort-keys-fix/sort-keys-fix": "warn"
}
}
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-simple-import-sort": "12.0.0",
"eslint-plugin-sort-keys-fix": "1.1.2",
"express": "4.19.2",
"node-fetch": "3.3.2",
"npm-run-all2": "6.1.2",
Expand Down
16 changes: 8 additions & 8 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import { defineConfig } from 'rollup';
*/
export function handlebarsPlugin(): Plugin {
return {
name: 'handlebars',
resolveId: (file: any, importer: any) => {
if (path.extname(file) === '.hbs') {
return path.resolve(path.dirname(importer), file);
}
return null;
},
load: (file: any) => {
if (path.extname(file) === '.hbs') {
const template = readFileSync(file, 'utf8').toString().trim();
Expand All @@ -41,9 +34,9 @@ export function handlebarsPlugin(): Plugin {
escapeDescription: true,
escapeNewline: true,
exactArray: true,
ifdef: true,
ifNotNullNotUndefined: true,
ifOperationDataOptional: true,
ifdef: true,
intersection: true,
modelUnionType: true,
nameOperationDataType: true,
Expand All @@ -60,6 +53,13 @@ export function handlebarsPlugin(): Plugin {
}
return null;
},
name: 'handlebars',
resolveId: (file: any, importer: any) => {
if (path.extname(file) === '.hbs') {
return path.resolve(path.dirname(importer), file);
}
return null;
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion rollup.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url)).
const external = [/^node:*/, ...Object.keys(pkg.dependencies), ...Object.keys(pkg.devDependencies)];

export default defineConfig({
external,
input: {
index: './temp/node/index.d.ts',
},
output: {
dir: './dist/node',
format: 'esm',
},
external,
plugins: [dts({ respectExternal: true })],
});
18 changes: 9 additions & 9 deletions src/openApi/common/parser/__tests__/getPattern.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { getPattern } from '../getPattern';

describe('getPattern', () => {
it.each([
{ pattern: undefined, expected: undefined },
{ pattern: '', expected: '' },
{ pattern: '^[a-zA-Z]', expected: '^[a-zA-Z]' },
{ pattern: '^\\w+$', expected: '^\\\\w+$' },
{ pattern: '^\\d{3}-\\d{2}-\\d{4}$', expected: '^\\\\d{3}-\\\\d{2}-\\\\d{4}$' },
{ pattern: '\\', expected: '\\\\' },
{ pattern: '\\/', expected: '\\\\/' },
{ pattern: '\\/\\/', expected: '\\\\/\\\\/' },
{ pattern: "'", expected: "\\'" },
{ expected: undefined, pattern: undefined },
{ expected: '', pattern: '' },
{ expected: '^[a-zA-Z]', pattern: '^[a-zA-Z]' },
{ expected: '^\\\\w+$', pattern: '^\\w+$' },
{ expected: '^\\\\d{3}-\\\\d{2}-\\\\d{4}$', pattern: '^\\d{3}-\\d{2}-\\d{4}$' },
{ expected: '\\\\', pattern: '\\' },
{ expected: '\\\\/', pattern: '\\/' },
{ expected: '\\\\/\\\\/', pattern: '\\/\\/' },
{ expected: "\\'", pattern: "'" },
])('getPattern($pattern) -> $expected', ({ pattern, expected }) => {
expect(getPattern(pattern)).toEqual(expected);
});
Expand Down
36 changes: 18 additions & 18 deletions src/openApi/common/parser/__tests__/getRef.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ describe('getRef (v2)', () => {
expect(
getRef(
{
swagger: '2.0',
info: {
title: 'dummy',
version: '1.0',
},
host: 'localhost:8080',
basePath: '/api',
schemes: ['http', 'https'],
paths: {},
definitions: {
Example: {
description: 'This is an Example model ',
type: 'integer',
},
},
host: 'localhost:8080',
info: {
title: 'dummy',
version: '1.0',
},
paths: {},
schemes: ['http', 'https'],
swagger: '2.0',
},
{
$ref: '#/definitions/Example',
Expand All @@ -39,25 +39,25 @@ describe('getRef (v3)', () => {
expect(
getRef(
{
openapi: '3.0',
components: {
schemas: {
Example: {
description: 'This is an Example model ',
type: 'integer',
},
},
},
info: {
title: 'dummy',
version: '1.0',
},
openapi: '3.0',
paths: {},
servers: [
{
url: 'https://localhost:8080/api',
},
],
components: {
schemas: {
Example: {
description: 'This is an Example model ',
type: 'integer',
},
},
},
},
{
$ref: '#/components/schemas/Example',
Expand All @@ -73,11 +73,11 @@ describe('getRef (v3)', () => {
expect(
getRef(
{
openapi: '3.0',
info: {
title: 'dummy',
version: '1.0',
},
openapi: '3.0',
paths: {
'/api/user/{id}': {
description: 'This is an Example path',
Expand Down
Loading

0 comments on commit 6132cf4

Please sign in to comment.