openapi-generators / openapi-generators/openapi-python-client

Handle "empty" default values as null

Open
#1,376 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
293
Avg merge
34m
Merged PRs (30d)
1

Description

Describe the bug
"empty" default values for optional fields throw an error. swagger-parser explicitly allows these (even though they are technically out-of-spec) by converting them silently to null. So, there exist openapi json in the wild built by swagger tools that pass swagger validation, but throw an error here in openapi-python-client.

OpenAPI Spec File
https://www.marinespecies.org/rest/api-docs/openapi.yaml

grep for:

                schema:
                    type: integer
                    default: ""

There are three endpoints that have this property. One of which is AphiaTaxonRanksByID. It might be useful to check this endpoint out in the swagger docs here.

Desktop (please complete the following information):

  • openapi-python-client version 0.28.0

Additional context
I am in contact with the folks at WORMS to try and find out how their openapi.yaml got this way. Will update here when I get more info.

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

Reproduce the failure with the marine species OpenAPI file linked in the issue, especially the schemas containing type: integer and default: "". Trace how optional-field defaults are handled during client generation and compare the behavior with the stated swagger-parser handling. Done means the affected endpoints generate successfully and empty defaults are treated as null.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
backend-api-design, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.