Skip to content

Commit

Permalink
import datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Apr 6, 2024
1 parent f60b25a commit a89027d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Generator/Python.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

namespace PSX\Schema\Generator;

use PSX\Schema\Format;
use PSX\Schema\Generator\Normalizer\NormalizerInterface;
use PSX\Schema\Generator\Type\GeneratorInterface;
use PSX\Schema\Type\AnyType;
use PSX\Schema\Type\ArrayType;
use PSX\Schema\Type\MapType;
use PSX\Schema\Type\ReferenceType;
use PSX\Schema\Type\StringType;
use PSX\Schema\Type\StructType;
use PSX\Schema\Type\TypeAbstract;
use PSX\Schema\Type\UnionType;
Expand Down Expand Up @@ -151,6 +153,14 @@ private function getImports(TypeAbstract $origin): array
$imports[] = 'from typing import Union';
}

if (TypeUtil::contains($origin, StringType::class, Format::DATE)) {
$imports[] = 'import datetime';
} elseif (TypeUtil::contains($origin, StringType::class, Format::TIME)) {
$imports[] = 'import datetime';
} elseif (TypeUtil::contains($origin, StringType::class, Format::DATETIME)) {
$imports[] = 'import datetime';
}

$refs = [];
TypeUtil::walk($origin, function(TypeInterface $type) use (&$refs){
if ($type instanceof ReferenceType) {
Expand Down
1 change: 1 addition & 0 deletions tests/Generator/resource/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Meta(Dict[str, str]):
from typing import List
from typing import Dict
from typing import Union
import datetime
from .meta import Meta
from .author import Author
from .location import Location
Expand Down

0 comments on commit a89027d

Please sign in to comment.