0

Input JSON

I have huge JSON. This is an excerpt of it.

{
  "base.get.v1.Input": {
    "properties": {
      "request": {
        "$ref": "#/components/schemas/base.get.v1.Input.Request"
      },
      "id": {
        "maxLength": 128,
        "type": "string"
      }
    },
    "required": ["id"],
    "type": "object"
  }
}

Output interface

Using OpenApi-generator-cli-3.0.0.jar i get the following typescript file (relative to che part of JSON showed before):

import { BaseGetV1InputRequest } from './baseGetV1InputRequest';


export interface BaseGetV1Input {
    request?: BaseGetV1InputRequest;
    trid: string;
}

Desired result

Is there a way to have the request object (and subsequent objects) be expanded (solver or exploded, whatever term you prefer). I would like the final interface to be like that:

import { BaseGetV1InputRequest } from './baseGetV1InputRequest';


export interface BaseGetV1Input {
  request?: {
    entity?: {
      code?: 0,
      id?: string
    },
    procedure?: string,
    search?: {
      type?: "starts" | "contains",
      value?: string
    }
  },
  trid: string
}

Tested solutions that don't work

I have tried to solve the $ref myself using json-schema-ref-parser but i think the codegen creates a sub-model when it finds properties inside of the input JSON.

I have also tried w/ and w/o mustache templates (that someone else got me). But the output didn't change.

I'm fairly new to OpenAPI, hope you can help me.

  • OpenApi-generator-cli-3.0.0.jar is pretty old. Please try the latest SNAPSHOT version: https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/ and let us know if you still have any question. – William Cheng Feb 20 '19 at 09:21
  • Thanks for the reply. I have tried with the version 4.0.0, but my problem is that the codegen is creating nested models to mirror the relative nested objects in the input JSON. What i need is to have 1 level deep models without all the nesting. Instead of having `request` of type `BaseGetV1InputRequest` as a separate model i want it as a child object. –  Feb 20 '19 at 09:49
  • so "request" is not a model but just a key-value pair instead? – William Cheng Feb 20 '19 at 10:18
  • Yes. Request should be `request?: { entity?: { ... } }` as i wrote in the "Desired result" paragraph. –  Feb 20 '19 at 10:44
  • Pls start a discussion in http://github.com/OpenAPITools/openapi-generator/issues/new so that the community can help you out there. – William Cheng Feb 20 '19 at 16:55

0 Answers0