Skip to content

Commit

Permalink
(fix, python): generated python snippets respect trailing slashes (#3789
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dsinghvi authored Jun 6, 2024
1 parent de051be commit f450801
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
3 changes: 3 additions & 0 deletions generators/python/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.9.0] - 2024-06-05
- Fix: Snippets preserve trailing slashes

## [2.9.0-rc1] - 2024-06-05

- Fix: The new http client abstraction ensures a slash is postfixed to the baseurl
Expand Down
2 changes: 1 addition & 1 deletion generators/python/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.0-rc1
2.9.0
20 changes: 9 additions & 11 deletions generators/python/src/fern_python/snippet/snippet_registry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict, List, Optional

import fern.generator_exec.resources as generator_exec
Expand Down Expand Up @@ -109,19 +110,16 @@ def _full_path_for_endpoint(
endpoint: ir_types.HttpEndpoint,
) -> str:
components: List[str] = []
head = endpoint.full_path.head.strip("/")
if len(head) > 0:
components.append(head)
has_tail = False
if not endpoint.full_path.head.startswith("/"):
components.append("/")
if len(endpoint.full_path.head) > 0:
components.append(endpoint.full_path.head)
for part in endpoint.full_path.parts:
has_tail = False
components.append("{" + part.path_parameter + "}")
tail = part.tail.strip("/")
if len(tail) > 0:
components.append(tail)
if part.tail.endswith("/"):
has_tail = True
return f"/{'/'.join(components)}/" if has_tail else f"/{'/'.join(components)}"
if len(part.tail) > 0:
components.append(part.tail)
joined_components = "".join(components)
return re.sub("/+", "/", joined_components)

def _ir_method_to_generator_exec_method(
self,
Expand Down
2 changes: 1 addition & 1 deletion seed/python-sdk/package-yml/snippet.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f450801

Please sign in to comment.