Skip to content

[REQ] Property requirements not included in generated Typescript files #8024

Open
@mppperez

Description

@mppperez

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions