Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7745
Closed
Open
Issue created Oct 18, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [typescript-fetch] nullable: true is not respected with enum

Created by: berlysia

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Enum properties declared in models or request parameters ignore nullable: true

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: yay
  version: 1.0.0
  title: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
  /fake/enum-request:
    get:
      operationId: fake-enum-request
      parameters:
        - name: nullable-string-enum
          in: query
          schema:
            type: string
            nullable: true
            enum:
              - one
              - two
              - three
        - name: nullable-number-enum
          in: query
          schema:
            type: number
            nullable: true
            enum:
              - 1
              - 2
              - 3
      responses:
        200:
          description: OK
components: 
  schemas:
    NullableClass:
      type: object
      properties:
        number_prop:
          type: number
          nullable: true
        string_prop:
          type: string
          nullable: true
        string_enum_nullable_prop:
          type: string
          enum:
            - one
            - two
            - three
          nullable: true
        number_enum_nullable_prop:
          type: number
          enum:
            - 1
            - 2
            - 3
          nullable: true
Generation Details
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i openapi.yaml -g typescript-fetch -o /local/lib
export interface FakeEnumRequestRequest {
   nullableStringEnum?: FakeEnumRequestNullableStringEnumEnum; // must be nullable
   nullableNumberEnum?: FakeEnumRequestNullableNumberEnumEnum; // must be nullable
}
export interface NullableClass {
   /**
    *
    * @type {number}
    * @memberof NullableClass
    */
   numberProp?: number | null;
   /**
    *
    * @type {string}
    * @memberof NullableClass
    */
   stringProp?: string | null;
   /**
    *
    * @type {string}
    * @memberof NullableClass
    */
   stringEnumNullableProp?: NullableClassStringEnumNullablePropEnum; // must be nullable
   /**
    *
    * @type {number}
    * @memberof NullableClass
    */
   numberEnumNullableProp?: NullableClassNumberEnumNullablePropEnum; // must be nullable
}
Steps to reproduce

same as above

Related issues/PRs

Enum is supported by https://github.com/OpenAPITools/openapi-generator/issues/665

Suggest a fix
  • add sample https://github.com/berlysia/openapi-generator/commit/97851c7e9b3065c2f853c9ecbf6b5088b563217e https://github.com/berlysia/openapi-generator/commit/56cb7329dad9f967d1751f2d96c716df5d2cf883
  • and fix it https://github.com/berlysia/openapi-generator/commit/56bff0f2a39472f3a4bb5600325965ceb3a220d7
Assignee
Assign to
Time tracking