Skip to content

Commit 6239e49

Browse files
committed
fix: drop broken readOnly support
1 parent 85cf790 commit 6239e49

7 files changed

Lines changed: 6 additions & 19 deletions

File tree

packages/documentation/src/app/overview/compatibility/page.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Most common functionality used by JSON based APIs should work.
2929
- Decent support for `paths` using `application/x-www-form-urlencoded` request bodies
3030
- Comprehensive support for most `schema` properties, including json validation stuff like `minLength`,
3131
but only for `json` content types. Notable exceptions:
32-
- `readonly` is currently implemented incorrectly
32+
- `writeOnly` / `readonly` is ignored
3333
- `discriminator` is ignored, but `union` / `intersection` types will be generated based on `anyOf` / `allOf` so
3434
this isn't an issue in practice
3535
- No support for security schemes, you'll need to fudge these as header parameters, or implement out-of-band
@@ -242,8 +242,7 @@ CLI option.
242242
The majority of attributes that can be specified by `schema` objects are supported, and accurately match the underlying
243243
openapi specification / json schema validation specifications.
244244

245-
Most notable exception is `readOnly` / `writeOnly` which are currently implemented incorrectly, planned to be addressed
246-
as a breaking change prior to v1.
245+
Most notable exception is `readOnly` / `writeOnly` which are currently ignored, planned to be addressed prior to v1.
247246

248247
| Attribute | Supported | Notes |
249248
|:---------------------|:---------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -275,7 +274,7 @@ as a breaking change prior to v1.
275274
| default | ✅ | |
276275
| nullable | ✅ | Also supports `type: null` as an alternative |
277276
| discriminator | 🚫 | Ignored. Union / Intersection types are usd based on `anyOf` / `allOf` / `oneOf`. |
278-
| readOnly | 🚫 | Produces `readonly` modifiers, but this behavior [is incorrect](https://github.com/mnahkies/openapi-code-generator/issues/157) |
277+
| readOnly | 🚫 | Not yet supported |
279278
| writeOnly | 🚫 | Not yet supported |
280279
| example | __N/A__ | Ignored |
281280
| externalDocs | __N/A__ | Ignored |

packages/openapi-code-generator/src/core/input.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,20 @@ describe("core/input - SchemaNormalizer", () => {
1919
type: "any",
2020
default: undefined,
2121
nullable: false,
22-
readOnly: false,
2322
"x-internal-preprocess": undefined,
2423
} satisfies IRModelAny,
2524
never: {
2625
isIRModel: true,
2726
type: "never",
2827
default: undefined,
2928
nullable: false,
30-
readOnly: false,
3129
"x-internal-preprocess": undefined,
3230
} satisfies IRModelNever,
3331
object: {
3432
isIRModel: true,
3533
type: "object",
3634
default: undefined,
3735
nullable: false,
38-
readOnly: false,
3936
properties: {},
4037
required: [],
4138
allOf: [],
@@ -49,7 +46,6 @@ describe("core/input - SchemaNormalizer", () => {
4946
type: "array",
5047
default: undefined,
5148
nullable: false,
52-
readOnly: false,
5349
uniqueItems: false,
5450
minItems: undefined,
5551
maxItems: undefined,
@@ -65,7 +61,6 @@ describe("core/input - SchemaNormalizer", () => {
6561
minLength: undefined,
6662
nullable: false,
6763
pattern: undefined,
68-
readOnly: false,
6964
"x-enum-extensibility": undefined,
7065
"x-internal-preprocess": undefined,
7166
} satisfies IRModelString,
@@ -81,7 +76,6 @@ describe("core/input - SchemaNormalizer", () => {
8176
inclusiveMinimum: undefined,
8277
multipleOf: undefined,
8378
nullable: false,
84-
readOnly: false,
8579
"x-enum-extensibility": undefined,
8680
"x-internal-preprocess": undefined,
8781
} satisfies IRModelNumeric,
@@ -91,7 +85,6 @@ describe("core/input - SchemaNormalizer", () => {
9185
default: undefined,
9286
enum: undefined,
9387
nullable: false,
94-
readOnly: false,
9588
"x-internal-preprocess": undefined,
9689
} satisfies IRModelBoolean,
9790
}
@@ -104,7 +97,6 @@ describe("core/input - SchemaNormalizer", () => {
10497
value: base.any,
10598
default: undefined,
10699
nullable: false,
107-
readOnly: false,
108100
"x-internal-preprocess": undefined,
109101
} satisfies IRModelRecord,
110102
}

packages/openapi-code-generator/src/core/input.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,6 @@ export class SchemaNormalizer {
753753
const base: IRModelBase = {
754754
isIRModel: true,
755755
nullable: schemaObject.nullable || false,
756-
readOnly: schemaObject.readOnly || false,
757756
default: schemaObject.default,
758757
"x-internal-preprocess": schemaObject["x-internal-preprocess"],
759758
}

packages/openapi-code-generator/src/core/openapi-types-normalized.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export interface IRModelBase {
1010
isIRModel: true
1111
// Note: meaningless for top level objects, maybe we can exclude these somehow in that case
1212
nullable: boolean /* false */
13-
readOnly: boolean /* false */
13+
// todo: bring back but support properly
14+
// readOnly: boolean /* false */
1415
default?: unknown | undefined
1516
"x-internal-preprocess"?: MaybeIRPreprocess | undefined
1617
}

packages/openapi-code-generator/src/typescript/common/type-builder.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ export class TypeBuilder implements ICompilable {
212212
const isRequired = schemaObject.required.some((it) => it === name)
213213
const type = this.schemaObjectToType(definition)
214214

215-
const isReadonly = isRef(definition) ? false : definition.readOnly
216-
217215
// ensure compatibility with `exactOptionalPropertyTypes` compiler option
218216
// https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes
219217
const exactOptionalPropertyTypes =
@@ -224,7 +222,7 @@ export class TypeBuilder implements ICompilable {
224222
type: exactOptionalPropertyTypes
225223
? union(type, "undefined")
226224
: type,
227-
isReadonly,
225+
isReadonly: false,
228226
isRequired,
229227
})
230228
})

packages/openapi-code-generator/src/typescript/common/typescript-common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ export function requestBodyAsParameter(
284284
isIRModel: true,
285285
type: "never",
286286
nullable: false,
287-
readOnly: false,
288287
},
289288
deprecated: false,
290289
},

packages/openapi-code-generator/src/typescript/server/server-operation-builder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ export class ServerOperationBuilder {
289289
schema.properties[key] ?? {
290290
isIRModel: true,
291291
nullable: false,
292-
readOnly: false,
293292
type: "any",
294293
},
295294
),

0 commit comments

Comments
 (0)