marshmallow-code / marshmallow-code/apispec

DateTime(format="timestamp") generates invalid OpenAPI schema using min instead of minimum

Open Beginner friendly
#1,064 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.2k
Forks
202
Avg merge
3h 38m
Merged PRs (30d)
3

Description

**Description**

`apispec` generates an invalid OpenAPI schema for `marshmallow.fields.DateTime(format="timestamp")`.

The generated schema contains the `min` property:

```yaml
changedOn:
type: number
format: float
example: "1676451245.596"
min: "0"
````

However, `min` is not a valid OpenAPI Schema Object property. As a result, the generated specification fails validation with `openapi-spec-validator`:

```
OpenAPIValidationError:
Property 'min' is not allowed
```

This was reproduced with:

* apispec 6.10.0
* marshmallow 3.26.2
* openapi-spec-validator 0.9.0
* OpenAPI 3.0.2

**Expected behavior**

The generated schema should use the standard OpenAPI keyword `minimum` instead of `min`, for example:

```yaml
changedOn:
type: number
format: float
example: "1676451245.596"
minimum: 0
```

or omit the constraint entirely if no minimum value is intended.

**Minimal reproduction**

````python
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from marshmallow import Schema, fields
from pprint import pprint

class TestSchema(Schema):
ts = fields.DateTime(format="timestamp")

spec = APISpec(
title="test",
version="1.0",
openapi_version="3.0.2",
plugins=[MarshmallowPlugin()],
)

spec.components.schema("Test", schema=TestSchema)

pprint(spec.to_dict()["components"]["schemas"]["Test"])
`````

Output:

```python
{'additionalProperties': False,
'properties': {'ts': {'example': '1676451245.596',
'format': 'float',
'min': '0',
'type': 'number'}},
'type': 'object'}
```

The file `field_converter.py` contains the code that causes this issue:
```python
elif field.format == "timestamp":
ret = {
"type": "number",
"format": "float",
"example": "1676451245.596",
"min": "0",
}
elif field.format == "timestamp_ms":
ret = {
"type": "number",
"format": "float",
"example": "1676451277514.654",
"min": "0",
}

```

**Specification reference**

The OpenAPI Schema Object defines the numeric constraint keyword as `minimum`; `min` is not a valid keyword.

OpenAPI 3.0.2 Schema Object:
[https://spec.openapis.org/oas/v3.0.2#schema-object](https://spec.openapis.org/oas/v3.0.2#schema-object)

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

The issue identifies field_converter.py as the source for timestamp and timestamp_ms schema generation. Reproduce the minimal example, inspect both branches, and verify that the generated schema uses the valid OpenAPI numeric constraint and passes specification validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.