swagger-api / swagger-api/swagger-codegen

Swagger CodeGen ignoring inherited properties in aspnetcore

Open
#10,961 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

CodeGen for aspnetcore is not including all properties when inheritance is being employed.
A simple example below. Ignores the effectiveDate property completely in the output. If I don't use inheritance it works just fine.

Swagger-codegen version

3.0.25

Swagger declaration file content or url

Schema

    Submission2:
      allOf:
      - type: object
        properties:
          effectiveDate:
            type: string
            format: date

Output from SmartBear SwaggerHub CodeGen integration for aspnetcore

/*
 * My Test API
 *
 * 
 *
 * OpenAPI spec version: v1.0.0
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 */
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace MyApi.Models
{ 
    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    public partial class Submission2 : IEquatable<Submission2>
    { 
        /// <summary>
        /// Returns the string presentation of the object
        /// </summary>
        /// <returns>String presentation of the object</returns>
        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.Append("class Submission2 {\n");
            sb.Append("}\n");
            return sb.ToString();
        }

        /// <summary>
        /// Returns the JSON string presentation of the object
        /// </summary>
        /// <returns>JSON string presentation of the object</returns>
        public string ToJson()
        {
            return JsonConvert.SerializeObject(this, Formatting.Indented);
        }

        /// <summary>
        /// Returns true if objects are equal
        /// </summary>
        /// <param name="obj">Object to be compared</param>
        /// <returns>Boolean</returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return obj.GetType() == GetType() && Equals((Submission2)obj);
        }

        /// <summary>
        /// Returns true if Submission2 instances are equal
        /// </summary>
        /// <param name="other">Instance of Submission2 to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Submission2 other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            return false;
        }

        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                return hashCode;
            }
        }

        #region Operators
        #pragma warning disable 1591

        public static bool operator ==(Submission2 left, Submission2 right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Submission2 left, Submission2 right)
        {
            return !Equals(left, right);
        }

        #pragma warning restore 1591
        #endregion Operators
    }
}

Command line used for generation

SmartBear SwaggerHub CodeGen integration feature for aspnetcore

Steps to reproduce

Using SmartBears CodeGen capability for aspnetcore server stub. Press sync button and review code output in repo.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the SmartBear SwaggerHub CodeGen integration for aspnetcore with the provided Submission2 schema and review the generated C# model. Trace the aspnetcore generation path that handles allOf inheritance; done means the generated Submission2 output includes the effectiveDate property and its date type.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.