feat(oas): medusa-oas-cli as OAS build tool (#3213)

## What

Introduce a CLI for extracting OAS from the core `medusa` package.

## Why

We need to decouple OAS tooling from documentation tooling in order to allow packages and external systems to leverage our OAS has a dependency.

## How

Introduce a new OAS workspace within packages in order to organize current and future OAS related package. Only 1 OAS package for now.

Introduce a new CLI only package to act as the main gateway for all upcoming OAS tooling. Only 1 command for now.

Update documentation tooling pertaining to OAS to use the CLI instead.

## Test

### Prerequisite
From the monorepo root:
* `yarn install`
* `yarn build`

### Documentation

#### Case - validation only - success
* Run `yarn openapi:generate --dry-run`
* Expect console output `🟢 Valid OAS` but no mention of `🔵 Exported OAS`

#### Case - validation only - invalid
* Introduce a bug by renaming `@schema Cart` to `@schema Kart` in [models/cart.ts](https://github.com/medusajs/medusa/blob/0adb0d9ff96087613b7a634cbc97a7e301b01121/packages/medusa/src/models/cart.ts#L2)
* Run `yarn build` to update `@medusajs/medusa` package with the bug.
* Run `yarn openapi:generate --dry-run`
* Expect console output `🔴 Invalid OAS` with a stack trace of the issue.

#### Case - docs generation
* Run `yarn openapi:generate`
* Expect `docs/api/` directory to contain:
  * `admin.oas.json` (raw OAS)
  * `store.oas.json` (raw OAS)
  * `admin.oas.yaml` (sanitized OAS)
  * `store.oas.yaml` (sanitized OAS)
  * `admin/` (updated redocly split output)
  * `store/` (updated redocly split output)

### CLI

#### Case - crawl additional paths
* From a local medusa server (`medusa-starter-default`), add an `index.ts` file in `src/models/`
* In the `index.ts`, add dummy OAS JSDoc like `/** @schema Foobar */`
* From the root of the monorepo, run `yarn medusa-oas --type store --paths path-to-medusa-server/src`
* Expect a `store.oas.json` to be created at the root of the monorepo.
* The `store.oas.json` should contain an additional `Foobar` entry in `components.schemas`.
This commit is contained in:
Patrick
2023-02-15 09:55:58 -05:00
committed by GitHub
parent 1bfbe27b9b
commit 8137061908
20 changed files with 613 additions and 82708 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa-oas-cli": patch
---
feat(oas): medusa-oas-cli as OAS build tool
+10 -2
View File
@@ -1,12 +1,17 @@
name: OAS Comments Format Validation
on:
on:
pull_request:
paths:
- packages/medusa/src/api/routes/**
- packages/medusa/src/api/**
- packages/medusa/src/models/**
- packages/medusa/src/types/**
jobs:
docs-test:
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
@@ -29,6 +34,9 @@ jobs:
with:
extension: oas
- name: Build Packages
run: yarn build
- name: Build OAS
run: |
yarn openapi:generate --dry-run
+60 -1
View File
@@ -5,7 +5,7 @@ plugins:
# when Redocly attempts to render circular references.
decorators:
plugin/circular-patch:
verbose: true
verbose: false
schemas:
Address:
- Customer
@@ -13,14 +13,26 @@ decorators:
- Customer
- Order
- Payment
- PaymentSession
ClaimImage:
- ClaimItem
ClaimItem:
- ClaimOrder
ClaimOrder:
- Fulfillment
- Order
- Return
Country:
- Region
Customer:
- Order
CustomerGroup:
- Customer
- PriceList
Discount:
- Discount
DiscountRule:
- DiscountCondition
DraftOrder:
- Cart
- Order
@@ -28,6 +40,8 @@ decorators:
- ClaimOrder
- Order
- Swap
FulfillmentItem:
- Fulfillment
GiftCard:
- Order
GiftCardTransaction:
@@ -39,6 +53,16 @@ decorators:
- Order
- OrderEdit
- Swap
LineItemAdjustment:
- LineItem
LineItemTaxLine:
- LineItem
MoneyAmount:
- PriceList
- ProductVariant
- Region
Notification:
- Notification
Order:
- Cart
- ClaimOrder
@@ -52,10 +76,26 @@ decorators:
- Swap
OrderEdit:
- Order
OrderItemChange:
- OrderEdit
Payment:
- Cart
- Order
- Swap
ProductCategory:
- ProductCategory
- Product
ProductCollection:
- Product
ProductOption:
- Product
ProductOptionValue:
- ProductOption
- ProductVariant
ProductVariant:
- Product
ProductVariantInventoryItem:
- ProductVariant
Refund:
- Order
- Payment
@@ -63,6 +103,12 @@ decorators:
- ClaimOrder
- Order
- Swap
ReturnItem:
- Return
ReturnReason:
- ReturnReason
SalesChannelLocation:
- SalesChannel
ShippingMethod:
- Cart
- ClaimOrder
@@ -70,12 +116,25 @@ decorators:
- Payment
- Return
- Swap
ShippingMethodTaxLine:
- ShippingMethod
ShippingOption:
- Region
ShippingOptionRequirement:
- ShippingOption
ShippingProfile:
- Product
- ShippingOption
Swap:
- Cart
- Fulfillment
- Order
- Payment
- Return
TaxRate:
- Region
TrackingLink:
- Fulfillment
# Similar config to /www/docs/docusaurus.config.js > redocusaurus
# Allows to emulate rendering of API public documentation when using `yarn redocly preview-docs openapi.yaml`
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-958
View File
@@ -1,958 +0,0 @@
{
"resources": {
"region": {
"id": "reg_01F0YES4R67TXXC1QBQ8P54A8Y",
"name": "Test Region",
"currency_code": "usd",
"tax_rate": "0",
"tax_code": null,
"payment_providers": [],
"fulfillment_providers": [
{
"id": "test-ful",
"is_installed": true
}
],
"created_at": "2021-03-16T21:24:00.389Z",
"updated_at": "2021-03-16T21:24:00.389Z",
"deleted_at": null,
"metadata": null
},
"shipping_option": {
"id": "so_01F0YES4T6ZHH52Z4KZEDT1312",
"name": "Free Shipping",
"region_id": "reg_01F0YES4R67TXXC1QBQ8P54A8Y",
"region": {
"id": "reg_01F0YES4R67TXXC1QBQ8P54A8Y",
"name": "Test Region",
"currency_code": "usd",
"tax_rate": "0",
"tax_code": null,
"payment_providers": [],
"fulfillment_providers": [
{
"id": "test-ful",
"is_installed": true
}
],
"created_at": "2021-03-16T21:24:00.389Z",
"updated_at": "2021-03-16T21:24:00.389Z",
"deleted_at": null,
"metadata": null
},
"profile_id": "sp_01F0YES4Q77FGG18GPFWW5BZP9",
"profile": {
"id": "sp_01F0YES4Q77FGG18GPFWW5BZP9",
"name": "Default Shipping Profile",
"type": "default",
"created_at": "2021-03-16T21:24:00.307Z",
"updated_at": "2021-03-16T21:24:00.307Z",
"deleted_at": null,
"metadata": null
},
"provider_id": "test-ful",
"price_type": "flat_rate",
"amount": 100,
"is_return": false,
"requirements": [],
"data": {},
"created_at": "2021-03-16T21:24:00.439Z",
"updated_at": "2021-03-16T21:24:00.439Z",
"deleted_at": null,
"metadata": null
},
"cart": {
"id": "cart_01F0YES82DA12W88KQ90EY6W4C",
"email": null,
"billing_address_id": null,
"billing_address": null,
"shipping_address_id": "addr_01F0YES82D4Y16JKGF0NFSSS3P",
"shipping_address": {
"id": "addr_01F0YES82D4Y16JKGF0NFSSS3P",
"customer_id": null,
"company": null,
"first_name": null,
"last_name": null,
"address_1": null,
"address_2": null,
"city": null,
"country_code": "us",
"province": null,
"postal_code": null,
"phone": null,
"created_at": "2021-03-16T21:24:03.766Z",
"updated_at": "2021-03-16T21:24:03.766Z",
"deleted_at": null,
"metadata": null
},
"items": [],
"region_id": "region",
"region": {
"id": "region",
"name": "Test Region",
"currency_code": "usd",
"tax_rate": "0",
"tax_code": null,
"countries": [
{
"id": 236,
"iso_2": "us",
"iso_3": "usa",
"num_code": 840,
"name": "UNITED STATES",
"display_name": "United States",
"region_id": "region"
}
],
"payment_providers": [],
"fulfillment_providers": [],
"created_at": "2021-03-16T21:24:03.743Z",
"updated_at": "2021-03-16T21:24:03.743Z",
"deleted_at": null,
"metadata": null
},
"discounts": [],
"gift_cards": [],
"customer_id": null,
"payment_sessions": [],
"payment_id": null,
"payment": null,
"shipping_methods": [],
"type": "default",
"completed_at": null,
"created_at": "2021-03-16T21:24:03.766Z",
"updated_at": "2021-03-16T21:24:03.857Z",
"deleted_at": null,
"metadata": null,
"idempotency_key": null,
"context": {
"ip": "::ffff:127.0.0.1",
"user_agent": "axios/0.21.1"
},
"shipping_total": 0,
"discount_total": 0,
"tax_total": 0,
"gift_card_total": 0,
"subtotal": 0,
"total": 0
},
"product_collection": {
"id": "pcol_01F0YESBFAZ0DV6V831JXWH0BG",
"title": "Summer Collection",
"handle": "summer-collection",
"created_at": "2021-03-16T21:24:07.273Z",
"updated_at": "2021-03-16T21:24:07.273Z",
"deleted_at": null,
"metadata": null
},
"gift_card": {
"id": "gift_01F0YESEKYJ5578VCAPV4XYFDP",
"code": "1J3U-WXO0-SZ0H-O5QU",
"value": 1000,
"balance": 1000,
"region_id": "reg_01F0YESEJP4H8Q517XSPGK6TD6",
"region": {
"id": "reg_01F0YESEJP4H8Q517XSPGK6TD6",
"name": "Test Region",
"currency_code": "usd",
"tax_rate": "0",
"tax_code": null,
"payment_providers": [],
"fulfillment_providers": [],
"created_at": "2021-03-16T21:24:10.454Z",
"updated_at": "2021-03-16T21:24:10.454Z",
"deleted_at": null,
"metadata": null
},
"is_disabled": false,
"ends_at": null,
"created_at": "2021-03-16T21:24:10.484Z",
"updated_at": "2021-03-16T21:24:10.484Z",
"deleted_at": null,
"metadata": null
},
"product": {
"id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"title": "Test product",
"subtitle": null,
"description": "test-product-description",
"handle": "test-product",
"is_giftcard": false,
"images": [],
"thumbnail": null,
"options": [
{
"id": "opt_01F0YESHQBZVKCEXJ24BS6PCX3",
"title": "size",
"product_id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
{
"id": "opt_01F0YESHQBV8MMNN4V7WSDMH6G",
"title": "color",
"product_id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
}
],
"variants": [
{
"id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"title": "Test variant",
"product_id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"product": {
"id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"title": "Test product",
"subtitle": null,
"description": "test-product-description",
"handle": "test-product",
"is_giftcard": false,
"thumbnail": null,
"profile_id": "sp_01F0YESHMKRB4V3B7F6MVQHGNN",
"weight": null,
"length": null,
"height": null,
"width": null,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"collection_id": "test-collection",
"type_id": "test-type",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
"prices": [
{
"id": "ma_01F0YESHRFQNH5S8Q0PK84YYZN",
"currency_code": "usd",
"amount": 100,
"sale_amount": null,
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"region_id": null,
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null
}
],
"sku": null,
"barcode": null,
"ean": null,
"upc": null,
"inventory_quantity": 10,
"allow_backorder": false,
"manage_inventory": true,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"weight": null,
"length": null,
"height": null,
"width": null,
"options": [
{
"id": "optval_01F0YESHR7S6ECD03RF6W12DSJ",
"value": "large",
"option_id": "opt_01F0YESHQBZVKCEXJ24BS6PCX3",
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
{
"id": "optval_01F0YESHR7N2GHM1RN3GKYPN6P",
"value": "green",
"option_id": "opt_01F0YESHQBV8MMNN4V7WSDMH6G",
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
}
],
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
}
],
"profile_id": "sp_01F0YESHMKRB4V3B7F6MVQHGNN",
"weight": null,
"length": null,
"height": null,
"width": null,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"collection_id": "test-collection",
"collection": {
"id": "test-collection",
"title": "Test collection",
"handle": null,
"created_at": "2021-03-16T21:24:13.603Z",
"updated_at": "2021-03-16T21:24:13.603Z",
"deleted_at": null,
"metadata": null
},
"type_id": "test-type",
"type": {
"id": "test-type",
"value": "test-type",
"created_at": "2021-03-16T21:24:13.613Z",
"updated_at": "2021-03-16T21:24:13.613Z",
"deleted_at": null,
"metadata": null
},
"tags": [
{
"id": "tag1",
"value": "123",
"created_at": "2021-03-16T21:24:13.609Z",
"updated_at": "2021-03-16T21:24:13.609Z",
"deleted_at": null,
"metadata": null
},
{
"id": "ptag_01F0YESHPZYY3H4SJ3A5918SBN",
"value": "456",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
}
],
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"metadata": null
},
"product_variant": {
"id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"title": "Test variant",
"product_id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"product": {
"id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"title": "Test product",
"subtitle": null,
"description": "test-product-description",
"handle": "test-product",
"is_giftcard": false,
"thumbnail": null,
"profile_id": "sp_01F0YESHMKRB4V3B7F6MVQHGNN",
"weight": null,
"length": null,
"height": null,
"width": null,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"collection_id": "test-collection",
"type_id": "test-type",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
"prices": [
{
"id": "ma_01F0YESHRFQNH5S8Q0PK84YYZN",
"currency_code": "usd",
"amount": 100,
"sale_amount": null,
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"region_id": null,
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null
}
],
"sku": null,
"barcode": null,
"ean": null,
"upc": null,
"inventory_quantity": 10,
"allow_backorder": false,
"manage_inventory": true,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"weight": null,
"length": null,
"height": null,
"width": null,
"options": [
{
"id": "optval_01F0YESHR7S6ECD03RF6W12DSJ",
"value": "large",
"option_id": "opt_01F0YESHQBZVKCEXJ24BS6PCX3",
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
{
"id": "optval_01F0YESHR7N2GHM1RN3GKYPN6P",
"value": "green",
"option_id": "opt_01F0YESHQBV8MMNN4V7WSDMH6G",
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
}
],
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
"product_option": {
"id": "opt_01F0YESHQBZVKCEXJ24BS6PCX3",
"title": "size",
"product_id": "prod_01F0YESHQ27Y31CAMD0NV6W9YP",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
"product_option_value": {
"id": "optval_01F0YESHR7S6ECD03RF6W12DSJ",
"value": "large",
"option_id": "opt_01F0YESHQBZVKCEXJ24BS6PCX3",
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null,
"metadata": null
},
"money_amount": {
"id": "ma_01F0YESHRFQNH5S8Q0PK84YYZN",
"currency_code": "usd",
"amount": 100,
"sale_amount": null,
"variant_id": "variant_01F0YESHR7P2YAYBDBY5B6X3PK",
"region_id": null,
"created_at": "2021-03-16T21:24:13.657Z",
"updated_at": "2021-03-16T21:24:13.657Z",
"deleted_at": null
},
"discount": {
"id": "disc_01F0YESMW10MGHWJKZSDDMN0VN",
"code": "10DISC",
"is_dynamic": false,
"rule_id": "dru_01F0YESMVK96HVX7N419E3CJ7C",
"rule": {
"id": "dru_01F0YESMVK96HVX7N419E3CJ7C",
"description": "10 Percent",
"type": "percentage",
"value": 10,
"allocation": "total",
"usage_limit": null,
"created_at": "2021-03-16T21:24:16.872Z",
"updated_at": "2021-03-16T21:24:16.872Z",
"deleted_at": null,
"metadata": null
},
"is_disabled": false,
"parent_discount_id": null,
"starts_at": "2021-03-16T21:24:16.872Z",
"ends_at": null,
"created_at": "2021-03-16T21:24:16.872Z",
"updated_at": "2021-03-16T21:24:16.872Z",
"deleted_at": null,
"metadata": null
},
"discount_rule": {
"id": "dru_01F0YESMVK96HVX7N419E3CJ7C",
"description": "10 Percent",
"type": "percentage",
"value": 10,
"allocation": "total",
"usage_limit": null,
"created_at": "2021-03-16T21:24:16.872Z",
"updated_at": "2021-03-16T21:24:16.872Z",
"deleted_at": null,
"metadata": null
},
"customer": {
"id": "cus_01F0YESQXFZ5WKMHTXJ4JDPBDZ",
"email": "test1@email.com",
"first_name": null,
"last_name": null,
"billing_address_id": null,
"password_hash": null,
"phone": null,
"has_account": false,
"orders": [],
"created_at": "2021-03-16T21:24:20.015Z",
"updated_at": "2021-03-16T21:24:20.015Z",
"deleted_at": null,
"metadata": null
},
"shipping_profile": {
"id": "sp_01F0YESTZQFW15SFEZSS29EZ5R",
"name": "Default Shipping Profile",
"type": "default",
"created_at": "2021-03-16T21:24:23.116Z",
"updated_at": "2021-03-16T21:24:23.116Z",
"deleted_at": null,
"metadata": null
},
"store": {
"id": "store_01F0YESXYNJNTJJY5G5Z26KHKJ",
"name": "Medusa Store",
"default_currency_code": "usd",
"default_currency": {
"code": "usd",
"symbol": "$",
"symbol_native": "$",
"name": "US Dollar"
},
"currencies": [],
"swap_link_template": null,
"created_at": "2021-03-16T21:24:26.191Z",
"updated_at": "2021-03-16T21:24:26.191Z",
"metadata": null,
"payment_providers": [
{
"id": "test-pay",
"is_installed": true
}
],
"fulfillment_providers": [
{
"id": "test-ful",
"is_installed": true
}
]
},
"user": {
"id": "admin_user",
"email": "admin@medusa.js",
"first_name": null,
"last_name": null,
"api_token": "test_token",
"created_at": "2021-03-16T21:24:29.411Z",
"updated_at": "2021-03-16T21:24:29.411Z",
"deleted_at": null,
"metadata": null
},
"notification": {
"id": "noti_01F0YET45G9NHP08Z66CE4QKBS",
"resource_type": "order",
"resource_id": "order_01F0BF66ZBXNJ98WDQ9SCWH8Y7",
"event_name": "order.placed",
"to": "test@email.com",
"provider_id": "test-not",
"created_at": "2021-03-16T21:24:32.560Z",
"updated_at": "2021-03-16T21:24:32.560Z",
"resends": []
},
"order": {
"id": "order_01F0YET7CZ741ECWG1J3N34RXF",
"status": "pending",
"fulfillment_status": "not_fulfilled",
"payment_status": "not_paid",
"display_id": 1,
"cart_id": null,
"customer_id": "cus_01F0YET7C3H3D5M8QPNPP5CDAX",
"customer": {
"id": "cus_01F0YET7C3H3D5M8QPNPP5CDAX",
"email": "test@email.com",
"first_name": null,
"last_name": null,
"billing_address_id": null,
"password_hash": null,
"phone": null,
"has_account": false,
"created_at": "2021-03-16T21:24:35.843Z",
"updated_at": "2021-03-16T21:24:35.843Z",
"deleted_at": null,
"metadata": null
},
"email": "test@email.com",
"billing_address": {
"id": "addr_01F0YET7CZZX0842X5AHQYAZ80",
"customer_id": null,
"company": null,
"first_name": "lebron",
"last_name": null,
"address_1": null,
"address_2": null,
"city": null,
"country_code": null,
"province": null,
"postal_code": null,
"phone": null,
"created_at": "2021-03-16T21:24:35.871Z",
"updated_at": "2021-03-16T21:24:35.871Z",
"deleted_at": null,
"metadata": null
},
"shipping_address": {
"id": "addr_01F0YET7CZDHXHXYJ3JTXPH4T7",
"customer_id": null,
"company": null,
"first_name": "lebron",
"last_name": null,
"address_1": null,
"address_2": null,
"city": null,
"country_code": "us",
"province": null,
"postal_code": null,
"phone": null,
"created_at": "2021-03-16T21:24:35.871Z",
"updated_at": "2021-03-16T21:24:35.871Z",
"deleted_at": null,
"metadata": null
},
"region_id": "reg_01F0YET7BZTARY9MKN1SJ7AAXF",
"region": {
"id": "reg_01F0YET7BZTARY9MKN1SJ7AAXF",
"name": "Test Region",
"currency_code": "usd",
"tax_rate": "0",
"tax_code": null,
"payment_providers": [],
"fulfillment_providers": [],
"created_at": "2021-03-16T21:24:35.839Z",
"updated_at": "2021-03-16T21:24:35.839Z",
"deleted_at": null,
"metadata": null
},
"currency_code": "usd",
"tax_rate": 0,
"discounts": [
{
"id": "test-discount",
"code": "TEST134",
"is_dynamic": false,
"rule_id": "dru_01F0YET7CZQDGWTFQYY8T4KYRZ",
"rule": {
"id": "dru_01F0YET7CZQDGWTFQYY8T4KYRZ",
"description": "Test Discount",
"type": "percentage",
"value": 10,
"allocation": "total",
"usage_limit": null,
"created_at": "2021-03-16T21:24:35.871Z",
"updated_at": "2021-03-16T21:24:35.871Z",
"deleted_at": null,
"metadata": null
},
"is_disabled": false,
"parent_discount_id": null,
"starts_at": "2021-03-16T21:24:35.871Z",
"ends_at": null,
"created_at": "2021-03-16T21:24:35.871Z",
"updated_at": "2021-03-16T21:24:35.871Z",
"deleted_at": null,
"metadata": null
}
],
"gift_cards": [],
"shipping_methods": [
{
"id": "sm_01F0YET7DR2E7CYVSDHM593QG2",
"shipping_option_id": "so_01F0YET7C758MMXF1WNVCPGKZJ",
"order_id": "order_01F0YET7CZ741ECWG1J3N34RXF",
"claim_order_id": null,
"cart_id": null,
"swap_id": null,
"return_id": null,
"shipping_option": {
"id": "so_01F0YET7C758MMXF1WNVCPGKZJ",
"name": "test-option",
"region_id": "reg_01F0YET7BZTARY9MKN1SJ7AAXF",
"profile_id": "sp_01F0YET7AF62TCC9CMWK5TXXAQ",
"provider_id": "test-ful",
"price_type": "flat_rate",
"amount": 1000,
"is_return": false,
"data": {},
"created_at": "2021-03-16T21:24:35.846Z",
"updated_at": "2021-03-16T21:24:35.846Z",
"deleted_at": null,
"metadata": null
},
"price": 1000,
"data": {}
}
],
"payments": [
{
"id": "test-payment",
"swap_id": null,
"cart_id": null,
"order_id": "order_01F0YET7CZ741ECWG1J3N34RXF",
"amount": 10000,
"currency_code": "usd",
"amount_refunded": 0,
"provider_id": "test",
"data": {},
"captured_at": null,
"canceled_at": null,
"created_at": "2021-03-16T21:24:35.871Z",
"updated_at": "2021-03-16T21:24:35.871Z",
"metadata": null,
"idempotency_key": null
}
],
"fulfillments": [],
"returns": [],
"claims": [],
"refunds": [],
"swaps": [],
"items": [
{
"id": "test-item",
"cart_id": null,
"order_id": "order_01F0YET7CZ741ECWG1J3N34RXF",
"swap_id": null,
"claim_order_id": null,
"title": "Line Item",
"description": "Line Item Desc",
"thumbnail": "https://test.js/1234",
"is_giftcard": false,
"should_merge": true,
"allow_discounts": true,
"has_shipping": null,
"unit_price": 8000,
"variant_id": "variant_01F0YET7BMD9FGWA5NTPBWT2SS",
"variant": {
"id": "variant_01F0YET7BMD9FGWA5NTPBWT2SS",
"title": "test variant",
"product_id": "prod_01F0YET7BA4AQ8WEK687BNWP3N",
"product": {
"id": "prod_01F0YET7BA4AQ8WEK687BNWP3N",
"title": "test product",
"subtitle": null,
"description": null,
"handle": "test-product",
"is_giftcard": false,
"thumbnail": null,
"profile_id": "sp_01F0YET7AF62TCC9CMWK5TXXAQ",
"weight": null,
"length": null,
"height": null,
"width": null,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"collection_id": null,
"type_id": null,
"created_at": "2021-03-16T21:24:35.818Z",
"updated_at": "2021-03-16T21:24:35.818Z",
"deleted_at": null,
"metadata": null
},
"sku": null,
"barcode": null,
"ean": null,
"upc": null,
"inventory_quantity": 1,
"allow_backorder": false,
"manage_inventory": true,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"weight": null,
"length": null,
"height": null,
"width": null,
"created_at": "2021-03-16T21:24:35.828Z",
"updated_at": "2021-03-16T21:24:35.828Z",
"deleted_at": null,
"metadata": null
},
"quantity": 1,
"fulfilled_quantity": 1,
"returned_quantity": null,
"shipped_quantity": null,
"created_at": "2021-03-16T21:24:35.871Z",
"updated_at": "2021-03-16T21:24:35.871Z",
"metadata": null,
"refundable": 7200
}
],
"gift_card_transactions": [],
"canceled_at": null,
"created_at": "2021-03-16T21:24:35.871Z",
"updated_at": "2021-03-16T21:24:35.871Z",
"metadata": null,
"shipping_total": 1000,
"gift_card_total": 0,
"discount_total": 800,
"tax_total": 0,
"subtotal": 8000,
"total": 8200,
"refunded_total": 0,
"refundable_amount": 8200
},
"return": {
"id": "ret_01F0YET7XPCMF8RZ0Y151NZV2V",
"status": "requested",
"items": [
{
"return_id": "ret_01F0YET7XPCMF8RZ0Y151NZV2V",
"item_id": "test-item",
"quantity": 1,
"is_requested": true,
"requested_quantity": 1,
"received_quantity": null,
"reason_id": null,
"reason": null,
"note": null,
"metadata": null
}
],
"swap_id": null,
"claim_order_id": null,
"order_id": "order_01F0YET7RD6NWQTEM0ZN5DRRVD",
"shipping_method": null,
"shipping_data": null,
"refund_amount": 7200,
"received_at": null,
"created_at": "2021-03-16T21:24:36.381Z",
"updated_at": "2021-03-16T21:24:36.381Z",
"metadata": null,
"idempotency_key": "f3dee891-7a24-4e34-9071-62606035563d"
},
"swap": {
"id": "swap_01F0YET86Y9G92D3YDR9Y6V676",
"fulfillment_status": "not_fulfilled",
"payment_status": "not_paid",
"order_id": "order_01F0YET82SR6NB8K61TNRN36FW",
"additional_items": [
{
"id": "item_01F0YET86YR1J3GX155E9R81A3",
"cart_id": "cart_01F0YET896KVZ17Y2QDVT28QFE",
"order_id": null,
"swap_id": "swap_01F0YET86Y9G92D3YDR9Y6V676",
"claim_order_id": null,
"title": "test product",
"description": "test variant",
"thumbnail": null,
"is_giftcard": false,
"should_merge": true,
"allow_discounts": true,
"has_shipping": null,
"unit_price": 8000,
"variant_id": "variant_01F0YET825M92TKN1ZGAVBPX1B",
"variant": {
"id": "variant_01F0YET825M92TKN1ZGAVBPX1B",
"title": "test variant",
"product_id": "prod_01F0YET8213X0J501ZZHZ56Y7Y",
"product": {
"id": "prod_01F0YET8213X0J501ZZHZ56Y7Y",
"title": "test product",
"subtitle": null,
"description": null,
"handle": "test-product",
"is_giftcard": false,
"thumbnail": null,
"profile_id": "sp_01F0YET7AF62TCC9CMWK5TXXAQ",
"weight": null,
"length": null,
"height": null,
"width": null,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"collection_id": null,
"type_id": null,
"created_at": "2021-03-16T21:24:36.545Z",
"updated_at": "2021-03-16T21:24:36.545Z",
"deleted_at": null,
"metadata": null
},
"sku": null,
"barcode": null,
"ean": null,
"upc": null,
"inventory_quantity": 1,
"allow_backorder": false,
"manage_inventory": true,
"hs_code": null,
"origin_country": null,
"mid_code": null,
"material": null,
"weight": null,
"length": null,
"height": null,
"width": null,
"created_at": "2021-03-16T21:24:36.549Z",
"updated_at": "2021-03-16T21:24:36.549Z",
"deleted_at": null,
"metadata": null
},
"quantity": 2,
"fulfilled_quantity": null,
"returned_quantity": null,
"shipped_quantity": null,
"created_at": "2021-03-16T21:24:36.659Z",
"updated_at": "2021-03-16T21:24:36.659Z",
"metadata": {}
}
],
"return_order": {
"id": "ret_01F0YET873ZAXQ7PYVKVFMT9FP",
"status": "requested",
"items": [
{
"return_id": "ret_01F0YET873ZAXQ7PYVKVFMT9FP",
"item_id": "test-item",
"quantity": 1,
"is_requested": true,
"requested_quantity": 1,
"received_quantity": null,
"reason_id": null,
"reason": null,
"note": null,
"metadata": null
}
],
"swap_id": "swap_01F0YET86Y9G92D3YDR9Y6V676",
"claim_order_id": null,
"order_id": null,
"shipping_method": null,
"shipping_data": null,
"refund_amount": 7200,
"received_at": null,
"created_at": "2021-03-16T21:24:36.659Z",
"updated_at": "2021-03-16T21:24:36.659Z",
"metadata": null,
"idempotency_key": null
},
"fulfillments": [],
"payment": null,
"difference_due": null,
"shipping_address_id": null,
"shipping_address": null,
"shipping_methods": [],
"cart_id": "cart_01F0YET896KVZ17Y2QDVT28QFE",
"confirmed_at": null,
"created_at": "2021-03-16T21:24:36.659Z",
"updated_at": "2021-03-16T21:24:36.659Z",
"deleted_at": null,
"metadata": null,
"idempotency_key": "10804103-2f4f-41ef-b44e-7049459f157d"
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+6 -3
View File
@@ -4,6 +4,7 @@
"workspaces": {
"packages": [
"packages/*",
"packages/oas/*",
"integration-tests/**/*"
]
},
@@ -19,6 +20,8 @@
"@babel/preset-react": "^7.18.6",
"@babel/register": "^7.11.5",
"@babel/runtime": "^7.11.2",
"@medusajs/medusa-oas-cli": "*",
"@readme/openapi-parser": "^2.4.0",
"@redocly/cli": "1.0.0-beta.123",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
@@ -33,11 +36,13 @@
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.11",
"execa": "^5.1.1",
"express": "^4.17.1",
"get-port": "^5.1.1",
"husky": "^7.0.4",
"import-from": "^3.0.0",
"jest": "^26.6.3",
"js-yaml": "^4.1.0",
"lint-staged": "^11.2.6",
"microbundle": "^0.13.3",
"pg-god": "^1.0.12",
@@ -89,9 +94,7 @@
"@linear/sdk": "^1.22.0",
"@octokit/core": "^4.0.5",
"global": "^4.4.0",
"import-from": "^3.0.0",
"oas-normalize": "^5.0.1",
"swagger-inline": "^3.2.3"
"import-from": "^3.0.0"
},
"packageManager": "yarn@3.2.1"
}
+6
View File
@@ -0,0 +1,6 @@
/dist
node_modules
.DS_store
.env*
.env
*.sql
+3
View File
@@ -0,0 +1,3 @@
# @medusajs/oas-cli
## 0.1.0
+72
View File
@@ -0,0 +1,72 @@
# medusa-oas-cli - 0.1.0 - experimental
A command-line tool for all OpenAPI Specifications (OAS) related tooling.
## Install
`yarn add --dev @medusajs/medusa-oas-cli`
Install in the global namespace is not yet supported.
~~`npm install -g @medusajs/medusa-oas-cli`~~
## Configuration / First time setup
N/A
## How to use
```bash
yarn medusa-oas <command>
```
### Command - `oas`
This command will scan the `@medusajs/medusa` package in order to extract JSDoc OAS into a json file.
By default, the command will output the two files `admin.oas.json` and `store.oas.json` in the same directory that the
command was run.
Invalid OAS with throw an error and will prevent the files from being outputted.
#### `--type <string>`
Specify which API OAS to create. Accepts `all`, `admin`, `store`.
Defaults to `all`.
```bash
yarn medusa-oas oas --type admin
```
#### `--out-dir <path>`
Specify in which directory should the files be outputted. It accepts a relative or absolute path.
If the directory doesn't exist, it will be created. Defaults to `./`.
```bash
yarm medusa-oas oas --out-dir
```
#### `--paths <paths...>`
Allows passing additional directory paths to crawl for JSDoc OAS and include in the generated OAS.
It accepts multiple entries.
```bash
yarn medusa-oas oas --paths ~/medusa-server/src
```
#### `--dry-run`
Will package the OAS but will not output file. Useful for validating OAS.
```bash
yarn medusa-oas oas --dry-run
```
#### `--force`
Ignore OAS errors and attempt to output generated OAS files.
```bash
yarn medusa-oas oas --force
```
+40
View File
@@ -0,0 +1,40 @@
{
"name": "@medusajs/medusa-oas-cli",
"version": "0.1.0",
"description": "OAS CLI",
"main": "dist/index.js",
"bin": {
"medusa-oas": "./dist/index.js"
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa",
"directory": "packages/oas/medusa-oas-cli"
},
"publishConfig": {
"access": "public"
},
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"ts-node": "^10.9.1",
"typescript": "4.9.5"
},
"scripts": {
"prepare": "cross-env NODE_ENV=production yarn run build",
"build": "tsc --build",
"cli": "ts-node src/index.ts",
"test": "jest --passWithNoTests",
"test:unit": "jest --passWithNoTests"
},
"dependencies": {
"@medusajs/medusa": "*",
"@readme/openapi-parser": "^2.4.0",
"commander": "^10.0.0",
"openapi3-ts": "^3.1.2",
"swagger-inline": "^6.1.0"
}
}
@@ -0,0 +1,149 @@
import * as path from "path"
import { lstat, mkdir, writeFile } from "fs/promises"
import swaggerInline from "swagger-inline"
import OpenAPIParser from "@readme/openapi-parser"
import { OpenAPIObject } from "openapi3-ts"
import { Command, Option, OptionValues } from "commander"
/**
* Constants
*/
// Medusa core package directory
const medusaPackagePath = path.dirname(
require.resolve("@medusajs/medusa/package.json")
)
type ApiType = "store" | "admin"
/**
* CLI Command declaration
*/
export const commandName = "oas"
export const commandDescription =
"Compile full OAS from swagger-inline compliant JSDoc."
export const commandOptions: Option[] = [
new Option("-t, --type <type>", "API type to compile []")
.choices(["all", "admin", "store"])
.default("all"),
new Option(
"-o, --out-dir <outDir>",
"Destination directory to output generated OAS files."
).default(process.cwd()),
new Option("-D, --dry-run", "Do not output files."),
new Option(
"-p, --paths <paths...>",
"Additional paths to crawl for OAS JSDoc."
),
new Option("-F, --force", "Ignore OAS validation and output OAS files."),
]
export function getCommand() {
const command = new Command(commandName)
command.description(commandDescription)
for (const opt of commandOptions) {
command.addOption(opt)
}
command.action(async (options) => await execute(options))
return command
}
/**
* Main
*/
export async function execute(cliParams: OptionValues) {
/**
* Process CLI options
*/
const dryRun = !!cliParams.dryRun
const force = !!cliParams.force
const apiTypesToExport =
cliParams.type === "all" ? ["store", "admin"] : [cliParams.type]
const outDir = path.resolve(cliParams.outDir)
const additionalPaths = (cliParams.paths ?? []).map((additionalPath) =>
path.resolve(additionalPath)
)
for (const additionalPath of additionalPaths) {
if (!(await isDirectory(additionalPath))) {
throw new Error(`--paths must be a directory - ${additionalPath}`)
}
}
/**
* Command execution
*/
if (!dryRun) {
await mkdir(outDir, { recursive: true })
}
for (const apiType of apiTypesToExport) {
console.log(`🟣 Generating OAS - ${apiType}`)
const oas = await getOASFromCodebase(apiType as ApiType, additionalPaths)
await validateOAS(oas, apiType as ApiType, force)
if (!dryRun) {
await exportOASToJSON(oas, apiType as ApiType, outDir)
}
}
}
/**
* Methods
*/
async function getOASFromCodebase(
apiType: ApiType,
additionalPaths: string[] = []
): Promise<OpenAPIObject> {
const gen = await swaggerInline(
[
path.resolve(medusaPackagePath, "dist", "models"),
path.resolve(medusaPackagePath, "dist", "types"),
path.resolve(medusaPackagePath, "dist", "api/middlewares"),
path.resolve(medusaPackagePath, "dist", `api/routes/${apiType}`),
...additionalPaths,
],
{
base: path.resolve(
medusaPackagePath,
"oas",
`${apiType}-spec3-base.yaml`
),
format: ".json",
}
)
return await OpenAPIParser.parse(JSON.parse(gen))
}
async function validateOAS(
oas: OpenAPIObject,
apiType: ApiType,
force = false
): Promise<void> {
try {
await OpenAPIParser.validate(JSON.parse(JSON.stringify(oas)))
console.log(`🟢 Valid OAS - ${apiType}`)
} catch (err) {
console.error(`🔴 Invalid OAS - ${apiType}`, err)
if (!force) {
process.exit(1)
}
}
}
async function exportOASToJSON(
oas: OpenAPIObject,
apiType: ApiType,
targetDir: string
): Promise<void> {
const json = JSON.stringify(oas, null, 2)
const filePath = path.resolve(targetDir, `${apiType}.oas.json`)
await writeFile(filePath, json)
console.log(`🔵 Exported OAS - ${apiType} - ${filePath}`)
}
async function isDirectory(dirPath: string): Promise<boolean> {
return (await lstat(path.resolve(dirPath))).isDirectory()
}
+22
View File
@@ -0,0 +1,22 @@
#! /usr/bin/env node
import { Command } from "commander"
import { getCommand as oasGetCommand } from "./command-oas"
const run = async () => {
const program = new Command()
/**
* Alias to command-oas.ts
*/
program.addCommand(oasGetCommand())
/**
* Run CLI
*/
await program.parseAsync()
}
void (async () => {
await run()
})()
+33
View File
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"lib": [
"es2019"
],
"target": "es2019",
"outDir": "./dist",
"esModuleInterop": true,
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"allowJs": true,
"skipLibCheck": true,
"downlevelIteration": true // to use ES5 specific tooling
},
"include": [
"src"
],
"exclude": [
"node_modules",
"**/tests/*"
],
"ts-node": {
"transpileOnly": true
}
}
+78 -138
View File
@@ -1,151 +1,91 @@
#!/usr/bin/env node
const fs = require("fs")
const OAS = require("oas-normalize")
const swaggerInline = require("swagger-inline")
const { exec } = require("child_process")
const fs = require("fs/promises")
const path = require("path")
const execa = require("execa")
const yaml = require("js-yaml")
const OpenAPIParser = require("@readme/openapi-parser")
const isDryRun = process.argv.indexOf("--dry-run") !== -1
const basePath = path.resolve(__dirname, `../`)
const docsApiPath = path.resolve(basePath, "docs/api/")
// Storefront API
swaggerInline(
[
"./packages/medusa/src/models",
"./packages/medusa/src/types",
"./packages/medusa/src/api/middlewares",
"./packages/medusa/src/api/routes/store",
],
{
base: "./docs/api/store-spec3-base.yaml",
const run = async () => {
await generateOASSources(docsApiPath, isDryRun)
if (isDryRun) {
return
}
)
.then((gen) => {
const oas = new OAS(gen)
oas
.validate(true)
.then(() => {
if (!isDryRun) {
fs.writeFileSync("./docs/api/store-spec3.json", gen)
}
})
.catch((err) => {
console.log("Error in store")
console.error(err)
process.exit(1)
})
})
.catch((err) => {
console.log("Error in store")
console.error(err)
process.exit(1)
})
swaggerInline(
[
"./packages/medusa/src/models",
"./packages/medusa/src/types",
"./packages/medusa/src/api/middlewares",
"./packages/medusa/src/api/routes/store",
],
{
base: "./docs/api/store-spec3-base.yaml",
format: "yaml",
}
)
.then((gen) => {
if (!isDryRun) {
fs.writeFileSync("./docs/api/store-spec3.yaml", gen)
exec(
[
"rm -rf docs/api/store/",
"yarn run -- redocly bundle docs/api/store-spec3.yaml -o docs/api/store-spec3.yaml --config=docs-util/redocly/config.yaml",
"yarn run -- redocly split docs/api/store-spec3.yaml --outDir=docs/api/store/",
].join(" && "),
(error, stdout, stderr) => {
if (error) {
throw new Error(`error: ${error.message}`)
}
console.log(`${stderr || stdout}`)
}
)
} else {
console.log("No errors occurred while generating Store API Reference")
}
})
.catch((err) => {
console.log("Error in store")
console.error(err)
process.exit(1)
})
for (const apiType of ["store", "admin"]) {
const inputJsonFile = path.resolve(docsApiPath, `${apiType}.oas.json`)
const outputYamlFile = path.resolve(docsApiPath, `${apiType}.oas.yaml`)
// Admin API
swaggerInline(
[
"./packages/medusa/src/models",
"./packages/medusa/src/types",
"./packages/medusa/src/api/middlewares",
"./packages/medusa/src/api/routes/admin",
],
{
base: "./docs/api/admin-spec3-base.yaml",
await jsonFileToYamlFile(inputJsonFile, outputYamlFile)
await sanitizeOAS(outputYamlFile)
await circularReferenceCheck(outputYamlFile)
await generateReference(outputYamlFile, apiType)
}
)
.then((gen) => {
const oas = new OAS(gen)
oas
.validate(true)
.then(() => {
if (!isDryRun) {
fs.writeFileSync("./docs/api/admin-spec3.json", gen)
}
})
.catch((err) => {
console.log("Error in admin")
console.error(err)
process.exit(1)
})
})
.catch((err) => {
console.log("Error in admin")
console.error(err)
process.exit(1)
})
}
swaggerInline(
[
"./packages/medusa/src/models",
"./packages/medusa/src/types",
"./packages/medusa/src/api/middlewares",
"./packages/medusa/src/api/routes/admin",
],
{
base: "./docs/api/admin-spec3-base.yaml",
format: "yaml",
const generateOASSources = async (outDir, isDryRun) => {
const params = ["oas", `--out-dir=${outDir}`]
if (isDryRun) {
params.push("--dry-run")
}
)
.then((gen) => {
if (!isDryRun) {
fs.writeFileSync("./docs/api/admin-spec3.yaml", gen)
exec(
[
"rm -rf docs/api/admin/",
"yarn run -- redocly bundle docs/api/admin-spec3.yaml -o docs/api/admin-spec3.yaml --config=docs-util/redocly/config.yaml",
"yarn run -- redocly split docs/api/admin-spec3.yaml --outDir=docs/api/admin/",
].join(" && "),
(error, stdout, stderr) => {
if (error) {
throw new Error(`error: ${error.message}`)
}
console.log(`${stderr || stdout}`)
return
}
)
} else {
console.log("No errors occurred while generating Admin API Reference")
}
const { all: logs } = await execa("medusa-oas", params, {
cwd: basePath,
all: true,
})
.catch((err) => {
console.log("Error in admin")
console.error(err)
process.exit(1)
console.log(logs)
}
const jsonFileToYamlFile = async (inputJsonFile, outputYamlFile) => {
const jsonString = await fs.readFile(inputJsonFile, "utf8")
const jsonObject = JSON.parse(jsonString)
const yamlString = yaml.dump(jsonObject)
await fs.writeFile(outputYamlFile, yamlString, "utf8")
}
const sanitizeOAS = async (srcFile) => {
const { all: logs } = await execa(
"redocly",
[
"bundle",
srcFile,
`--output=${srcFile}`,
"--config=docs-util/redocly/config.yaml",
],
{ cwd: basePath, all: true }
)
console.log(logs)
}
const circularReferenceCheck = async (srcFile) => {
const parser = new OpenAPIParser()
await parser.validate(srcFile, {
dereference: {
circular: "ignore",
},
})
if (parser.$refs.circular) {
console.log(`🔴 Unhandled circular references - ${srcFile}`)
const circularRefs = [...parser.$refs.circularRefs]
circularRefs.sort()
console.log(circularRefs)
}
}
const generateReference = async (srcFile, apiType) => {
const outDir = path.resolve(docsApiPath, `${apiType}`)
await fs.rm(outDir, { recursive: true, force: true })
const { all: logs } = await execa(
"redocly",
["split", srcFile, `--outDir=${outDir}`],
{ cwd: basePath, all: true }
)
console.log(logs)
}
void (async () => {
await run()
})()
+129 -58
View File
@@ -4807,6 +4807,22 @@ __metadata:
languageName: unknown
linkType: soft
"@medusajs/medusa-oas-cli@*, @medusajs/medusa-oas-cli@workspace:packages/oas/medusa-oas-cli":
version: 0.0.0-use.local
resolution: "@medusajs/medusa-oas-cli@workspace:packages/oas/medusa-oas-cli"
dependencies:
"@medusajs/medusa": "*"
"@readme/openapi-parser": ^2.4.0
commander: ^10.0.0
openapi3-ts: ^3.1.2
swagger-inline: ^6.1.0
ts-node: ^10.9.1
typescript: 4.9.5
bin:
medusa-oas: ./dist/index.js
languageName: unknown
linkType: soft
"@medusajs/medusa@*, @medusajs/medusa@^1.7.6, @medusajs/medusa@^1.7.7, @medusajs/medusa@workspace:packages/medusa":
version: 0.0.0-use.local
resolution: "@medusajs/medusa@workspace:packages/medusa"
@@ -5829,33 +5845,33 @@ __metadata:
languageName: node
linkType: hard
"@readme/json-schema-ref-parser@npm:^1.1.0":
version: 1.1.0
resolution: "@readme/json-schema-ref-parser@npm:1.1.0"
"@readme/json-schema-ref-parser@npm:^1.2.0":
version: 1.2.0
resolution: "@readme/json-schema-ref-parser@npm:1.2.0"
dependencies:
"@jsdevtools/ono": ^7.1.3
"@types/json-schema": ^7.0.6
call-me-maybe: ^1.0.1
js-yaml: ^4.1.0
checksum: 6d90e49ea53354f9d75fd7369b553774f0a9f4e1e3ad7e4be9140be1b469d2478b2a5c81283272f9948978509375d82568db744b77aa473dd0abde250da18693
checksum: 3a1d3dd7b5a8bcde2ca2ff894fcfebd1752fe633c24a6b6a9ad673dfb61a28e565bdb4beaeb3ac4dd022abeddd28833ac9e52adebe4e44254eede3b685157313
languageName: node
linkType: hard
"@readme/openapi-parser@npm:^2.1.1":
version: 2.2.0
resolution: "@readme/openapi-parser@npm:2.2.0"
"@readme/openapi-parser@npm:^2.4.0":
version: 2.4.0
resolution: "@readme/openapi-parser@npm:2.4.0"
dependencies:
"@apidevtools/openapi-schemas": ^2.1.0
"@apidevtools/swagger-methods": ^3.0.2
"@jsdevtools/ono": ^7.1.3
"@readme/better-ajv-errors": ^1.5.0
"@readme/json-schema-ref-parser": ^1.1.0
"@readme/json-schema-ref-parser": ^1.2.0
ajv: ^8.11.0
ajv-draft-04: ^1.0.0
call-me-maybe: ^1.0.1
peerDependencies:
openapi-types: ">=7"
checksum: 16f1056df3640e548b5403d2a658e517b0bfe2990ddfed79233ad1b0240da02297cd9c5aa393fa7b0427b09cec2c08bf5b7ca9f7cb370036dc86a5698e62ef07
checksum: e17414bf2b4e74ea928052451c18d6582021b47fc76ca05122bffc47aa180038722c61335cdbb7d7db38db05771aeab9fbe4baa3325608679e305f388e217f13
languageName: node
linkType: hard
@@ -10117,6 +10133,19 @@ __metadata:
languageName: node
linkType: hard
"array.prototype.map@npm:^1.0.5":
version: 1.0.5
resolution: "array.prototype.map@npm:1.0.5"
dependencies:
call-bind: ^1.0.2
define-properties: ^1.1.4
es-abstract: ^1.20.4
es-array-method-boxes-properly: ^1.0.0
is-string: ^1.0.7
checksum: cf44c0c958e94059d98132a3d5b7aa20d29aea34d20c515fdb236b69a95b1d3f1408f634f26fca51a9dbe06c85e93f7b351c85ea94300774af5ad2f1e8df3ae8
languageName: node
linkType: hard
"array.prototype.reduce@npm:^1.0.4":
version: 1.0.4
resolution: "array.prototype.reduce@npm:1.0.4"
@@ -11276,7 +11305,7 @@ __metadata:
languageName: node
linkType: hard
"bluebird@npm:^3.4.0, bluebird@npm:^3.4.1, bluebird@npm:^3.5.5, bluebird@npm:^3.7.2":
"bluebird@npm:^3.4.0, bluebird@npm:^3.5.5, bluebird@npm:^3.7.2":
version: 3.7.2
resolution: "bluebird@npm:3.7.2"
checksum: 680de03adc54ff925eaa6c7bb9a47a0690e8b5de60f4792604aae8ed618c65e6b63a7893b57ca924beaf53eee69c5af4f8314148c08124c550fe1df1add897d2
@@ -12798,6 +12827,13 @@ __metadata:
languageName: node
linkType: hard
"commander@npm:^10.0.0":
version: 10.0.0
resolution: "commander@npm:10.0.0"
checksum: f1824812019664598ba7409c489cb5c15d33f65b43b08952a84e87e0023144c08d101e2f43af968cf2d464c0d667b50a2a9780f4a6c52915324f54fe9b451a31
languageName: node
linkType: hard
"commander@npm:^2.19.0, commander@npm:^2.20.0, commander@npm:^2.20.3":
version: 2.20.3
resolution: "commander@npm:2.20.3"
@@ -12833,12 +12869,12 @@ __metadata:
languageName: node
linkType: hard
"comment-patterns@npm:^0.11.0":
version: 0.11.0
resolution: "comment-patterns@npm:0.11.0"
"comment-patterns@npm:^0.12.0":
version: 0.12.2
resolution: "comment-patterns@npm:0.12.2"
dependencies:
lodash: ^4.17.11
checksum: a0f022727e3e10321d5863007d9132a67793e99aa89c539008326c480748110045d2c46abab718a7606df7d043e3ce1202c03053c55dafca968679c3c1843e5f
checksum: 912953259d7c259ca3a515259d12df75983c37e6ebc9879734c7e7f9a5290038e63bb163cf9e79371835e216e34b55a4ff884535b2f1656911aca7a78c6a3aea
languageName: node
linkType: hard
@@ -15118,6 +15154,21 @@ __metadata:
languageName: node
linkType: hard
"es-aggregate-error@npm:^1.0.9":
version: 1.0.9
resolution: "es-aggregate-error@npm:1.0.9"
dependencies:
define-properties: ^1.1.4
es-abstract: ^1.20.4
function-bind: ^1.1.1
functions-have-names: ^1.2.3
get-intrinsic: ^1.1.3
globalthis: ^1.0.3
has-property-descriptors: ^1.0.0
checksum: b977bfd94546b0f853b93112e0804a0901fd6bca4829012265f8d8266c6ef20f68b2e6cbae23425926920e37fc91b18eff1142c7481a25670d054dea9790827c
languageName: node
linkType: hard
"es-array-method-boxes-properly@npm:^1.0.0":
version: 1.0.0
resolution: "es-array-method-boxes-properly@npm:1.0.0"
@@ -17543,7 +17594,7 @@ __metadata:
languageName: node
linkType: hard
"functions-have-names@npm:^1.2.2":
"functions-have-names@npm:^1.2.2, functions-have-names@npm:^1.2.3":
version: 1.2.3
resolution: "functions-have-names@npm:1.2.3"
checksum: 33e77fd29bddc2d9bb78ab3eb854c165909201f88c75faa8272e35899e2d35a8a642a15e7420ef945e1f64a9670d6aa3ec744106b2aa42be68ca5114025954ca
@@ -18454,7 +18505,7 @@ __metadata:
languageName: node
linkType: hard
"globalthis@npm:^1.0.0":
"globalthis@npm:^1.0.0, globalthis@npm:^1.0.3":
version: 1.0.3
resolution: "globalthis@npm:1.0.3"
dependencies:
@@ -26252,15 +26303,15 @@ __metadata:
languageName: node
linkType: hard
"multilang-extract-comments@npm:^0.3.2":
version: 0.3.3
resolution: "multilang-extract-comments@npm:0.3.3"
"multilang-extract-comments@npm:^0.4.0":
version: 0.4.0
resolution: "multilang-extract-comments@npm:0.4.0"
dependencies:
comment-patterns: ^0.11.0
comment-patterns: ^0.12.0
line-counter: ^1.0.3
lodash: ^4.17.11
quotemeta: 0.0.0
checksum: 86b27810e0716015f93435727c9c3553de5d252fb519e2b971ce06d593b0c9e0cce6561796884a6dfa2047c74756e7fe69bc0c1966a3d96d632e34c173df54e7
checksum: 6fa800c38d928d34cbbf32fea4a0ec04e5acc2f4ef051ce44f8911eaebb4a338058de2ee2b76e0e6dc422a9a23456ed08ff02745f91cc75ecf8b95ae08e7deb7
languageName: node
linkType: hard
@@ -26971,18 +27022,6 @@ __metadata:
languageName: node
linkType: hard
"oas-normalize@npm:^5.0.1":
version: 5.2.1
resolution: "oas-normalize@npm:5.2.1"
dependencies:
"@readme/openapi-parser": ^2.1.1
js-yaml: ^4.1.0
node-fetch: ^2.6.1
swagger2openapi: ^7.0.8
checksum: 5a5aba25528511644a5abe50535b2ce8a9ac05facefc5dab284446d68fc918d18f2b84c4bc5e590f1e372b74d108cd5b421649b69f419f45408c7520b8931720
languageName: node
linkType: hard
"oas-resolver@npm:^2.5.6":
version: 2.5.6
resolution: "oas-resolver@npm:2.5.6"
@@ -27321,6 +27360,15 @@ __metadata:
languageName: node
linkType: hard
"openapi3-ts@npm:^3.1.2":
version: 3.1.2
resolution: "openapi3-ts@npm:3.1.2"
dependencies:
yaml: ^2.1.3
checksum: 5dc9c24e5ae8d3b39880eef076a56dc1e905b4f863b5102591b8e3a43230d7a2cac1d12017894a1b7764a6ce390960e787a9368bac7bc163fa59894e493fc064
languageName: node
linkType: hard
"opencollective-postinstall@npm:^2.0.0":
version: 2.0.3
resolution: "opencollective-postinstall@npm:2.0.3"
@@ -29245,6 +29293,21 @@ __metadata:
languageName: node
linkType: hard
"promise.any@npm:^2.0.2":
version: 2.0.5
resolution: "promise.any@npm:2.0.5"
dependencies:
array.prototype.map: ^1.0.5
call-bind: ^1.0.2
define-properties: ^1.1.4
es-abstract: ^1.20.4
es-aggregate-error: ^1.0.9
get-intrinsic: ^1.1.3
iterate-value: ^1.0.2
checksum: fc573c2f3f13719284d577c0b1fbecdcd84552de1bbf2d59133e140931fd90a284ebba7d51d1e288ed15550b0f340f96805126547a9a0b30cb10da02a34b1c70
languageName: node
linkType: hard
"promise.prototype.finally@npm:^3.1.0, promise.prototype.finally@npm:^3.1.2":
version: 3.1.3
resolution: "promise.prototype.finally@npm:3.1.3"
@@ -31146,7 +31209,9 @@ __metadata:
"@changesets/changelog-github": ^0.4.8
"@changesets/cli": ^2.26.0
"@linear/sdk": ^1.22.0
"@medusajs/medusa-oas-cli": "*"
"@octokit/core": ^4.0.5
"@readme/openapi-parser": ^2.4.0
"@redocly/cli": 1.0.0-beta.123
"@typescript-eslint/eslint-plugin": ^5.36.2
"@typescript-eslint/parser": ^5.36.2
@@ -31161,19 +31226,19 @@ __metadata:
eslint-plugin-markdown: ^3.0.0
eslint-plugin-prettier: ^4.2.1
eslint-plugin-react: ^7.31.11
execa: ^5.1.1
express: ^4.17.1
get-port: ^5.1.1
global: ^4.4.0
husky: ^7.0.4
import-from: ^3.0.0
jest: ^26.6.3
js-yaml: ^4.1.0
lint-staged: ^11.2.6
microbundle: ^0.13.3
oas-normalize: ^5.0.1
pg-god: ^1.0.12
prettier: ^2.7.1
resolve-cwd: ^3.0.0
swagger-inline: ^3.2.3
ts-jest: ^26.5.6
ts-node: ^10.9.1
turbo: ^1.6.3
@@ -33229,23 +33294,22 @@ __metadata:
languageName: node
linkType: hard
"swagger-inline@npm:^3.2.3":
version: 3.2.3
resolution: "swagger-inline@npm:3.2.3"
"swagger-inline@npm:^6.1.0":
version: 6.1.1
resolution: "swagger-inline@npm:6.1.1"
dependencies:
bluebird: ^3.4.1
commander: ^6.0.0
globby: ^11.0.1
js-yaml: ^3.13.1
lodash: ^4.17.11
multilang-extract-comments: ^0.3.2
js-yaml: ^4.1.0
multilang-extract-comments: ^0.4.0
promise.any: ^2.0.2
bin:
swagger-inline: build/index.js
checksum: a714b77b7c8445dec6eacd6d532c2720d2a8a49c4c3ff4d4be261be240c52e41b53f66f07cd40fe2872aa4eee90ae6902c4767b01d7c3d19ecb85cbb86b9cf8f
swagger-inline: bin/swagger-inline
checksum: 2423c4d244d2104290bd44a59a1635cf1920f6ed5913f8841266ca8a59bd1d40ec3b710113064d45e00cc75f89b988b74ee96651b20f473dc2fd4d374fb3f211
languageName: node
linkType: hard
"swagger2openapi@npm:^7.0.6, swagger2openapi@npm:^7.0.8":
"swagger2openapi@npm:^7.0.6":
version: 7.0.8
resolution: "swagger2openapi@npm:7.0.8"
dependencies:
@@ -34682,6 +34746,16 @@ __metadata:
languageName: node
linkType: hard
"typescript@npm:4.9.5, typescript@npm:^4.9.5":
version: 4.9.5
resolution: "typescript@npm:4.9.5"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 5f6cad2e728a8a063521328e612d7876e12f0d8a8390d3b3aaa452a6a65e24e9ac8ea22beb72a924fd96ea0a49ea63bb4e251fb922b12eedfb7f7a26475e5c56
languageName: node
linkType: hard
"typescript@npm:^4.1.3, typescript@npm:^4.4.4, typescript@npm:^4.5.2":
version: 4.7.4
resolution: "typescript@npm:4.7.4"
@@ -34692,13 +34766,13 @@ __metadata:
languageName: node
linkType: hard
"typescript@npm:^4.9.5":
"typescript@patch:typescript@4.9.5#~builtin<compat/typescript>, typescript@patch:typescript@^4.9.5#~builtin<compat/typescript>":
version: 4.9.5
resolution: "typescript@npm:4.9.5"
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=7ad353"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 5f6cad2e728a8a063521328e612d7876e12f0d8a8390d3b3aaa452a6a65e24e9ac8ea22beb72a924fd96ea0a49ea63bb4e251fb922b12eedfb7f7a26475e5c56
checksum: 897c8ac656e01b132fa82be6a8e34c4507b19be63dbf1ff1d8287d775519081a7c91dd0ca3ec62536c8137228141d65b238dfb2e8987a3f5182818f58f83e7d7
languageName: node
linkType: hard
@@ -34712,16 +34786,6 @@ __metadata:
languageName: node
linkType: hard
"typescript@patch:typescript@^4.9.5#~builtin<compat/typescript>":
version: 4.9.5
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=7ad353"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 897c8ac656e01b132fa82be6a8e34c4507b19be63dbf1ff1d8287d775519081a7c91dd0ca3ec62536c8137228141d65b238dfb2e8987a3f5182818f58f83e7d7
languageName: node
linkType: hard
"ua-parser-js@npm:^0.7.30":
version: 0.7.31
resolution: "ua-parser-js@npm:0.7.31"
@@ -36572,6 +36636,13 @@ __metadata:
languageName: node
linkType: hard
"yaml@npm:^2.1.3":
version: 2.2.1
resolution: "yaml@npm:2.2.1"
checksum: 12f3a73f2d28970d146184b1425d32a63f65e9f4840eeab09155a4d23a15be8401ac7a3a09b6626895ccf853c1b9069450957c0ad82cfe591369aaa58d1593d6
languageName: node
linkType: hard
"yargs-parser@npm:18.x, yargs-parser@npm:^18.1.2, yargs-parser@npm:^18.1.3":
version: 18.1.3
resolution: "yargs-parser@npm:18.1.3"