Skip to content

[BUG][python] Cannot instantiate class without required read-only parameters for POST endpoint #9296

Closed
@gbmarc1

Description

@gbmarc1

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)

@spacether

Python generator

Description

I have a POST endpoint and the request body and response body use the same schema definition as below. Dataset has multiple readOnly parameters that must be present in the response, but should not be provided in the request.

I can instantiate the Dataset model providing None to the parameters that are readOnly and without verifying the model's input (_check_type=False). However, post request still fails (404 bad request) because params are still present with None values.

openapi-generator version

5.1.1

OpenAPI declaration file content or url
paths:
  /datasets:
    post:
      operationId: v1_inference_datasets_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Dataset'
        description: The dataset to be registered
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Dataset'
          description: Confirmation of dataset registration
      summary: Register a dataset
      tags:
        - datasets
 
components:
  schemas:
    Dataset:
      additionalProperties: false
      example:
        statusLastChange: 2000-01-23T04:56:07+00:00
        modifiedOn: 2000-01-23T04:56:07+00:00
        name: name
        inactiveOn: 2000-01-23T04:56:07+00:00
        description: description
        mediaType: text/plain
        id: 0
        createdOn: 2000-01-23T04:56:07+00:00
        status: active
      properties:
        id:
          description: ID of the dataset
          readOnly: true
          type: integer
        name:
          description: User-defined name of the dataset
          maxLength: 128
          type: string
        description:
          description: User-defined description of the dataset
          maxLength: 256
          type: string
        mediaType:
          description: Data type of the dataset. All data must be of the same type.
          enum:
            - text/plain
          type: string
        createdOn:
          description: Creation time of the dataset
          format: date-time
          readOnly: true
          type: string
        modifiedOn:
          description: Modification time of the dataset
          format: date-time
          readOnly: true
          type: string
        inactiveOn:
          description: |
            Time when the dataset will become inactive. Make sure to retrieve all data and job results
            before this time.
          format: date-time
          readOnly: true
          type: string
        status:
          description: |
            Status of the dataset:
              * `active`: The dataset can be modified (including the data it contains).
              * `committed`: The dataset can no longer be
                 modified (including the data it contains) but jobs can be submitted.
              * `inactive`: The dataset can no longer be modified (including the
                data it contains) and jobs cannot be submitted. Once a dataset is inactive,
                it becomes a candidate for deletion meaning it will soon be deleted from the system.
          enum:
            - active
            - committed
            - inactive
          readOnly: true
          type: string
        statusLastChange:
          description: Time when the status last changed
          format: date-time
          readOnly: true
          type: string
      required:
        - createdOn
        - description
        - id
        - inactiveOn
        - mediaType
        - modifiedOn
        - name
        - status
        - statusLastChange
      type: object
Generation Details

generate -i openapi/openapi.yaml -g "python" --package-name ex_ai_hub_api_client2 -p packageVersion=0.2.0

Steps to reproduce
Related issues/PRs
Suggest a fix

I suggest the following 3 modifications:

  1. Modify the signature of __init__ for readOnly=True parameters from
Dataset:
    @convert_js_args_to_python_args
    def __init__(self, id, name, description, created_on, modified_on, inactive_on, status, status_last_change, *args, **kwargs):

to

Dataset:
    @convert_js_args_to_python_args
    def __init__(self, id, name, description, created_on=None, modified_on=None, inactive_on=None, status=None, status_last_change=None, *args, **kwargs):
  1. Modify the checks accordingly to support null values when instantiating a class
  2. Do not add parameter to body payload for readOnly=True and nullable=False parameters when value is None .

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions