Skip to content

readWrite parser transform fails to split schemas when all properties are readOnly/writeOnly #3212

@jmillandev

Description

@jmillandev

Description

This appears to be related to #28:

Problem

When a schema has all properties marked as readOnly or writeOnly, the parser.transforms.readWrite logic only generates a single type instead of splitting into readable/writable variants.

However, if at least one field is neither readOnly nor writeOnly, the generator correctly produces both:

  • TokenObtain
  • TokenObtainWriteable (or the configured writable name)

Example schema

{
  "TokenObtain": {
    "type": "object",
    "properties": {
      "email": { "type": "string", "writeOnly": true },
      "password": { "type": "string", "writeOnly": true },
      "expires_at": { "type": "integer", "readOnly": true },
      "user_id": { "type": "string", "format": "uuid", "readOnly": true },
      "refresh_token": { "type": "string", "readOnly": true },
      "access_token": { "type": "string", "readOnly": true },
      "token_type": { "type": "string", "readOnly": true, "default": "Bearer" }
    },
    "required": [
      "access_token",
      "email",
      "expires_at",
      "password",
      "refresh_token",
      "token_type",
      "user_id"
    ]
  }
}

Expected behavior

Even when all fields are read/write scoped, the generator should still split the schema into:

  • a readable (response) type
  • a writable (request) type

This matches the intent of the fix in #28, but the edge case where no “shared” fields exist still seems to fall through,

Reproducible example or configuration

OpenAPI

{
  "openapi": "3.0.3",
  "info": {
    "title": "readWrite edge case repro",
    "version": "1.0.0"
  },
  "paths": {},
  "components": {
    "schemas": {
      "TokenObtain": {
        "type": "object",
        "properties": {
          "email": { "type": "string", "writeOnly": true },
          "password": { "type": "string", "writeOnly": true },
          "expires_at": { "type": "integer", "readOnly": true },
          "user_id": { "type": "string", "format": "uuid", "readOnly": true },
          "refresh_token": { "type": "string", "readOnly": true },
          "access_token": { "type": "string", "readOnly": true },
          "token_type": { "type": "string", "readOnly": true, "default": "Bearer" }
        },
        "required": [
          "access_token",
          "email",
          "expires_at",
          "password",
          "refresh_token",
          "token_type",
          "user_id"
        ]
      }
    }
  }
}

openapi-ts.config.ts

export default defineConfig({
  input: 'openapi.json',
  plugins: [
    {
      name: '@hey-api/client-axios',
      parser: {
        transforms: {
          readWrite: {
            requests: '{{name}}Writable', 
            responses: '{{name}}', 
          },
        },
      },
    },
  ],
});

Versions

    "@hey-api/client-axios": "^0.9.1",
    "@hey-api/openapi-ts": "^0.90.4",

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Labels

bug 🔥Broken or incorrect behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions