swagger-ui-py icon indicating copy to clipboard operation
swagger-ui-py copied to clipboard

bug: Swagger 3.0.0 datetime

Open jitka opened this issue 5 years ago • 1 comments

When I try to create object with date-time I got

Fetch error
Internal Server Error /swagger.json

My simple app:

import falcon
import swagger_ui
from wsgiref import simple_server

app = falcon.API()
swagger_ui.falcon_api_doc(
    app, config_path="./swagger.yaml", url_prefix="/", title="API doc planed",
)

with simple_server.make_server('', 8000, app) as httpd:
    httpd.serve_forever()

specification:

openapi: 3.0.0
info:
  version: 1.0.0
  title: Example
  contact:
    email: [email protected]
servers:
  - url: http://localhost:8000
paths:
  "/":
    get:
      summary: Minimal example
      responses:
        "200":
          description: successful operation
components:
  schemas:
    Revision:
      type: object
      properties:
        revisionId:
          type: integer
          description: Monotonic revision ID, starting from zero
          example: 0
        created:
          type: string
          format: date-time
          description: Timestamp of the creation of this section
          example: 2019-02-01T17:23:11.683Z

Without that created property it works fine. I check that swagger.yaml is valid in many tools.

jitka avatar Sep 01 '20 13:09 jitka

Although this is almost five years old, just in case someone discovers this: Quoting the example string solved the problem for me.

It is actually unrelated to the format, even if that is not specified, something recognizes the example string as a datetime and parses it, resulting in the error above.

EDIT: It is PyYAML that applies a regular expression to recognize timestamps and parse them to a datetime object.

m-appel avatar Aug 27 '25 06:08 m-appel