Skip to content

[IDP-1766] Improve configuration#10

Merged
Tommy Josépovic (tjosepo) merged 11 commits intomainfrom
feature/idp-1766_improve_config
Jul 9, 2024
Merged

[IDP-1766] Improve configuration#10
Tommy Josépovic (tjosepo) merged 11 commits intomainfrom
feature/idp-1766_improve_config

Conversation

@tjosepo
Copy link
Member

@tjosepo Tommy Josépovic (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 Tommy Josépovic (tjosepo) force-pushed the feature/idp-1766_improve_config branch from 39be001 to 695e648 Compare July 4, 2024 15:50
@tjosepo Tommy Josépovic (tjosepo) marked this pull request as ready for review July 4, 2024 15:51
@tjosepo Tommy Josépovic (tjosepo) requested a review from a team as a code owner July 4, 2024 15:51
@tjosepo
Copy link
Member Author

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.

@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