datamodel-code-generator
datamodel-code-generator copied to clipboard
Change ordering of actions
Update the ordering of the actions as the one literal on default option is not working for descriminator properties
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
83ebb6d) to head (8bd40ef). Report is 1 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #1961 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 38 38
Lines 4205 4205
Branches 976 976
=========================================
Hits 4205 4205
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 99.66% <100.00%> (ø) |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
CodSpeed Performance Report
Merging #1961 will not alter performance
Comparing prmshepherd:main (8bd40ef) with main (83ebb6d)
Summary
✅ 31 untouched benchmarks
@prmshepherd Sorry for my late response. Thank you for creating the PR. Could you please provide the test case? I would like to add the unittest for the changes.
Hi @koxudaxi, sorry I have this in draft as more work is needed by me. My use-case is when I am using a discriminator
openapi: 3.0.0
info:
title: Pet API
version: 1.0.0
paths:
/pets:
post:
summary: Add a new pet
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: Successfully added the pet
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
type: object
oneOf:
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Cat'
discriminator:
propertyName: petType
mapping:
dog: '#/components/schemas/Dog'
cat: '#/components/schemas/Cat'
Dog:
properties:
breed:
type: string
barkVolume:
type: integer
format: int32
description: The volume of the dog's bark
Cat:
properties:
color:
type: string
isIndoor:
type: boolean
description: Indicates if the cat is an indoor cat
This generates:
class Dog(BaseModel):
breed: Optional[str] = None
barkVolume: Optional[int] = Field(None, description="The volume of the dog's bark")
petType: Literal['dog']
What I would like is petType: Literal['dog'] = 'dog'.
But I think the ordering of those actions prevents that
@prmshepherd Thank you for explaining it Could you please add the unittest for the case?
@koxudaxi Sorry for the delay on this. I've added the test case now
@koxudaxi I've fixed that test error with the extraneous args - I'm not sure why I didn't see that on my local run.
@koxudaxi is anything more needed from me for this one?