Skip to content

Fix remote path item object $refs #1246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2023
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/stupid-pens-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-typescript": patch
---

Fix remote path item object $refs
38 changes: 19 additions & 19 deletions packages/openapi-typescript/examples/digital-ocean-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3984,7 +3984,7 @@ export interface external {
*/
type?: "custom" | "lets_encrypt";
};
/** Custom Certificate Request */ certificate_request_custom: certificate_create_base[] & {
/** Custom Certificate Request */ certificate_request_custom: external["resources/certificates/models/certificate_create.yml"]["certificate_create_base"] & {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generating incorrectly before due to an unrelated bug. Fix was easy; we just didn’t have a test for it before.

/**
* @description The contents of a PEM-formatted private-key corresponding to the SSL certificate.
* @example -----BEGIN PRIVATE KEY-----
Expand Down Expand Up @@ -4113,7 +4113,7 @@ export interface external {
*/
certificate_chain?: string;
};
/** Let's Encrypt Certificate Request */ certificate_request_lets_encrypt: certificate_create_base[] & {
/** Let's Encrypt Certificate Request */ certificate_request_lets_encrypt: external["resources/certificates/models/certificate_create.yml"]["certificate_create_base"] & {
/**
* @description An array of fully qualified domain names (FQDNs) for which the certificate was issued. A certificate covering all subdomains can be issued using a wildcard (e.g. `*.example.com`).
* @example [
Expand Down Expand Up @@ -7686,14 +7686,14 @@ export interface external {
*/
type: "enable_backups" | "disable_backups" | "reboot" | "power_cycle" | "shutdown" | "power_off" | "power_on" | "restore" | "password_reset" | "resize" | "rebuild" | "rename" | "change_kernel" | "enable_ipv6" | "snapshot";
};
droplet_action_restore: droplet_action[] & {
droplet_action_restore: external["resources/droplets/models/droplet_actions.yml"]["droplet_action"] & {
/**
* @description The ID of a backup of the current Droplet instance to restore from.
* @example 12389723
*/
image?: number;
};
droplet_action_resize: droplet_action[] & {
droplet_action_resize: external["resources/droplets/models/droplet_actions.yml"]["droplet_action"] & {
/**
* @description When `true`, the Droplet's disk will be resized in addition to its RAM and CPU. This is a permanent change and cannot be reversed as a Droplet's disk size cannot be decreased.
* @example true
Expand All @@ -7705,28 +7705,28 @@ export interface external {
*/
size?: string;
};
droplet_action_rebuild: droplet_action[] & ({
droplet_action_rebuild: external["resources/droplets/models/droplet_actions.yml"]["droplet_action"] & ({
/**
* @description The image ID of a public or private image or the slug identifier for a public image. The Droplet will be rebuilt using this image as its base.
* @example ubuntu-20-04-x64
*/
image?: string | number;
});
droplet_action_rename: droplet_action[] & {
droplet_action_rename: external["resources/droplets/models/droplet_actions.yml"]["droplet_action"] & {
/**
* @description The new name for the Droplet.
* @example nifty-new-name
*/
name?: string;
};
droplet_action_change_kernel: droplet_action[] & {
droplet_action_change_kernel: external["resources/droplets/models/droplet_actions.yml"]["droplet_action"] & {
/**
* @description A unique number used to identify and reference a specific kernel.
* @example 12389723
*/
kernel?: number;
};
droplet_action_snapshot: droplet_action[] & {
droplet_action_snapshot: external["resources/droplets/models/droplet_actions.yml"]["droplet_action"] & {
/**
* @description The name to give the new snapshot of the Droplet.
* @example Nifty New Snapshot
Expand Down Expand Up @@ -9037,10 +9037,10 @@ export interface external {
};
floating_ip_action_unassign: {
type: undefined;
} & Omit<floatingIPsAction[], "type"> & Record<string, never>;
} & Omit<external["resources/floating_ips/models/floating_ip_actions.yml"]["floatingIPsAction"], "type"> & Record<string, never>;
floating_ip_action_assign: {
type: undefined;
} & Omit<floatingIPsAction[], "type"> & {
} & Omit<external["resources/floating_ips/models/floating_ip_actions.yml"]["floatingIPsAction"], "type"> & {
/**
* @description The ID of the Droplet that the floating IP will be assigned to.
* @example 758604968
Expand Down Expand Up @@ -9850,7 +9850,7 @@ export interface external {
*/
type: "convert" | "transfer";
};
image_action_transfer: image_action_base[] & {
image_action_transfer: external["resources/images/models/image_action.yml"]["image_action_base"] & {
region: external["shared/attributes/region_slug.yml"];
};
};
Expand Down Expand Up @@ -10672,7 +10672,7 @@ export interface external {
* }
* ]
*/
load_balancers?: associated_kubernetes_resource[][];
load_balancers?: external["resources/kubernetes/models/associated_kubernetes_resources.yml"]["associated_kubernetes_resource"][];
/**
* @description A list of names and IDs for associated volumes that can be destroyed along with the cluster.
* @example [
Expand All @@ -10682,7 +10682,7 @@ export interface external {
* }
* ]
*/
volumes?: associated_kubernetes_resource[][];
volumes?: external["resources/kubernetes/models/associated_kubernetes_resources.yml"]["associated_kubernetes_resource"][];
/**
* @description A list of names and IDs for associated volume snapshots that can be destroyed along with the cluster.
* @example [
Expand All @@ -10692,7 +10692,7 @@ export interface external {
* }
* ]
*/
volume_snapshots?: associated_kubernetes_resource[][];
volume_snapshots?: external["resources/kubernetes/models/associated_kubernetes_resources.yml"]["associated_kubernetes_resource"][];
};
associated_kubernetes_resource: {
/**
Expand Down Expand Up @@ -13771,10 +13771,10 @@ export interface external {
};
reserved_ip_action_unassign: {
type: undefined;
} & Omit<reserved_ip_action_type[], "type"> & Record<string, never>;
} & Omit<external["resources/reserved_ips/models/reserved_ip_actions.yml"]["reserved_ip_action_type"], "type"> & Record<string, never>;
reserved_ip_action_assign: {
type: undefined;
} & Omit<reserved_ip_action_type[], "type"> & {
} & Omit<external["resources/reserved_ips/models/reserved_ip_actions.yml"]["reserved_ip_action_type"], "type"> & {
/**
* @description The ID of the Droplet that the reserved IP will be assigned to.
* @example 758604968
Expand Down Expand Up @@ -15984,7 +15984,7 @@ export interface external {
}
"shared/pages.yml": {
pagination: {
links?: page_links[];
links?: external["shared/pages.yml"]["page_links"];
};
page_links: {
/**
Expand All @@ -15997,8 +15997,8 @@ export interface external {
*/
pages?: unknown;
};
backward_links: link_to_first_page[] & link_to_prev_page[];
forward_links: link_to_last_page[] & link_to_next_page[];
backward_links: external["shared/pages.yml"]["link_to_first_page"] & external["shared/pages.yml"]["link_to_prev_page"];
forward_links: external["shared/pages.yml"]["link_to_last_page"] & external["shared/pages.yml"]["link_to_next_page"];
link_to_first_page: {
/**
* @description URI of the first page of the results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ kubernetes_node_pool_base:
type: object
nullable: true
example: null
description: An object containing a set of Kubernetes labels. The keys and
are values are both user-defined.
description: An object of key/value mappings specifying labels to apply
to all nodes in a pool. Labels will automatically be applied to all
existing nodes and any subsequent nodes added to the pool. Note that
when a label is removed, it is not deleted from the nodes in the pool.

taints:
type: array
items:
$ref: "#/kubernetes_node_pool_taint"
description: An array of taints to apply to all nodes in a pool. Taints
will automatically be applied to all existing nodes and any subsequent
nodes added to the pool. When a taint is removed, it is removed from
nodes added to the pool. When a taint is removed, it is deleted from
all nodes in the pool.

auto_scale:
Expand Down
18 changes: 18 additions & 0 deletions packages/openapi-typescript/examples/stripe-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,7 @@ export interface components {
account_business_profile: {
/** @description [The merchant category code for the account](https://stripe.com/docs/connect/setting-mcc). MCCs are used to classify businesses based on the goods or services they provide. */
mcc?: string | null;
monthly_estimated_revenue?: components["schemas"]["account_monthly_estimated_revenue"];
/** @description The customer-facing business name. */
name?: string | null;
/** @description Internal-only description of the product sold or service provided by the business. It's used by Stripe for risk and underwriting purposes. */
Expand Down Expand Up @@ -2433,6 +2434,13 @@ export interface components {
/** @description The URL for the account link. */
url: string;
};
/** AccountMonthlyEstimatedRevenue */
account_monthly_estimated_revenue: {
/** @description A non-negative integer representing how much to charge in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal). */
amount: number;
/** @description Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies). */
currency: string;
};
/** AccountPaymentsSettings */
account_payments_settings: {
/** @description The default text that appears on credit card statements when a charge is made. This field prefixes any dynamic `statement_descriptor` specified on the charge. */
Expand Down Expand Up @@ -16326,6 +16334,11 @@ export interface operations {
*/
business_profile?: {
mcc?: string;
/** monthly_estimated_revenue_specs */
monthly_estimated_revenue?: {
amount: number;
currency: string;
};
name?: string;
product_description?: string;
/** address_specs */
Expand Down Expand Up @@ -16849,6 +16862,11 @@ export interface operations {
*/
business_profile?: {
mcc?: string;
/** monthly_estimated_revenue_specs */
monthly_estimated_revenue?: {
amount: number;
currency: string;
};
name?: string;
product_description?: string;
/** address_specs */
Expand Down
47 changes: 47 additions & 0 deletions packages/openapi-typescript/examples/stripe-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ components:
maxLength: 5000
nullable: true
type: string
monthly_estimated_revenue:
$ref: '#/components/schemas/account_monthly_estimated_revenue'
name:
description: The customer-facing business name.
maxLength: 5000
Expand Down Expand Up @@ -291,6 +293,7 @@ components:
title: AccountBusinessProfile
type: object
x-expandableFields:
- monthly_estimated_revenue
- support_address
account_capabilities:
description: ''
Expand Down Expand Up @@ -1032,6 +1035,28 @@ components:
type: object
x-expandableFields: []
x-resourceId: account_link
account_monthly_estimated_revenue:
description: ''
properties:
amount:
description: >-
A non-negative integer representing how much to charge in the
[smallest currency
unit](https://stripe.com/docs/currencies#zero-decimal).
type: integer
currency:
description: >-
Three-letter [ISO currency
code](https://www.iso.org/iso-4217-currency-codes.html), in
lowercase. Must be a [supported
currency](https://stripe.com/docs/currencies).
type: string
required:
- amount
- currency
title: AccountMonthlyEstimatedRevenue
type: object
x-expandableFields: []
account_payments_settings:
description: ''
properties:
Expand Down Expand Up @@ -39941,6 +39966,17 @@ paths:
mcc:
maxLength: 4
type: string
monthly_estimated_revenue:
properties:
amount:
type: integer
currency:
type: string
required:
- amount
- currency
title: monthly_estimated_revenue_specs
type: object
name:
maxLength: 5000
type: string
Expand Down Expand Up @@ -41086,6 +41122,17 @@ paths:
mcc:
maxLength: 4
type: string
monthly_estimated_revenue:
properties:
amount:
type: integer
currency:
type: string
required:
- amount
- currency
title: monthly_estimated_revenue_specs
type: object
name:
maxLength: 5000
type: string
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"test": "run-p -s test:*",
"test:js": "vitest run",
"test:ts": "tsc --noEmit",
"update:examples": "vite-node ./scripts/update-examples.ts",
"update:examples": "pnpm run download:schemas && vite-node ./scripts/update-examples.ts",
"prepublish": "pnpm run build",
"version": "pnpm run build"
},
Expand Down
24 changes: 11 additions & 13 deletions packages/openapi-typescript/scripts/download-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@ import { fileURLToPath } from "node:url";
import degit from "degit";
import { fetch } from "undici";
import { error } from "../src/utils.js";

export const singleFile = {
"github-api": "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.yaml",
"github-api-next": "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.yaml",
"octokit-ghes-3.6-diff-to-api": "https://raw.githubusercontent.com/octokit/octokit-next.js/main/cache/types-openapi/ghes-3.6-diff-to-api.github.com.json",
"stripe-api": "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.yaml",
};
export const multiFile = {
"digital-ocean-api": {
repo: "https://github.com/digitalocean/openapi/specification",
entry: "./DigitalOcean-public.v2.yaml",
},
};
import { multiFile, singleFile } from "./schemas.js";

const ONE_DAY = 1000 * 60 * 60 * 24;
const EXAMPLES_DIR = new URL("../examples/", import.meta.url);

export async function download() {
const allSchemas = Object.keys({ ...singleFile, ...multiFile });
let done = 0;
console.log("Downloading schemas..."); // eslint-disable-line no-console
await Promise.all([
...Object.entries(singleFile).map(async ([k, url]) => {
const start = performance.now();
const ext = path.extname(url);
const dest = new URL(`${k}${ext}`, EXAMPLES_DIR);
if (fs.existsSync(dest)) {
Expand All @@ -37,8 +29,11 @@ export async function download() {
}
fs.mkdirSync(new URL(".", dest), { recursive: true });
fs.writeFileSync(dest, await result.text());
done++;
console.log(`✔︎ [${done}/${allSchemas.length}] Downloaded ${k} (${Math.round(performance.now() - start)}ms)`); // eslint-disable-line no-console
}),
...Object.entries(multiFile).map(async ([k, meta]) => {
const start = performance.now();
const dest = new URL(k, EXAMPLES_DIR);
if (fs.existsSync(dest)) {
const { mtime } = fs.statSync(dest);
Expand All @@ -48,8 +43,11 @@ export async function download() {
force: true,
});
await emitter.clone(fileURLToPath(new URL(k, EXAMPLES_DIR)));
done++;
console.log(`✔︎ [${done}/${allSchemas.length}] Downloaded ${k} (${Math.round(performance.now() - start)}ms)`); // eslint-disable-line no-console
}),
]);
console.log("Downloading schemas done."); // eslint-disable-line no-console
}

download();
12 changes: 12 additions & 0 deletions packages/openapi-typescript/scripts/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const singleFile = {
"github-api": "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.yaml",
"github-api-next": "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.yaml",
"octokit-ghes-3.6-diff-to-api": "https://raw.githubusercontent.com/octokit/octokit-next.js/main/cache/types-openapi/ghes-3.6-diff-to-api.github.com.json",
"stripe-api": "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.yaml",
};
export const multiFile = {
"digital-ocean-api": {
repo: "https://github.com/digitalocean/openapi/specification",
entry: "./DigitalOcean-public.v2.yaml",
},
};
Loading