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

[BUG][Python] readOnly property inside of allOf causes "The input data was invalid for the allOf schema" #9596

Closed
6 tasks done
mfmarche opened this issue May 26, 2021 · 5 comments

Comments

@mfmarche
Copy link
Contributor

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)
Description

This is related specifically to the python generator.

Here is an example schema:

openapi-generator version

master

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Sample test
  version: '2.0'
paths:
  /v2/projects:
    post:
      operationId: sample_post
      summary: sample
      tags:
        - Samplek
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/parent'
      responses:
        '200':
          description: OK
components:
  schemas:
    parent:
      allOf:
        - $ref: '#/components/schemas/child'
    child:
      type: object
      properties:
        test_readonly:
          type: string
          readOnly: true
          example: 4e1bfbc3
Generation Details
java -jar openapi-generator-cli.jar generate -i test.yaml -g python
Steps to reproduce
from openapi_client.model import parent
parent.Parent._from_openapi_data(test_readonly="foobar")
<snip>
openapi_client.exceptions.ApiValueError: Invalid inputs given to generate an instance of 'Child'. The input data was invalid for the allOf schema 'Child' in the composed schema 'Parent'. Error=`test_readonly` is a read-only attribute. Use `from_openapi_data` to instantiate class with read only attributes.
Related issues/PRs
Suggest a fix

I made a quick fix to model_utils.mustache as follows:

mfmarche@eb28082#diff-5378d085f86e7e92f3e0044670bce659d30efdfe1f0c31a502b5da22ba6e2070R1458

But likely inappropriate since it now always calls from_openapi_data, but rather it should likely use either__init_ or _from_openapi_data depending on the caller.

@spacether
Copy link
Contributor

spacether commented Jun 2, 2021

Yes it should definitely call either __init__ or _from_openapi_data depending on the calling context

mfmarche added a commit to mfmarche/openapi-generator that referenced this issue Jun 6, 2021
@languitar
Copy link
Contributor

Does anyone know when this issue was introduced?

@languitar
Copy link
Contributor

Ah, with 5.2.0. This is a serious blocker for using 5.2.0 when generating Python clients. Any chance to get this fixed?

@mfmarche
Copy link
Contributor Author

#9735 has a fix for this that should address this issue. That fix is currently in review and fixes are pending.

@spacether
Copy link
Contributor

Fixed per PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants