Skip to content

fix(docs): createTypeReferenceNode in transform examples #1753

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 8, 2024

Conversation

danmichaelo
Copy link
Contributor

@danmichaelo danmichaelo commented Jul 8, 2024

Changes

Fixes #1688

How to Review

Verify example from docs:

# test1.ts
import path from "node:path";
import { fileURLToPath } from "node:url";
import openapiTS, { astToString } from "openapi-typescript";
import ts from "typescript";

const BLOB = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Blob")); // `Blob`
const NULL = ts.factory.createLiteralTypeNode(ts.factory.createNull()); // `null`

const baseDir = path.dirname(fileURLToPath(import.meta.url));
const mySchema = new URL(path.resolve(baseDir, "../test1.yaml"), import.meta.url);

const ast = await openapiTS(mySchema, {
  transform(schemaObject, metadata) {
    if (schemaObject.format === "binary") {
      return {
        schema: schemaObject.nullable ? ts.factory.createUnionTypeNode([BLOB, NULL]) : BLOB,
        questionToken: true,
      };
    }
  },
});

console.log(astToString(ast));

using a minimal example:

# test1.yaml
openapi: "3.0"
paths:
  /test:
    post:
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                source:
                  type: string
                file:
                  type: string
                  format: binary

Checklist

  • docs/ updated (if necessary)

@danmichaelo danmichaelo requested a review from a team as a code owner July 8, 2024 10:27
Copy link

changeset-bot bot commented Jul 8, 2024

⚠️ No Changeset found

Latest commit: 1e3c5d8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

Thank you!

@drwpow drwpow merged commit 8b103e2 into openapi-ts:main Jul 8, 2024
7 checks passed
@danmichaelo danmichaelo deleted the fix-docs-issue branch July 8, 2024 19:56
kerwanp pushed a commit to kerwanp/openapi-typescript that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v7] transform + nullable issue with Identifier with Node.js API
2 participants