Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing character in "ValidRegex" pattern of ComponentFieldName #16

Closed
claorden opened this issue Aug 3, 2020 · 3 comments · Fixed by #19
Closed

Missing character in "ValidRegex" pattern of ComponentFieldName #16

claorden opened this issue Aug 3, 2020 · 3 comments · Fixed by #19
Assignees
Labels
🐛 bug Something isn't working 💡 enhancement New feature or request

Comments

@claorden
Copy link

claorden commented Aug 3, 2020

In my class properties I have some nullable components. In AsyncApiSchema/v2/ComponentFieldName.cs there is a validation of the component field name which does not include the character "`" of my type "nullable`1", which breaks the process.

Just adding the character to ValidRegex fixes the problem:

private const string ValidRegex = @"^[a-zA-Z0-9\.\-_`]+$";

Any collateral damage you could think of after adding this?

Thank you for your work!

@m-wild
Copy link
Collaborator

m-wild commented Aug 3, 2020

This is following the AsyncApi specification. See: https://www.asyncapi.com/docs/specifications/2.0.0/#componentsObject

All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.

Field Name Examples:

  • User
  • User_1
  • User_Name
  • user-name
  • my.org.User

So the backtick is an invalid character by the spec.
A quick fix would be to replace this with an underscore. We can update the settings:

services.AddAsyncApiSchemaGeneration(options =>
{
    options.SchemaIdSelector = type => new CamelCaseNamingStrategy().GetPropertyName(type.Name, false).Replace("`", "_");
    // ...
}

However, it's a bit unfortunate that the name of a generic type is "generic_1", the type name is not exactly useful.
In your example "nullable_1" could be a nullable anything.
It would be more useful to generate a name for the type, like nullableOfFoo, or listOfBar, or dictionaryOfStringAndFoo.

I will update the SchemaIdSelector to handle generics better by default 👍


Also, we should probably be handling Nullable differently to other generics...
Json Schema allows for { "type": "null" }, see: https://json-schema.org/understanding-json-schema/reference/null.html
Which means we could detect System.Nullable<T> and set the property as { "type": [ "T", "null" ] }. I will investigate this.

@m-wild m-wild self-assigned this Aug 3, 2020
@m-wild m-wild added 🐛 bug Something isn't working 💡 enhancement New feature or request labels Aug 3, 2020
@claorden
Copy link
Author

claorden commented Aug 3, 2020

As said in the other issue, that was fast! Thank you for taking a look into this. Please let me know if I can be of any help.

@m-wild
Copy link
Collaborator

m-wild commented Aug 4, 2020

Fixed in v0.2.0: https://www.nuget.org/packages/Saunter/0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 💡 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants