swagger-api / swagger-api/swagger-codegen
Errors in c-sharp code code generation export using https://app.swaggerhub.com/apis
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
There is code generation errors using c-sharp
The abstraction used for this object called MoneyObject (see below)
See how this translates
public partial class AllOfTransactionResourceAttributesHoldInfo : HoldInfoObject,IEquatable, IValidatableObject
{
/// Initializes a new instance of the class.
public AllOfTransactionResourceAttributesHoldInfo( amount = default(), foreignAmount = default()) : base(amount, foreignAmount)
{
}
public partial class HoldInfoObject : IEquatable, IValidatableObject
{
/// Initializes a new instance of the class.
public HoldInfoObject(AllOfHoldInfoObjectAmount amount = default(AllOfHoldInfoObjectAmount), AllOfHoldInfoObjectForeignAmount foreignAmount = default(AllOfHoldInfoObjectForeignAmount))
Eventually the MoneyObject is defined as you would expect as per the spec
/// Initializes a new instance of the <see cref="AllOfHoldInfoObjectAmount" /> class.
public AllOfHoldInfoObjectAmount(string currencyCode = default(string), string value = default(string), int? valueInBaseUnits = default(int?)) : base(currencyCode, value, valueInBaseUnits)
{
}
Everywhere MoneyObject is used as the base it just does not insert the type on the first level so it should have been
Should have been
public AllOfTransactionResourceAttributesHoldInfo(AllOfHoldInfoObjectAmount amount = default(AllOfHoldInfoObjectAmount), AllOfHoldInfoObjectForeignAmount foreignAmount = default(AllOfHoldInfoObjectForeignAmount)) : base(amount, foreignAmount)
{
}
There is a bug when swagger creates the output
Likewise here - Error
public AllOfTransactionResourceAttributesCashback(string description = default(string), amount = default()) : base(description, amount)
{
}
Should have been
public AllOfTransactionResourceAttributesCashback(string description = default(string), AllOfCashbackObjectAmount amount = default(AllOfCashbackObjectAmount)) : base(description, amount)
{
}
2. Also this is an error
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
foreach(var x in BaseValidate(validationContext)) yield return x;
yield break;
}
_CS0103 The name 'BaseValidate' does not exist in the current context
Swagger-codegen version
c-sharp (current online version)
Swagger declaration file content or url
openapi: 3.0.3…
HoldInfoObject:
type: object
description: |
Provides information about the amount at which a transaction was in the
HELD status.
properties:
amount:
description: |
The amount of this transaction while in the HELD status, in
Australian dollars.
allOf:
- $ref: '#/components/schemas/MoneyObject'
foreignAmount:
nullable: true
description: |
The foreign currency amount of this transaction while in the HELD
status. This field will be null for domestic transactions. The amount
was converted to the AUD amount reflected in the amount field.
allOf:
- $ref: '#/components/schemas/MoneyObject'
required:
- amount
- foreignAmount
CashbackObject:
type: object
description: |
Provides information about an instant reimbursement in the form of
cashback.
properties:
description:
type: string
description: |
A brief description of why this cashback was paid.
amount:
description: |
The total amount of cashback paid, represented as a positive value.
allOf:
- $ref: '#/components/schemas/MoneyObject'
required:
- description
- amount
MoneyObject:
type: object
description: |
Provides information about a value of money.
properties:
currencyCode:
type: string
description: |
The ISO 4217 currency code.
value:
type: string
description: |
The amount of money, formatted as a string in the relevant currency.
For example, for an Australian dollar value of $10.56, this field will
be `"10.56"`. The currency symbol is not included in the string.
valueInBaseUnits:
type: integer
description: |
The amount of money in the smallest denomination for the currency, as a
64-bit integer. For example, for an Australian dollar value of $10.56,
this field will be `1056`.
required:
- currencyCode
- value
- valueInBaseUnits
Command line used for generation
Using https://app.swaggerhub.com/apis
Steps to reproduce
Generate a c-sharp export
Related issues/PRs
There are similar postings about AllOf
Suggest a fix/enhancement
I can manually code the missing parts
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the C# export from the supplied OpenAPI schemas, focusing on the generated HoldInfoObject and CashbackObject constructors and IValidatableObject.Validate method. Done means the generated code includes the referenced MoneyObject types and no longer refers to an undefined BaseValidate member, while compiling successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100