OpenAPITools / OpenAPITools/openapi-generator

[REQ] [python-flask] Distinction between "null" and "undefined"

Open
#10,076 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

It does not seems to be possible to distinct "null" and "undefined" when receiving request body parameters in Python.

For example :
Schema :

User:
  type: object
  properties:
    firstname:
      type: string
    lastname:
      type: string
    email:
      type: string
      nullable: true
  required:
    - firstname
    - lastname

Payload A :

{
  firstname: "John",
  lastname: "Doe",
  email: null,
}

Payload B :

{
  firstname: "John",
  lastname: "Doe",
}

Using payload A and B do not have the same meaning using Json Merge Patch format from RFC 7386.
(See : https://datatracker.ietf.org/doc/html/rfc7386)

Payload A should set 'None' to attribute email and Payload B should let the email untouched.

Describe the solution you'd like

It could be nice to have a solution like JsonNullable used on the Java Codegen (See : https://github.com/OpenAPITools/jackson-databind-nullable)
We could wrap with "nullable" attributes from Python model.mustache and it will allow to distinct between "None" and "undefined" using ".is_set" or ".get".

Note :
If a "to_dict" method is present on the model, it should not generate Entry<Key,Value> for the "undefined" attributes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the Python Flask model.mustache template and the generated model behavior for nullable fields. Compare the requested distinction with Java's JsonNullable approach, including the mentioned is_set/get semantics. Done means payloads with null and omitted fields remain distinguishable, and to_dict omits undefined attributes.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.