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

Support readOnly/writeOnly fields in Schema Object #239

Open
fmatzy opened this issue Mar 16, 2023 · 0 comments
Open

Support readOnly/writeOnly fields in Schema Object #239

fmatzy opened this issue Mar 16, 2023 · 0 comments

Comments

@fmatzy
Copy link

fmatzy commented Mar 16, 2023

Description

readOnly/writeOnly fields for Schema Object properties is not reflected in the output type information.
Specification of readOnly/writeOnly is here.

Example input:

openapi: 3.0.3
info:
  title: example
  version: 0.1.0
servers:
  - url: https://example.com/v1
paths:
  /path:
    put:
      summary: Put Example
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ExampleObject"
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ExampleObject"
components:
  schemas:
    ExampleObject:
      type: object
      required:
        - id
        - name
        - value
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
        value:
          type: integer
          writeOnly: true

I got

api/@types/index.ts:

/* eslint-disable */
export type ExampleObject = {
  id: number
  name: string
  value: number
}

api/path/index.ts:

/* eslint-disable */
import type * as Types from '../@types'

export type Methods = {
  put: {
    status: 200
    /** Success */
    resBody: Types.ExampleObject
    reqBody: Types.ExampleObject
  }
}

The id is readOnly: true and therefore not needed in the request, while the value is writeOnly: true and therefore not needed in the response.

Describe the solution you'd like

Expected output is like below:

/* eslint-disable */
import type * as Types from '../@types'

export type Methods = {
  put: {
    status: 200
    /** Success */
    resBody: Omit<Types.ExampleObject, "value">
    reqBody: Omit<Types.ExampleObject, "id">
  }
}

Omit the writeOnly properties for the resBody type, and conversely, omit the readOnly properties for the reqBody type.

Describe alternatives you've considered

Additional context

Environment

  • Package version: v0.21.0
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

No branches or pull requests

1 participant