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
  • #9586
Closed
Open
Issue created May 26, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][C#][csharp-netcore] maxLength + enum = generated code doesn't build

Created by: jfeltesse-mdsol

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

When an object property features maxLength (and possibly other similar attributes?) alongside an enum, the generated code does not compile. Now, I know this is kind of weird to have both enum values and maxLength defined but the spec doesn't prevent those for the reasons stated here. Which means that the validators won't catch these, the generator will run fine, only at the final step of building a package the error would show up.

openapi-generator version

master @ e09409fb

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: C# enum length repro
  version: v1
paths:
  '/hello':
    get:
      responses:
        '200':
          description: returns a greeting
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Greeting'

components:
  schemas:
    Greeting:
      type: object
      properties:
        reply:
          type: string
          maxLength: 20
          enum:
            - hi
            - howdy
Generation Details

See steps below.

Steps to reproduce
openapi-generator generate -i openapi.yaml -g csharp-netcore --library httpclient -o out/csharp_enum
cd out/csharp_enum 
dotnet build --configuration Release

produces:

(...)
out/csharp_enum/src/Org.OpenAPITools/Model/Greeting.cs(141,49): error CS1061: 'Greeting.ReplyEnum?' does not contain a definition for 'Length' and no accessible extension method 'Length' accepting a first argument of type 'Greeting.ReplyEnum?' could be found (are you missing a using directive or an assembly reference?)
(...)

Build FAILED.
Related issues/PRs

None that I could find.

Suggest a fix

No idea... 🙇

@mandrean @frankyjuang @shibayan @Blackclaws @lucamazzanti @wing328 @prajon84

Assignee
Assign to
Time tracking