Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 16:58

    RicoSuter on release

    Update README.md Fix/1047 (#1048) * Suppressing… Fix project metadata, remove bu… and 7 more (compare)

  • 16:58
    RicoSuter closed #1050
  • 16:56
    RicoSuter commented #1043
  • 16:56
    RicoSuter commented #1044
  • 16:56
    RicoSuter commented #1048
  • 16:56
    RicoSuter commented #1049
  • 16:56
    RicoSuter commented #1039
  • 16:54
    RicoSuter synchronize #1050
  • 16:54

    RicoSuter on master

    Inlined primitive types aren't … (compare)

  • 16:54
    RicoSuter closed #1039
  • 16:53
    RicoSuter opened #1050
  • 16:52

    RicoSuter on master

    v10.0.23 (compare)

  • 16:51

    RicoSuter on master

    Code formatting (compare)

  • 16:48
    RicoSuter closed #1042
  • 16:48

    RicoSuter on master

    Fix flags enums generation in C… (compare)

  • 16:48
    RicoSuter closed #1049
  • 16:47
    RicoSuter closed #1021
  • 16:47

    RicoSuter on master

    Fix TypeScript discriminator as… (compare)

  • 16:47
    RicoSuter closed #1043
  • 16:46

    RicoSuter on master

    Add GenerateOptionalPropertiesA… (compare)

Maikar
@Maikar

Hey guys, not sure if this should be in the NSwag channel or not, but I was looking to see if there was some way I could get my flag enums to be generated using their implementation values

Currently I have the following enum

[Flags]
public enum UserFlags
{
    None = 0,
    MustChangePassword = 1,
    Administrator = 2,
}

During the build process, we use NSwag.MSBuild to generate a .NET Standard 2.0 client library

That ends up generating the following:

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "9.13.18.0 (Newtonsoft.Json v11.0.0.0)")]
[System.Flags]
public enum UserFlags
{
    None = 1,
    MustChangePassword = 2,
    Administrator = 4,
}

Am I missing a setting in the settings file that could fix this, or are there any other suggestions other than changing my original enum? Would this be a bug?

Jérémy VIGNELLES
@jeremyVignelles
@RSuter : I'm here if you want to discuss about the naming of #916
Rico Suter
@RicoSuter
@Maikar please create an issue in the NJsonSchema repo... but flagged enums are custom in NJS and not really a supported feature of JSON Schema/Swagger/OpenAPI so be careful :-)
@jeremyVignelles what do you think of the PR? And the attribute name? Do you have a better idea to tell the generator that this is a property with an array with nullable items?
ItemsCanBeNullAttribute sounds better :-)
Jérémy VIGNELLES
@jeremyVignelles
:)
Is there any reason why you wanted to include the JsonSchema prefix?
at JsonSchemaGenerator.cs line 448, you have a #pragma warning disable 1998 why is that?
Otherwise I don't really have any remarks as I don't really understand the code
Rico Suter
@RicoSuter
Because the async callback does not have an await and thus there is a warning (and in this project we treat warnings as errors)
image.png
Jérémy VIGNELLES
@jeremyVignelles
why async then?
why not returning Task.CompletedTask?
Rico Suter
@RicoSuter
there are places where async is needed for this callback
Task.CompletedTask does not exist in some target frameworks (e.g. 4.0 :-)
also Task.FromResult<object>(null) is not available in the .NET 4.0 target,
that's why accept the warning and ignore it ;-)
I think we can merge the PR now, but I'm a little worried that this might be a breaking change
so I need to do more tests with NSwag later
Jérémy VIGNELLES
@jeremyVignelles
Fine, I can live with it for 1-2 weeks (I don't need to update my .ts for now)
but I will need it sooner or later
Pavel
@cpoDesign
HI All, question about schema validation. Why my schema does not fail on additional properties present ?? -> I am bit confused here
Jérémy VIGNELLES
@jeremyVignelles
there is an option for that, don't remember which
you can say that your objects accept additional properties or not
basically, I have a V1 API, but I don't want to break when a new property is added to the message. The V1 app will still continue to work, ignoring that new parameter, while newer versions will handle the extra parameter just fine (there should be a default value for older clients)
Pavel
@cpoDesign
I have found this: AllowAdditionalProperties = true but not sure where to put it
Jérémy VIGNELLES
@jeremyVignelles
in NJS, there is a property to modify the serializer settings as far as I remember
this is the way you can set properties on the underlying Newtonsoft.Json serializer
Pavel
@cpoDesign
I have found the following:var schema = JsonSchema4.FromJsonAsync(sch).Result; schema.AllowAdditionalItems = false;
Pavel
@cpoDesign
@jeremyVignelles Thanx for the help, it was AllowAdditionalProperties and not AllowAdditionalItems on schmea
*schema
Rico Suter
@RicoSuter

Just FYI: You are talking about two different things:

@jeremyVignelles you are looking for the JsonExtensionDataAttribute which is picked up by the NJS JSON Schema generator (i.e. generates a dictionary type)
https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonExtensionDataAttribute.htm
@cpoDesign just asked a general question about JSON Schema itself and how to manually define a "dictionary type" (that is with the additional properties metadata)

Attila Kemény
@Kemyke
hello @RicoSuter i have a question regarding inheritance. I checked this documentation https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance and copied the schema and the example JSON to a validator (eg https://www.jsonschemavalidator.net/) and it is considered as invalid. Am I missing somthing or this is a known problem?
Rico Suter
@RicoSuter
This is only valid in swagger/openapi - json schema does not have a way to really express inheritance
Attila Kemény
@Kemyke
actually i tried to find an openapi/swagger online validator but couldn't find anything. Do you happen to know some?
thanks for the info
Rico Suter
@RicoSuter
The whole discriminator stuff is not json schema valid
I think swagger.io has a validator?
Attila Kemény
@Kemyke
i couldn't find it within couple of clicks. Anyway i think i can sort it out somehow. Thanks for your time!
Rico Suter
@RicoSuter
👍
Chris
@Cisien
I'm looking to enforce schema for properties that gets serialized into a Dictionary<string, T>. From what i can tell, this is possible with patternProperties, however, i haven't found a way to declare that in NJsonSchmea -- is this possible?
Chris
@Cisien
@RicoSuter any ideas? At this point, it looks like i'm going to need to create a custom processor to handle dictionaries
Rico Suter
@RicoSuter
Maybe we also need some custom properties here
custom attributes
Chris
@Cisien
yeah, i can't really think of a way that would be unambiguous without something custom
Chris
@Cisien
Those changes work, Thanks!
@RicoSuter It looks like i'm going to need something like a MinLength attribute that I can apply to the class level to enforce that "At least X" of the possible properties are defined. I'll look into doing a PR for that maybe this weekend. What are your thoughts on a custom attribute to influence minProperties/maxProperties that can be applied at the class level (MinLengh/MaxLength can't be applied to a class)
Rico Suter
@RicoSuter
Seems good to me.. maybe JsonSchemaMinPropertiesAttribute?
Chris
@Cisien
ok