OpenAPITools / OpenAPITools/openapi-generator
[REQ] Property requirements not included in generated Typescript files
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
Property restrictions (maxLength, minLength, etc) should be used in frontend to e.g. limit text fields (maxLength) and do validation (of course the backend validates too, but we don't need to send a request to backend which is invalid).
Describe the solution you'd like
Add maxLength, minLength and pattern to generated files.
Describe alternatives you've considered
Manually adding those. If API changes these changes will have to be check for all properties of API and may be updated ...
Additional context
Consider following spec:
openapi: 3.0.1
info:
title: OpenAPI Test
description: Test
license:
name: Apache-2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: http://localhost:9999/v2
paths:
/ping:
post:
summary: test
description: test me
operationId: myTest
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyObj'
required: true
responses:
200:
description: OK
content: { }
components:
schemas:
MyObj:
properties:
myTest:
type: string
minLength: 1
maxLength: 3
This will generate (parameters: "generate -g typescript-node -i test.yaml -o src/test --additional-properties=supportsES6=true" ) e.g.
/**
* OpenAPI Test
* Test
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { RequestFile } from './models';
export class MyObj {
'myTest'?: string;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "myTest",
"baseName": "myTest",
"type": "string"
} ];
static getAttributeTypeMap() {
return MyObj.attributeTypeMap;
}
}
Limitations for myTest are not included (minLength=1 and maxLength=3) and there is no additional information available like e.g. a validation package with appropriate myObjValidator.ts and appropriate functions.
Did I miss any flag or option to generate these information somehow (in which form ever) or is it just missing since no one ever needed it? Is there alternatively a workaround or another feature that may help with this issue? I would like to avoid checking and adjusting requirements manually in frontend if API changes occurred.
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
Start by reproducing the supplied generate -g typescript-node -i test.yaml -o src/test --additional-properties=supportsES6=true command with the example OpenAPI schema and inspect the generated MyObj output. Trace the TypeScript node generator entry points and templates that produce the model, then verify that minLength, maxLength, and pattern are represented in generated files or validation support.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100