Skip to content
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

[IDP-1766] Improve configuration #10

Merged
merged 11 commits into from
Jul 9, 2024
Merged

Conversation

tjosepo
Copy link
Member

@tjosepo tjosepo commented Jul 3, 2024

Description of changes

The whole design of this feature is heavily inspired by Vite. See InlineConfig, resolveconfig() and CLI

Improves CLI configuration with commander:

$ pnpm exec create-schemas --help

Usage: create-schemas [options] [input]

Options:
  -v, --version        display version number
  -c, --config <file>  use specified config file (default: "create-schemas.config")
  -i, --input <path>   path to the OpenAPI schema file
  -o, --output <path>  output file path (default: "openapi-types.ts")
  --cwd <path>         path to working directory (default: ".")
  -h, --help           display available CLI options

Add support for config file with c12:

// create-schemas.config.ts
import { defineConfig } from "@workleap/create-schemas";

export default defineConfig({
  input: "v1.yaml",
  output: "codegen/schema.ts",
  openApiTsOptions: {
    enum: true,
  },
});

User configuration is now validated with zod (feel free to bikeshed on the format of the message):

$ pnpm exec create-schemas -o out.ts

Invalid configuration:
 - input: Required
Use --help to see available options.

Breaking changes

The openapi-typescript command line arguments are no longer supported on the CLI. Instead, they need to be declared in the configuration file in the openApiTsOptions property.

Additional checks

As mentionned, still waiting for #8 and #9 to get merged. Once they are merged, I will update this PR to include a changeset and tests.

@tjosepo tjosepo force-pushed the feature/idp-1766_improve_config branch from 39be001 to 695e648 Compare July 4, 2024 15:50
@tjosepo tjosepo marked this pull request as ready for review July 4, 2024 15:51
@tjosepo tjosepo requested a review from a team as a code owner July 4, 2024 15:51
@tjosepo
Copy link
Member Author

tjosepo commented Jul 5, 2024

Paths have been fixed (Until proven otherwise 😅)

During the resolveConfig() function, all paths are transformed into URL strings (either file:// or https:// URLs). These URLs are fully qualified. Depending on the usage, they can be converted back into file paths or into instances of the URL class.

.changeset/old-impalas-tie.md Outdated Show resolved Hide resolved
packages/create-schemas/package.json Show resolved Hide resolved
packages/create-schemas/src/utils.ts Show resolved Hide resolved
packages/create-schemas/src/utils.ts Show resolved Hide resolved
packages/create-schemas/tests/e2e.test.ts Show resolved Hide resolved
packages/create-schemas/tests/utils.test.ts Show resolved Hide resolved
packages/create-schemas/src/utils.ts Show resolved Hide resolved
@tjosepo tjosepo merged commit 868734a into main Jul 9, 2024
2 checks passed
@github-actions github-actions bot mentioned this pull request Jul 4, 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.

3 participants