datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Change ordering of actions

Open prmshepherd opened this issue 1 year ago • 5 comments

Update the ordering of the actions as the one literal on default option is not working for descriminator properties

prmshepherd avatar May 15 '24 10:05 prmshepherd

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.

codecov[bot] avatar Jun 01 '24 15:06 codecov[bot]

CodSpeed Performance Report

Merging #1961 will not alter performance

Comparing prmshepherd:main (8bd40ef) with main (83ebb6d)

Summary

✅ 31 untouched benchmarks

codspeed-hq[bot] avatar Jun 01 '24 16:06 codspeed-hq[bot]

@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.

koxudaxi avatar Jun 05 '24 16:06 koxudaxi

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 avatar Jun 06 '24 14:06 prmshepherd

@prmshepherd Thank you for explaining it Could you please add the unittest for the case?

koxudaxi avatar Jun 28 '24 17:06 koxudaxi

@koxudaxi Sorry for the delay on this. I've added the test case now

prmshepherd avatar Sep 13 '24 09:09 prmshepherd

@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.

prmshepherd avatar Sep 17 '24 18:09 prmshepherd

@koxudaxi is anything more needed from me for this one?

prmshepherd avatar Sep 26 '24 10:09 prmshepherd