Skip to content

Conversation

@JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented Jan 25, 2023

Note: this depends on #126. The first commit was pulled from that.

Sample output:

async def _serialize_all_query_string_types(
    input: AllQueryStringTypesInput, config: Config
) -> Request:
    headers: _HeadersList = []
    path = "/AllQueryStringTypesInput"
    query_params: list[tuple[str, str | None]] = []

    if input.query_string is not None:
        query_params.append(("String", input.query_string))
    if input.query_string_list is not None:
        query_params.extend(("StringList", e) for e in input.query_string_list)
    if input.query_string_set is not None:
        query_params.extend(("StringSet", e) for e in input.query_string_set)
    if input.query_byte is not None:
        query_params.append(("Byte", str(input.query_byte)))
    if input.query_short is not None:
        query_params.append(("Short", str(input.query_short)))
    if input.query_integer is not None:
        query_params.append(("Integer", str(input.query_integer)))
    if input.query_integer_list is not None:
        query_params.extend(("IntegerList", str(e)) for e in input.query_integer_list)
    if input.query_integer_set is not None:
        query_params.extend(("IntegerSet", str(e)) for e in input.query_integer_set)
    if input.query_long is not None:
        query_params.append(("Long", str(input.query_long)))
    if input.query_float is not None:
        query_params.append(("Float", serialize_float(input.query_float)))
    if input.query_double is not None:
        query_params.append(("Double", serialize_float(input.query_double)))
    if input.query_double_list is not None:
        query_params.extend(
            ("DoubleList", serialize_float(e)) for e in input.query_double_list
        )
    if input.query_boolean is not None:
        query_params.append(("Boolean", ("true" if input.query_boolean else "false")))
    if input.query_boolean_list is not None:
        query_params.extend(
            ("BooleanList", ("true" if e else "false"))
            for e in input.query_boolean_list
        )
    if input.query_timestamp is not None:
        query_params.append(
            ("Timestamp", serialize_rfc3339(ensure_utc(input.query_timestamp)))
        )
    if input.query_timestamp_list is not None:
        query_params.extend(
            ("TimestampList", serialize_rfc3339(ensure_utc(e)))
            for e in input.query_timestamp_list
        )
    if input.query_enum is not None:
        query_params.append(("Enum", input.query_enum))
    if input.query_enum_list is not None:
        query_params.extend(("EnumList", e) for e in input.query_enum_list)
    if input.query_integer_enum is not None:
        query_params.append(("IntegerEnum", str(input.query_integer_enum)))
    if input.query_integer_enum_list is not None:
        query_params.extend(
            ("IntegerEnumList", str(e)) for e in input.query_integer_enum_list
        )
    if input.query_params_map_of_string_list is not None:
        query_params.extend(
            (k, v)
            for k in input.query_params_map_of_string_list
            for v in input.query_params_map_of_string_list[k]
        )
    query: str = ""
    for i, param in enumerate(query_params):
        if i != 1:
            query += "&"
        if param[1] is None:
            query += param[0]
        else:
            query += f"{param[0]}={param[1]}"

    body: Any = b""
    return _Request(
        url=_URI(
            host="",
            path=path,
            scheme="https",
            query=query,
        ),
        method="GET",
        headers=headers,
        body=body,
    )


async def _serialize_constant_and_variable_query_string(
    input: ConstantAndVariableQueryStringInput, config: Config
) -> Request:
    headers: _HeadersList = []
    path = "/ConstantAndVariableQueryString"
    query_params: list[tuple[str, str | None]] = [
        ("foo", "bar"),
    ]

    if input.baz is not None:
        query_params.append(("baz", input.baz))
    if input.maybe_set is not None:
        query_params.append(("maybeSet", input.maybe_set))
    query: str = ""
    for i, param in enumerate(query_params):
        if i != 1:
            query += "&"
        if param[1] is None:
            query += param[0]
        else:
            query += f"{param[0]}={param[1]}"

    body: Any = b""
    return _Request(
        url=_URI(
            host="",
            path=path,
            scheme="https",
            query=query,
        ),
        method="GET",
        headers=headers,
        body=body,
    )

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

writer.pushState(new SerializeQuerySection(operation));
writer.write("query_params: list[tuple[str, str | None]] = []");
// TODO: implement query serialization
writer.writeInline("query_params: list[tuple[str, str | None]] = [");
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure I understand how we intend this to work. If I want mylonginfovalue1234567890 appended to the end of my URI as the only part of a query string, it would be something like:

query_params = [('mylonginfovalue1234567890', None)]
uri = build_uri(query_params=query_params, **kwargs)
>>> https://example.com/?mylonginfovalue1234567890

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

jonemo
jonemo previously approved these changes Feb 1, 2023
nateprewitt
nateprewitt previously approved these changes Feb 1, 2023
@JordonPhillips JordonPhillips merged commit c3013e4 into develop Feb 2, 2023
@JordonPhillips JordonPhillips deleted the query-ser branch February 2, 2023 10:04
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.

3 participants