OpenAPITools / OpenAPITools/openapi-generator
[typescript] Prevent nested models/interfaces
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
This issue is related to this question on stack-overflow
Input JSON
I have a huge JSON. This is an excerpt of it. (I can't past it all because it's for internal use only and because it's 16k lines).
{
"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 the 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 to admit i didn't read the docs when i first started. I assumed a new interface was created with every $ref.
I have also tried w/ and w/o mustache templates (that someone else got me). But the output didn't change.
I have also tried with the latest snapshot of the codegen as suggested by William Cheng in one of the comments. The problem isn't with the version but with a feature that I might not know about or that's not even possible.
I'm fairly new to OpenAPI, hope you can help me.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the request with the supplied OpenAPI schema using openapi-generator-cli and the TypeScript generator. Compare the generated nested model file with the desired inline interface, then inspect the generator entry point and any mustache templates involved. Done means nested $ref models are expanded in the generated TypeScript interface without unwanted sub-model files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100