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

feat: fetch urls, fix #67 #95

Merged
merged 35 commits into from
May 24, 2024
Merged

feat: fetch urls, fix #67 #95

merged 35 commits into from
May 24, 2024

Conversation

hanspagel
Copy link
Member

@hanspagel hanspagel commented May 23, 2024

With this PR references to URLs can be resolved.

To achieve this, I’ve introduced the new utility load utility, which imports JSON stings, YAML strings, JS objects, files and urls now. It even comes with a tiny plugin API, which means you can add whatever data source you’d like, or not enable file support (in browser envs).

I’ve had to make the load utility async, which made the pipeline syntax really ugly (await (await openapi().load()).resolve()), so I’ve refactored it to put all actions in a queue and work through it at the end, which enables a way nicer syntax:

Pipeline syntax

import { openapi, fetchUrlsPlugin, readFilesPlugin } from '@scalar/openapi-parser'

const result = await openapi()
  .load('./openapi.yaml', {
    plugins: [readFilesPlugin, fetchUrlsPlugin],
  })
  .dereference()
  .get()

Modular syntax

import {
  dereference,
  fetchUrlsPlugin,
  load,
  readFilesPlugin,
} from '@scalar/openapi-parser'

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

// Instead of just passing a single specification, pass the whole “filesystem”
const result = await dereference(filesystem)

Additional improvements

  • fixed add loose types #67 to account for random user input
  • openapi().load(…).files() to retrieve the whole filesystem
  • improved error messages (they all used to start with “: ”)

Example

{
  "openapi": "3.1.0",
  "info": {
    "title": "HTTP Reference"
  },
  "paths": {
    "/foobar": {
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.json#/components/schemas/Planet"
              }
            }
          }
        }
      }
    }
  }
}

Copy link

changeset-bot bot commented May 23, 2024

🦋 Changeset detected

Latest commit: 78cd843

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@scalar/openapi-parser Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

relativeci bot commented May 23, 2024

#44 Bundle Size — 477.72KiB (-0.58%).

78cd843(current) vs e3d7bba main#42(baseline)

Bundle metrics  Change 3 changes Improvement 1 improvement
                 Current
#44
     Baseline
#42
Improvement  Initial JS 477.72KiB(-0.58%) 480.51KiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 100% 0%
No change  Chunks 1 1
No change  Assets 1 1
Change  Modules 306(+0.33%) 305
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#44
     Baseline
#42
Improvement  JS 477.72KiB (-0.58%) 480.51KiB

Bundle analysis reportBranch feat/fetch-urlsProject dashboard

@hanspagel hanspagel changed the title feat: fetch urls feat: fetch urls, fix # May 24, 2024
@hanspagel hanspagel changed the title feat: fetch urls, fix # feat: fetch urls, fix #67 May 24, 2024
@hanspagel hanspagel marked this pull request as ready for review May 24, 2024 13:20
@hanspagel hanspagel merged commit 0b7d7be into main May 24, 2024
7 checks passed
@hanspagel hanspagel deleted the feat/fetch-urls branch May 24, 2024 13:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add loose types
1 participant