Skip to content

feat: add immutable types #1350

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

J3MPA
Copy link

@J3MPA J3MPA commented Aug 5, 2025

In a functional codebase consumers of swagger-typescript-api would want to force properties and values to be immutable even if swagger spec does not have readOnly property.

With this change one can simply add --make-immutable or set makeImmutable to force immutable types.

Copy link

changeset-bot bot commented Aug 5, 2025

🦋 Changeset detected

Latest commit: b0b035b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
swagger-typescript-api Minor

Not sure what this means? Click here to learn what changesets are.

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

@J3MPA J3MPA changed the title Feat/add default readonly configuration feat: add immutable types Aug 5, 2025
@J3MPA
Copy link
Author

J3MPA commented Aug 6, 2025

@smorimoto I'm a little bit unsure on when to use lodash or not in the lib, seems like there is no clear pattern on when it's applied or not.

Do you have time to review the PR?

@smorimoto
Copy link
Collaborator

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Flag Ignored in API Generation

The new --make-immutable CLI flag is defined but isn't passed through to the generateApi function. This means the flag will be ignored and won't have any effect when used.

index.ts#L239-L281

responses: {
type: "boolean",
alias: "r",
description:
"generate additional information about request responses also add typings for bad responses",
default: codeGenBaseConfig.generateResponses,
},
"route-types": {
type: "boolean",
description: "generate type definitions for API routes",
default: codeGenBaseConfig.generateRouteTypes,
},
silent: {
type: "boolean",
description: "Output only errors to console",
default: codeGenBaseConfig.silent,
},
"single-http-client": {
type: "boolean",
description: "Ability to send HttpClient instance to Api constructor",
default: codeGenBaseConfig.singleHttpClient,
},
"sort-routes": {
type: "boolean",
description: "sort routes in alphabetical order",
default: codeGenBaseConfig.sortRoutes,
},
"sort-types": {
type: "boolean",
description: "sort fields and types",
default: codeGenBaseConfig.sortTypes,
},
templates: {
type: "string",
alias: "t",
description: "path to folder containing templates",
},
"type-prefix": {
type: "string",
description: "data contract name prefix",
default: codeGenBaseConfig.typePrefix,
},
"type-suffix": {

index.ts#L88-L93

},
"make-immutable": {
type: "boolean",
description: "makes all properties and values readonly",
default: codeGenBaseConfig.makeImmutable,
},

index.ts#L297-L298

await generateApi({

Fix in Cursor Fix in Web


Bugbot free trial expires on September 2, 2025
Learn more in the Cursor dashboard.

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.

2 participants