OpenAPITools / OpenAPITools/openapi-generator

[BUG][TYPESCRIPT] properties and required in DTO for yaml file all props becomes optional

Open
#22,354 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

When generating the openapi files with the new v7.17.0 we are getting the results of having required fields set to optional.

What happens is that when we're having the uuid, it is required in the code with the previous update. Now when having both properties and required it sets the uuid to optional. When removing the properties it is required again.

openapi-generator version

v7.17.0

OpenAPI declaration file content or url

YAML:

openapi: 3.0.0
info:
  title: title
  version: 1.0.0
components:
  parameters:
    PATH-test:
      name: uuid
      in: path
      required: true
      schema:
        type: string
  schemas:
    TestExampleDto:
      type: object
      properties:
        uuid:
          type: string
    TestDto:
      type: object
      properties:
        comment:
          type: string
      allOf:
        - $ref: "#/components/schemas/TestExampleDto"
      required:
        - uuid

security:
    - bearerAuth: [ ]

paths:
  /api/test/{uuid}:
    get:
      parameters:
        - $ref: "#/components/parameters/PATH-test"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TestDto"

openapitools.json:

{
    "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
    "spaces": 4,
    "generator-cli": {
        "version": "7.17.0",
        "generators": {
            "example-test-service": {
                "additionalProperties": {
                    "stringEnums": true
                },
                "generatorName": "typescript-fetch",
                "inputSpec": ".openapi/DDNEI/example-test-service",
                "output": "src/js/types/openapi/example-test-service"
            }
        }
    }
}

Generation Details

Command:
openapi-generator-cli --openapitools 'openapitools.json' generate --generator-key 'example-test-service'

Steps to reproduce

Implement the code and run the command we've provided

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied OpenAPI YAML and the typescript-fetch generator configuration in openapitools.json, then run the provided openapi-generator-cli command. Compare the generated TestDto output with the schema and verify that uuid remains required when TestDto combines properties, allOf, and required.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
57/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.