-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
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.
Reactions are currently unavailable