Skip to content

ObjectSchema member.Key.ToCamelCase() ignores underscores #167

@sberney

Description

@sberney

Expected Behavior

I have class like this:

public class MyClass
{
  [JsonIgnore]
  [ModelProperty(Ignore = true)]
  public string _isSeven { get; set; }

  public bool IsSeven
  {
    get
    {
      return _isSeven == 'True';
    }

    set
    {
      _isSeven = value ? 'True' : 'False';
    }
  }
}

I expect including this class in the ModelCatalog to not totally bork the Nancy.Swagger /api-docs route. I also expect it not to add _isSeven into the Schema Properties, or at least to do so under a different name.

Taking a look at the relevant code, the object properties are normalized using member.Key.ToCamelCase(), which maps both IsSeven and _isSeven to the same string, isSeven.

While I understand (and enjoy) normalization to camelCase, in the project I am working on, it is the convention to name sometimes name an underlying property the same as the public property, but prefixing the name with an underscore, eg IsSeven and _isSeven to be ultra pedantic. At the very least, the [ModelProperty(Ignore = true)] ought to fix this behavior (the error message for which is obtuse), or another property.

I hesitate to introduce Nancy.Swagger to my colleagues when I know that they will eventually have their swagger docs broken after trying to include a particular model.

Steps to Reproduce the Problem

  1. Open Nancy.Swagger sample annotations project
  2. Add class as described above somewhere in the project.
  3. Add class to ModelCatalog.
  4. Attempt to access generated docs -- will not work

Specifications

  • Version: 2.2.53-alpha through and including master
  • Project: Nancy.Swagger
  • Platform: Windows, .NET 4.6.1; probably all

Thank you,
Sam Berney

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions