cancel
Showing results for 
Search instead for 
Did you mean: 

"readOnly" and "required" C# properties generation

New Contributor

"readOnly" and "required" C# properties generation

Dears

 

Please help me with readOnly property generation

 

I've found that properties declared with readOnly -oneOf are generated with Object data type.

 

  Customer:
    type: object
    required:
      - "ClientTypeId"
    properties:
      ClientTypeId:
        type: "integer"
        format: "int32"
      ClientType:
        readOnly: true
        allOf:
          - $ref: '#/definitions/ClientType'
definitions:
ClientType:
type: object
required:
- "ClientTypeId"
properties:
ClientTypeId:
type: "integer"
format: "int32"
Description:
type: "string"
LegalType:
type: "boolean"

ClientType is generated as 

/// <summary>                         
/// Gets or Sets ClientType           
/// </summary>                        
[DataMember(Name="ClientType")]       
public Object ClientType { get; set; }

however I expected that it will get strongly typed property ClientType according to the definition

additionally ClientTypeId is generated as Nullable<int> property but I expect that it will be generated like int ClientTypeId:

/// <summary>                         
/// Gets or Sets ClientTypeId         
/// </summary>                        
[Required]                            
[DataMember(Name="ClientTypeId")]     
public int? ClientTypeId { get; set; }

I used both online generator https://generator.swagger.io/api/gen/servers/aspnetcore and offline swagger-codegen (https://github.com/swagger-api/swagger-codegen) at master.

 

Is it possible to get ClientType to be generated as

public ClientType ClientType { get; set; }

?

Regards

Tags (1)
1 REPLY 1
New Contributor

Re: "readOnly" and "required" C# properties generation

I've updated DefaultCodegen.java 

please check https://github.com/swagger-api/swagger-codegen/issues/9350 for details

 

waiting for PR

New Here?
Join us and watch the welcome video:
Join our online event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win