Skip to content

fix: Исправить генератор клиента под ensi guide - #23

Open
HEIZ2303 wants to merge 2 commits into
masterfrom
date-fix
Open

fix: Исправить генератор клиента под ensi guide#23
HEIZ2303 wants to merge 2 commits into
masterfrom
date-fix

Conversation

@HEIZ2303

@HEIZ2303 HEIZ2303 commented Aug 6, 2026

Copy link
Copy Markdown

В рамках PR заменил DateTime::ATOM на формат под ensi guide - https://docs.ensi.tech/backend-guides/principles/date-time

@HEIZ2303
HEIZ2303 requested a review from DimionX August 6, 2026 14:50
@HEIZ2303 HEIZ2303 self-assigned this Aug 6, 2026

protected function patchDateTimeInterfaceSupport(string $content): string
{
return $this->replaceValue(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если генератор начнет сам генерировать:

$value instanceof \DateTimeInterface

после патча получится:

$value instanceof \DateTimeInterfaceInterface

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил


$sanitizeFilenameDocBlock = <<<'PHP'
/**
* Sanitize filename by removing path.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень хрупкое решение: цепляться за комментарии, которые потом могут поменяться в шаблоне и из-за этого получим Runtime Error.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил

}

$utcDateTime = DateTimeImmutable::createFromFormat('U.u', $value->format('U.u'), new DateTimeZone('UTC'));
if (false === $utcDateTime) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно поменять местами, в ensi принято наоборот писать $utcDateTime === false

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил


protected static function formatDate(DateTimeInterface $value, string $format): string
{
if ('date' === $format) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно поменять местами, в ensi принято наоборот писать $format === 'date'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил

file_put_contents($this->objectSerializerFile, $content);
}

protected function patchDefaultDateTimeFormat(string $content): string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В patchDefaultDateTimeFormat и в patchDateTimeInterfaceSupport используется replaceValue и нет проверок на количество замен.

patchDefaultDateTimeFormat(): там формат глобально меняется с DateTime::ATOM на Y-m-d\TH:i:s.u\Z, где Z — literal и сам по себе не переводит значение в UTC. Поэтому после этой замены все ветки, использующие $dateTimeFormat, должны гарантированно быть переведены на formatDateTime().

Сейчас если хотя бы один из этих exact str_replace не найдёт исходную строку, патчер молча продолжит работу. В результате можем получить частично пропатченный ObjectSerializer: новый формат с Z, но старый $value->format(self::$dateTimeFormat). Например, 15:00+03:00 в таком пути станет 15:00Z вместо 12:00Z.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил и добавил тесты

@DimionX

DimionX commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Ещё нужно добавить тесты.

Например:

  • DateTime с +03:00 сериализуется в эквивалентный UTC с Z;
  • микросекунды сохраняются;
  • format: date не сдвигается из-за timezone conversion;
  • если ожидаемый фрагмент ObjectSerializer.php не найден — patcher падает, а не молча продолжает;
  • если исходник уже содержит DateTimeInterface, не получается DateTimeInterfaceInterface;
  • после patch гарантированно существует formatDateTime().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants