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

NonReadonly type incorrectly includes readonly fields #1348

Closed
052hide opened this issue May 2, 2024 · 4 comments · Fixed by #1352 or #1354
Closed

NonReadonly type incorrectly includes readonly fields #1348

052hide opened this issue May 2, 2024 · 4 comments · Fixed by #1352 or #1354
Labels
bug Something isn't working
Milestone

Comments

@052hide
Copy link

052hide commented May 2, 2024

What are the steps to reproduce this issue?

  1. Generate code using the provided OpenAPI schema and orval.config.ts.
`./sample/openapi.yml'`
---
openapi: 3.1.0
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  '/pets':
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
        required: true
      responses:
        '201':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                '$ref': '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                '$ref': '#/components/schemas/Error'
  '/pets/{petId}':
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                '$ref': '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                '$ref': '#/components/schemas/Error'
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
          readOnly: true
        name:
          type: string
`./orval.config.ts`
import { defineConfig } from 'orval'

export default defineConfig({
  api: {
    input: {
      target: './sample/openapi.yml',
    },
    output: {
      target: './sample/generated',
      client: 'react-query',
    },
  },
})

What happens?

The NonReadonly type incorrectly includes readonly fields as a required fields.

What were you expecting to happen?

I expected the NonReadonly type to exclude readonly fields, similar to the behavior in version 6.25.0.

Any logs, error output, etc?

v6.25.0 v6.26.0
image image

What versions are you using?

Package Version: v6.26.0

@melloware
Copy link
Collaborator

Similar to #828

@melloware melloware added the bug Something isn't working label May 2, 2024
@melloware
Copy link
Collaborator

Also related: #826

@tamanugi
Copy link

tamanugi commented May 2, 2024

@melloware @052hide
I think this bug related to #1237.
That PR changed NonReadonly behavior.

It seems more appropriate for NonReadonly to remove readonly keys themselves, rather than just removing the readonly modifier.

Properties marked as readonly should not be included in the RequestBody 🤔

https://swagger.io/docs/specification/data-models/data-types/#:~:text=Read%2DOnly%20and%20Write%2DOnly%20Properties

Thanks.

@melloware
Copy link
Collaborator

@ezequiel thoughts on this since you did the original fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants