[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