3
votes

I am trying to generate Typescript client with OpenAPI Generator 4.0.0-SNAPSHOT (our manager asked us to use that version for some reason) that reads an OpenAPI 3.0 spec. All of our current endpoints either accept data in query string or as form body, and they all work perfectly. I have a new endpoint that will read data as JSON in POST body (other endpoints will eventually be converted too). It will accept an object like the following:

{email: "[email protected]"}

I'm trying to document the endpoint in YAML as following:

 /users/send-password-reminder:
    post:
      [...]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
      responses:
        [...]

However, when I generate the Typescript client, it generates a SendPasswordReminderRequest object, which wraps an autogenerated InlineObject1 object, which wraps my actual email.

This causes me to use it like:

const req: SendPasswordReminderRequest = {
    inlineObject1:{
      email: "..."
  }
};

APIClient.user.sendPasswordReminder(req, ...)

What I want instead is to get rid of that InlineObject1 completely and make SendPasswordReminderRequest directly wrap email property, and to be able to use it as:

const req: SendPasswordReminderRequest = {
   email: "..."
};

APIClient.user.sendPasswordReminder(req, ...)

I've tried defining the body in components/requestBodies and using $ref, and it still wraps the actual body even though it uses the name of my request body type.

How can I get rid of this wrapping?

1
What kind of TypeScript client are you generating? - Shaun Luttin
I thought I had an answer for you but I misunderstood your question. You're trying to avoid the wrapping entirely whereas I though you were only trying to replace inlineObject1 with User. - Shaun Luttin
@ShaunLuttin exactly. if I create a schema explicitly with a name and reference it using $ref, InlineObject1 is replaced by MyNameThatIChoose, but I want to remove wrapping altogether. - Can Poyrazoğlu
As far as I can tell, what you're wanting to do is not built-in to any of the existing generators. One approach would be to create your own generator that forks an existing one. - Shaun Luttin

1 Answers

5
votes

Im not sure if this will be still relevant for you but in code I find a way how to resolve not to generate InlineObjects at all

If you define "title" for your schema used in requestBody, it will use this title to name inline object.

So instead of getting InlineObject You can get something similar to: sendPasswordReminderRequestData, based on how you name your schema.

Hope this helps You or anyone else :).