openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Add support for plain text request body

Open kairntech opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. It should be possible to have endpoint with a full plain text request body like

  /dummy:
    post:
      requestBody:
        description: (to be documented)
        content:
          text/plain:
            schema:
              type: string
        required: true

Today it is completely ignored

Describe the solution you'd like In openapi._add_body() we should have a additional line

        text_body, schemas = Endpoint.parse_request_text_body(
            body=data.requestBody, schemas=schemas, parent_name=endpoint.name, config=config
        )

And

    @staticmethod
    def parse_request_text_body(
        *, body: oai.RequestBody, schemas: Schemas, parent_name: str, config: Config
    ) -> Tuple[Union[Property, PropertyError, None], Schemas]:
        """Return text_body"""
        body_content = body.content
        text_body = body_content.get("text/plain")
        if text_body is not None and text_body.media_type_schema is not None:
            return property_from_data(
                name="text_body",
                required=True,
                data=text_body.media_type_schema,
                schemas=schemas,
                parent_name=parent_name,
                config=config,
            )
        return None, schemas

Describe alternatives you've considered

Additional context

kairntech avatar Dec 03 '21 14:12 kairntech

I can probably provide a PR

kairntech avatar Dec 03 '21 15:12 kairntech

I am facing the same issue for response. text/plain does not seems to be supported

rubenfiszel avatar Dec 04 '21 17:12 rubenfiszel