Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

fix: max call stack exceeded #116

Merged
merged 16 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-mangos-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@scalar/openapi-parser': minor
---

refactor!: most functions return an object now
5 changes: 5 additions & 0 deletions .changeset/young-coins-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@scalar/openapi-parser': patch
---

fix: max call stack exceeded error
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const file = `{
"paths": {}
}`

const result = await validate(file)
const { valid, errors } = await validate(file)

console.log(result.valid)
console.log(valid)

if (!result.valid) {
console.log(result.errors)
if (!valid) {
console.log(errors)
}
```

Expand All @@ -67,7 +67,7 @@ const specification = `{
"paths": {}
}`

const result = await dereference(specification)
const { schema, errors } = await dereference(specification)
```

### Modify an OpenAPI specification
Expand All @@ -84,7 +84,7 @@ const specification = `{
"paths": {}
}`

const result = filter(specification, (schema) => !schema?.['x-internal'])
const { specification } = filter(specification, (schema) => !schema?.['x-internal'])
```

### Upgrade your OpenAPI specification
Expand All @@ -96,7 +96,7 @@ There’s an `upgrade` command to upgrade all your OpenAPI specifications to the
```ts
import { upgrade } from '@scalar/openapi-parser'

const result = upgrade({
const { specification } = upgrade({
openapi: '3.0.0',
info: {
title: 'Hello World',
Expand All @@ -105,7 +105,7 @@ const result = upgrade({
paths: {},
})

console.log(result.openapi)
console.log(specification.openapi)
// Output: 3.1.0
```

Expand Down Expand Up @@ -141,7 +141,7 @@ import {
} from '@scalar/openapi-parser'

// Load a file and all referenced files
const filesystem = await load('./openapi.yaml', {
const { filesystem } = await load('./openapi.yaml', {
plugins: [readFilesPlugin(), fetchUrlsPlugin()],
})

Expand Down
1 change: 1 addition & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@vitejs/plugin-vue": "^5.0.5",
"typescript": "^5.2.2",
"vite": "^5.2.12",
"vue-json-viewer": "3",
"vue-tsc": "^2.0.19"
}
}
36 changes: 18 additions & 18 deletions demo/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<script setup lang="ts">
import {
dereference,
fetchUrlsPlugin,
load,
toJson, // validate,
} from '@scalar/openapi-parser'
import { dereference, fetchUrlsPlugin, load } from '@scalar/openapi-parser'
import { watchDebounced } from '@vueuse/core'
import { onMounted, ref, watch } from 'vue'
// @ts-ignore
import JsonViewer from 'vue-json-viewer'

const value = ref(
JSON.stringify(
Expand Down Expand Up @@ -35,7 +32,7 @@ const value = ref(
),
)

const result = ref('')
const result = ref({})

onMounted(() => {
const savedValue = window.localStorage.getItem('value')
Expand All @@ -52,16 +49,14 @@ watch(value, async (newValue) => {
watchDebounced(
value,
async (newValue) => {
const content = await load(newValue, {
const { filesystem } = await load(newValue, {
plugins: [fetchUrlsPlugin()],
})

// console.log(await validate(content))

const { schema } = await dereference(content)
const { schema } = await dereference(filesystem)

if (schema) {
result.value = toJson(schema)
result.value = schema
}
},
{
Expand All @@ -84,7 +79,9 @@ watchDebounced(
v-model="value" />
</div>
<div class="preview-right">
<pre id="output">{{ result }}</pre>
<json-viewer
:value="result"
:expand-depth="3"></json-viewer>
</div>
</div>
</template>
Expand All @@ -110,11 +107,9 @@ watchDebounced(
width: 50%;
height: 100%;
font-size: 1rem;
padding: 20px;
border-radius: 5px;
background: #000;
color: #fff;
overflow: auto;
border: 1px solid #ccc;
}

textarea {
Expand All @@ -125,13 +120,18 @@ textarea {
resize: none;
padding: 0;
margin: 0;
font-size: 1rem;
font-size: 0.9rem;
line-height: 1.4;
font-family: monospace;
border: 1px solid #ccc;
padding: 20px;
padding: 15px 20px;
border-radius: 5px;
}

.jv-container .jv-code {
padding: 20px;
}

pre {
margin: 0;
}
Expand Down
32 changes: 16 additions & 16 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export default defineConfig({
// external: [...builtinModules, ...builtinModules.map((m) => `node:${m}`)],
// },
// },
// resolve: {
// alias: [
// // Resolve the uncompiled source code for all @scalar packages
// // It’s working with the alias, too. It’s just required to enable HMR.
// // It also does not match components since we want the built version
// {
// // Resolve the uncompiled source code for @scalar/openapi-parser packages
// find: '@scalar/openapi-parser',
// replacement: path.resolve(
// __dirname,
// // '../packages/openapi-parser/dist/index.js',
// '../packages/openapi-parser/src/index.ts',
// ),
// },
// ],
// },
resolve: {
alias: [
// Resolve the uncompiled source code for all @scalar packages
// It’s working with the alias, too. It’s just required to enable HMR.
// It also does not match components since we want the built version
{
// Resolve the uncompiled source code for @scalar/openapi-parser packages
find: '@scalar/openapi-parser',
replacement: path.resolve(
__dirname,
// '../packages/openapi-parser/dist/index.js',
'../packages/openapi-parser/src/index.ts',
),
},
],
},
})
12 changes: 6 additions & 6 deletions packages/openapi-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ const file = `{
"paths": {}
}`

const result = await validate(file)
const { valid, errors } = await validate(file)

console.log(result.valid)
console.log(valid)

if (!result.valid) {
console.log(result.errors)
if (!valid) {
console.log(errors)
}
```

Expand All @@ -70,7 +70,7 @@ const file = `{
"paths": {}
}`

const result = await dereference(file)
const { version } = await dereference(file)

console.log(result.version)
console.log(version)
```
Loading