Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi,

I have some issues creating a oneof in Python.

I'd like to implement a oneof with three options:

get:
  operationId: doSomething
  x-bidistream: true
  requestBody:
    content:
      application/json:
        schema:
          oneOf:
            - $ref: '../components/schemas/Option1.yaml'
            - $ref: '../components/schemas/Option2.yaml'
            - $ref: '../components/schemas/Option3.yaml'

The generator correctly generates a request for this comprising all these options:

class doSomethingRequest(BaseModel):
    oneof_schema_1_validator: Optional[Option1] = None
    oneof_schema_2_validator: Optional[Option2] = None
    oneof_schema_3_validator: Optional[Option3] = None

The websocket endpoint looks like this:

async def do_something(self, client_request_generator: Callable[[AsyncGenerator[DoSomethingResponse, None]], AsyncGenerator[DoSomethingRequest, None]]) -> None:  # noqa: E501

My async generator looks like this:

 async def faulty_request_generator(
            response_generator: AsyncGenerator[Models.DoSomethingResponse, None],
            request: Union[Models.Option1, Models.Option2, Models.Option3],
        ) -> AsyncGenerator[Models.DoSomethingRequest, None]:

            yield Models.DoSomethingRequest(request)

This doesn't seem to work, because if I wrap my request in Models.DoSomethingRequest in the yield command, the json that is sent seems to ignore the oneof-character of this message. Somewhere pydantics model_dump_json is called on this message which will also include oneof_schema_1_validator etc.

If I just call yield request, everything works, but MyPy complains that the types don't match. I could disable this warning, but somehow it feels wrong.

I noticed that there is a to_json method of the DoSomethingRequest-class, which seems to do the correct thing, but it doesn't seem to get called. Do I have to setup something to make this work?

Thanks and best regards
oz

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.